2021-03-09 10:50:51 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { actions } from './reducer';
|
|
|
|
import type { ActionType, ActionCallbackType } from './types';
|
|
|
|
|
2022-06-15 09:56:52 +00:00
|
|
|
export const emitterCallback =
|
|
|
|
( type: string, observerDispatch: React.Dispatch< ActionType > ) =>
|
|
|
|
( callback: ActionCallbackType, priority = 10 ): ( () => void ) => {
|
|
|
|
const action = actions.addEventCallback( type, callback, priority );
|
|
|
|
observerDispatch( action );
|
|
|
|
return () => {
|
|
|
|
observerDispatch( actions.removeEventCallback( type, action.id ) );
|
|
|
|
};
|
2021-03-09 10:50:51 +00:00
|
|
|
};
|