ez-observable
Version:
Make class fields reactive in React with a single decorator + hook
2 lines (1 loc) • 547 B
JavaScript
class t{constructor(){this.values=Object.create(null),this.subscribers=new Set,this.hasProperty=s=>s in this.values,this.getPropertyValue=s=>this.values[s],this.setPropertyValue=(s,e,r=!1)=>{this.values=Object.assign(Object.create(null),{...this.values,[s]:e}),r||this.subscribers.forEach(i=>i(s,e))},this.subscribe=s=>(this.subscribers.add(s),()=>this.subscribers.delete(s)),this.getValues=()=>this.values}static for(s){if(t.pool.has(s))return t.pool.get(s);{const e=new t;return t.pool.set(s,e),e}}}t.pool=new Map;export{t as ObservableHelper};