@captaincodeman/rdx
Version:
Small state library. Like Redux, but smaller
2 lines (1 loc) • 422 B
JavaScript
import{dispatchEvent as t,stateEvent as e}from"./const.js";class s extends EventTarget{constructor(t,e){super(),this.state=t,this.reducer=e,this.state=this.reducer(this.state,{})}dispatch(s){const i=new CustomEvent(t,{cancelable:!0,detail:{action:s}});return this.dispatchEvent(i)&&(s=i.detail.action,this.state=this.reducer(this.state,s),this.dispatchEvent(new CustomEvent(e,{detail:{action:s}}))),s}}export{s as Store};