UNPKG

raid-addons

Version:

Add-ons functions for use with Raid

28 lines (23 loc) 569 B
import _match from '@mattstyles/match' /** * Cache match function, pass through update arguments and expect match * arms to comply to update arity. */ const match = matcher => { const _matcher = _match( matcher .map(([p, arm]) => { if (!arm) { return null } return [ ({ event }) => p(event), ({ state, event }) => arm(state, event) ] }) .filter(v => !!v) .concat([[({ state }) => state]]) ) return (state, event) => _matcher({ state, event }) } export default match