mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
wordpress__data: Add unsubscribe return to subscribe (#42355)
* Add unsubscribe to subscribe * Add subscribe/unsubscribe test
This commit is contained in:
Vendored
+20
-1
@@ -18,10 +18,29 @@ export { Action, combineReducers };
|
||||
//
|
||||
export type SelectorMap = Record<string, <T = unknown>(...args: readonly any[]) => T>;
|
||||
export type DispatcherMap = Record<string, <T = void>(...args: readonly any[]) => T>;
|
||||
export type Subscriber = (callback: () => void) => void;
|
||||
|
||||
/**
|
||||
* Subscribe to any changes to the store
|
||||
*
|
||||
* @param callback Will be invoked whenever there are any updates to the store.
|
||||
* @returns A callback that can be invoked to unsubscribe.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* const unsubscribe = subscribe( () => {
|
||||
* // You could use this opportunity to test whether the derived result of a
|
||||
* // selector has subsequently changed as the result of a state update.
|
||||
* } );
|
||||
*
|
||||
* // Later, if necessary...
|
||||
* unsubscribe();
|
||||
*
|
||||
*/
|
||||
export type Subscriber = (callback: () => void) => () => void;
|
||||
|
||||
export function dispatch(key: string): DispatcherMap;
|
||||
export function select(key: string): SelectorMap;
|
||||
|
||||
export const subscribe: Subscriber;
|
||||
|
||||
//
|
||||
|
||||
@@ -3,6 +3,9 @@ import * as data from '@wordpress/data';
|
||||
data.select('core/block-editor').isTyping<boolean>();
|
||||
data.dispatch('core/block-editor').resetBlocks('');
|
||||
|
||||
const unsubscribe = data.subscribe(() => console.log('Store was updated.'));
|
||||
unsubscribe();
|
||||
|
||||
data.use(data.plugins.persistence, { storage: window.localStorage });
|
||||
|
||||
interface FooBar {
|
||||
|
||||
Reference in New Issue
Block a user