-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Editor: Add subscription action generator for managing sources depend…
…encies
- Loading branch information
Showing
4 changed files
with
155 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createRegistryControl } from '@wordpress/data'; | ||
|
||
/** | ||
* Returns an control descriptor signalling to subscribe to the registry and | ||
* resolve the control promise only when the next state change occurs. | ||
* | ||
* @return {Object} Control descriptor. | ||
*/ | ||
export function awaitNextStateChange() { | ||
return { type: 'AWAIT_NEXT_STATE_CHANGE' }; | ||
} | ||
|
||
const controls = { | ||
AWAIT_NEXT_STATE_CHANGE: createRegistryControl( | ||
( registry ) => () => new Promise( ( resolve ) => { | ||
const unsubscribe = registry.subscribe( () => { | ||
unsubscribe(); | ||
resolve(); | ||
} ); | ||
} ) | ||
), | ||
}; | ||
|
||
export default controls; |
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