-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add mobx * docs: fix typo * docs: update README with mobx results * refactor: rename mobx to mobx-react-lite for consistency with react binding names --------- Co-authored-by: Eric Masiello <emasiello@vistaprint.com>
- Loading branch information
1 parent
620e09d
commit ff650fc
Showing
7 changed files
with
266 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React, { useCallback } from 'react'; | ||
import { observable, runInAction } from 'mobx'; | ||
import { observer } from 'mobx-react-lite'; | ||
|
||
import { | ||
reducer, | ||
initialState, | ||
selectCount, | ||
incrementAction, | ||
doubleAction, | ||
createApp, | ||
} from '../common'; | ||
|
||
const state = observable(initialState); | ||
|
||
const useCount = () => selectCount(state); | ||
|
||
const useIncrement = () => useCallback(() => { | ||
const newState = reducer(state, incrementAction); | ||
runInAction(() => { | ||
Object.keys(newState).forEach((key) => { | ||
state[key] = newState[key]; | ||
}); | ||
}); | ||
}, []); | ||
|
||
const useDouble = () => useCallback(() => { | ||
const newState = reducer(state, doubleAction); | ||
runInAction(() => { | ||
Object.keys(newState).forEach((key) => { | ||
state[key] = newState[key]; | ||
}); | ||
}); | ||
}, []); | ||
|
||
export default createApp(useCount, useIncrement, useDouble, React.Fragment, observer, observer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters