-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Refactor: move core/edit-post
INIT effect to use action-generators and controls
#14740
Changes from all commits
9729557
5046796
1f97ee1
1cf604c
f960196
6f937d9
4bd8154
f1d2a60
9c3fb4e
84ed847
8287c2b
db6f2ca
7b0ed6f
c1a5fe5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* The identifier for the data store. | ||
* @type {string} | ||
*/ | ||
export const STORE_KEY = 'core/edit-post'; | ||
|
||
/** | ||
* CSS selector string for the admin bar view post link anchor tag. | ||
* @type {string} | ||
*/ | ||
export const VIEW_AS_LINK_SELECTOR = '#wp-admin-bar-view a'; | ||
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. Aside: It wasn't introduced here, but "View" shows for draft posts with a different ID 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.
Follow-up issue: #15402 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createRegistryControl } from '@wordpress/data'; | ||
|
||
/** | ||
* Calls a selector using the current state. | ||
* | ||
* @param {string} storeName Store name. | ||
* @param {string} selectorName Selector name. | ||
* @param {Array} args Selector arguments. | ||
* | ||
* @return {Object} control descriptor. | ||
*/ | ||
export function select( storeName, selectorName, ...args ) { | ||
return { | ||
type: 'SELECT', | ||
storeName, | ||
selectorName, | ||
args, | ||
}; | ||
} | ||
|
||
/** | ||
* Calls a subscriber using the current state. | ||
* | ||
* @param {function} listenerCallback A callback for the subscriber that | ||
* receives the registry. | ||
* @return {Object} control descriptor. | ||
*/ | ||
export function __unstableSubscribe( listenerCallback ) { | ||
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. Since it's not exposed on a public API, I suppose it doesn't strictly need the prefix. But could be a good indicator for internal use as well. |
||
return { type: 'SUBSCRIBE', listenerCallback }; | ||
} | ||
|
||
const controls = { | ||
SELECT: createRegistryControl( | ||
( registry ) => ( { storeName, selectorName, args } ) => { | ||
return registry.select( storeName )[ selectorName ]( ...args ); | ||
} | ||
), | ||
SUBSCRIBE: createRegistryControl( | ||
( registry ) => ( { listenerCallback } ) => { | ||
return registry.subscribe( listenerCallback( registry ) ); | ||
} | ||
), | ||
}; | ||
|
||
export default controls; |
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.
I'd recommend some JSDoc for the constants.