HEX
Server: LiteSpeed
System: Linux premium127.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User: luxbsolr (925)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: /home/luxbsolr/cardsord.store/wp-content/plugins/woocommerce-shipping/client/utils/data-store.ts
import { Action } from 'types';

export const createReducer = < S >( defaultState: S ) => {
	const handlers: Record<
		string,
		< Actions extends Action >( s: S, action: Actions ) => S
	> = {};

	const bind = < A extends Action >() => {
		return ( s = defaultState, action: A ) => {
			const handler = handlers[ action.type ];
			return typeof handler === 'function'
				? handler( s, action as A )
				: s;
		};
	};
	const on = ( type: string, handler: ( s: S, action: Action ) => S ) => {
		handlers[ type ] = handler;
		return {
			on,
			bind,
		};
	};
	return {
		on,
		bind,
	};
};