File "emitter-callback.ts"

Full Path: /home/vantageo/public_html/cache/cache/cache/cache/cache/.wp-cli/wp-content/plugins/woocommerce/packages/woocommerce-blocks/assets/js/base/context/event-emit/emitter-callback.ts
File size: 496 bytes
MIME-type: text/x-java
Charset: utf-8

/**
 * Internal dependencies
 */
import { actions } from './reducer';
import type { ActionType, ActionCallbackType } from './types';

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 ) );
	};
};