-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: improve substate object format
- switch useSubstate from returning array to returning object - improve type checking - refactor some awkward types - remove useGlobalDispatch - rework useDispatch to do what useGlobalDispatch used to do - refer to GlobalDispatch now as GenericDispatch BREAKING CHANGE: This commit alters the function and type API in a backwards-incompatible way in preparation for v6.
- Loading branch information
1 parent
d340069
commit 923a2c9
Showing
12 changed files
with
74 additions
and
90 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
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 |
---|---|---|
@@ -1,23 +1,28 @@ | ||
import {useCallback} from 'react' | ||
|
||
import {dispatch} from '../dispatch.js' | ||
import {ActionKey, Dispatcher, SubstateKey} from '../Interfaces.js' | ||
import {ActionKey, GenericDispatcher, SubstateKey} from '../Interfaces.js' | ||
|
||
/** | ||
* Hook that allows a component to receive a reference to a dispatch function that can be called to | ||
* update a particular substate without also listening for changes to any substates. | ||
* update ANY substate without also listening for changes to a substate. | ||
* | ||
* @param {SubstateKey<*>} substateKey The substate to be modified by actions dispatched via the | ||
* returned dispatch function. | ||
* @returns {Dispatcher} Dispatch function that can be called to update the substate. | ||
* Similar to the dispatch function obtained via `useSubstate`, except this function requires a | ||
* reference to a Substate as the first argument. | ||
* | ||
* @returns Dispatch function that can be called to update any substate. | ||
*/ | ||
export function useDispatch <Type> (substateKey: SubstateKey<Type>): Dispatcher { | ||
export function useDispatch (): GenericDispatcher { | ||
// Since we are creating a function in this hook, memoize it so it remains the same across | ||
// re-renders | ||
return useCallback( | ||
<Payload>(actionKey: ActionKey<Payload>, payload: Payload) => ( | ||
<Payload>( | ||
substateKey: SubstateKey<unknown>, | ||
actionKey: ActionKey<Payload>, | ||
payload: Payload | ||
) => ( | ||
dispatch(substateKey, actionKey, payload) | ||
), | ||
[substateKey] | ||
[] | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
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