forked from WordPress/wp-feature-notifications
-
Notifications
You must be signed in to change notification settings - Fork 0
feature: type redux store #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,11 @@ | ||
| import { CurriedSelectorsOf } from '@wordpress/data/build-types/types' | ||
| import { NoticeStore, NOTIFY_NAMESPACE } from './scripts/store' | ||
|
|
||
| declare global { | ||
| interface Window { wp: { notify: any }; wp_notify_data?: { settingsPage: string } } | ||
| } | ||
|
|
||
| declare module '@wordpress/data' { | ||
| function dispatch( key: NOTIFY_NAMESPACE ): typeof import( './scripts/store/actions' ); | ||
| function select( key: NOTIFY_NAMESPACE ): CurriedSelectorsOf< NoticeStore >; | ||
| } |
This file contains hidden or 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,41 +1,83 @@ | ||
| /* eslint-disable jsdoc/require-returns-type */ | ||
|
|
||
| /** | ||
| * @typedef {import('./index').Notice} Notice | ||
| */ | ||
|
|
||
| /** | ||
| * Action creator to hydrate a notice from the store. | ||
| * | ||
| * @param {Notice[]} payload The notices to hydrate. | ||
| * @return A redux action. | ||
| */ | ||
| export const hydrate = ( payload ) => { | ||
| return { | ||
| type: 'HYDRATE', | ||
| type: /** @type {'HYDRATE'} */ ( 'HYDRATE' ), | ||
| payload, | ||
| }; | ||
| }; | ||
|
|
||
| /** | ||
| * Action creator to clear a notification context from the store. | ||
| * | ||
| * @param {string} context The slug of the context to clear. | ||
| * @return A redux action. | ||
| */ | ||
| export const clear = ( context ) => { | ||
| return { | ||
| type: 'CLEAR', | ||
| type: /** @type {'CLEAR'} */ ( 'CLEAR' ), | ||
| context, | ||
| }; | ||
| }; | ||
|
|
||
| /** | ||
| * Action creator to add a notice to the store. | ||
| * | ||
| * @param {Notice} payload The notice to add. | ||
| * @return A redux action. | ||
| */ | ||
| export const addNotice = ( payload ) => { | ||
| return { | ||
| type: 'ADD', | ||
| type: /** @type {'ADD'} */ ( 'ADD' ), | ||
| payload, | ||
| }; | ||
| }; | ||
|
|
||
| /** | ||
| * Action creator to remove a notice from the store. | ||
| * | ||
| * @param {number} id The id of the notice to remove. | ||
| * @return A redux action. | ||
| */ | ||
| export const removeNotice = ( id ) => { | ||
| return { | ||
| type: 'DELETE', | ||
| type: /** @type {'DELETE'} */ ( 'DELETE' ), | ||
| id, | ||
| }; | ||
| }; | ||
|
|
||
| /** | ||
| * Action creator to update a notice in the store. | ||
| * | ||
| * @param {Notice} payload | ||
| * @return A redux action. | ||
| */ | ||
| export const updateNotice = ( payload ) => { | ||
| return { | ||
| type: 'UPDATE', | ||
| type: /** @type {'UPDATE'} */ ( 'UPDATE' ), | ||
| payload, | ||
| }; | ||
| }; | ||
|
|
||
| /** | ||
| * Action creator to fetch notices. | ||
| * | ||
| * @param {string} path The REST API route from which to fetch notices. | ||
| * @return A redux action. | ||
| */ | ||
| export const fetchAPI = ( path = '' ) => { | ||
| return { | ||
| type: 'FETCH', | ||
| type: /** @type {'FETCH'} */ ( 'FETCH' ), | ||
| path, | ||
| }; | ||
| }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -8,6 +8,26 @@ import * as controls from './controls'; | |
| import * as resolvers from './resolvers'; | ||
|
|
||
| /** | ||
| <<<<<<< Updated upstream | ||
| ======= | ||
| * | ||
| * @typedef {import('@wordpress/data/build-types/types').ReduxStoreConfig<State, typeof actions, typeof selectors>} StoreConfig | ||
| * @typedef {import('@wordpress/data/build-types/types').StoreDescriptor<StoreConfig>} NoticeStore | ||
| */ | ||
|
|
||
| /** | ||
| * @template {Record<string, unknown>} T | ||
| * @template {keyof T} K | ||
| * @typedef {T[K]} ValuesOf | ||
| */ | ||
|
|
||
| /** | ||
| * @typedef {ReturnType<ValuesOf<typeof actions, keyof actions>>} Action | ||
| */ | ||
|
|
||
| /** | ||
| >>>>>>> Stashed changes | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ARGH... JUST A SEC THESE SHOULDN'T BE HERE |
||
| * | ||
| * @typedef {Object} DashiconsIcon The Dashicons icon type. | ||
| * @property {string} dashicons The Dashicons slug of the icon. | ||
| */ | ||
|
|
@@ -33,7 +53,12 @@ import * as resolvers from './resolvers'; | |
| */ | ||
|
|
||
| /** | ||
| <<<<<<< Updated upstream | ||
| * | ||
| * @typedef {Object} Notification The notification type. | ||
| ======= | ||
| * @typedef {Object} Notice The notification type. | ||
| >>>>>>> Stashed changes | ||
| * @property {NoticeAction=} action The optional action associated to the notification. | ||
| * @property {string=} context The rendering context of the notification. | ||
| * @property {number} date The datetime from which the notification was emitted. | ||
|
|
@@ -47,21 +72,28 @@ import * as resolvers from './resolvers'; | |
| */ | ||
|
|
||
| /** | ||
| <<<<<<< Updated upstream | ||
| * | ||
| * @typedef {Record<string, Notification[]>} State The notifications redux store type. | ||
| ======= | ||
| * @typedef {Record<string, Notice[]>} State The notifications redux store type. | ||
| >>>>>>> Stashed changes | ||
| */ | ||
|
|
||
| /** | ||
| * Creating a store for the redux state. | ||
| * | ||
| * @return {store} A Redux store that lets you read the state, dispatch actions and subscribe to changes. | ||
| * A Redux store that lets you read the state, dispatch actions and subscribe to changes. | ||
| */ | ||
| const store = createReduxStore( NOTIFY_NAMESPACE, { | ||
| reducer, | ||
| actions, | ||
| selectors, | ||
| controls, | ||
| resolvers, | ||
| } ); | ||
| const store = /** @type {NoticeStore} */ ( | ||
| createReduxStore( NOTIFY_NAMESPACE, { | ||
| reducer, | ||
| actions, | ||
| selectors, | ||
| controls, | ||
| resolvers, | ||
| } ) | ||
| ); | ||
|
|
||
| register( store ); | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is weird but required for it to be type
'HYDRATE'notstring. Otherwise the type union in action types doesn't work right in the reducer.