effector-react
Advanced tools
Comparing version 19.1.1 to 19.1.2
@@ -1,2 +0,2 @@ | ||
function e(e,t){var r,s,o,a;let c,u;if(effector.is.store(e))u=e;else if('function'==typeof e)c=e;else{if('object'!=typeof e||null===e)throw Error('shape should be a store or object with stores');u=effector.createStoreObject(e)}const i=null!==(r=null===(s=u)||void 0===s?void 0:s.shortName)&&void 0!==r?r:'Unknown',p=effector.createEvent(i+".View mounted"),l=effector.createEvent(i+".View unmounted");return a=o=class extends n.Component{constructor(...t){super(...t),this._unsubscribe=null,this._hasUnmounted=0,this.store='function'==typeof e?c(this.props):u,this.state={currentState:this.store.getState()}}componentDidMount(){p({props:this.props,state:this.store.getState()}),this.subscribe()}componentWillUnmount(){l({props:this.props,state:this.store.getState()}),this.unsubscribe(),this._hasUnmounted=1}render(){return t(this.props,this.state.currentState)}subscribe(){this._unsubscribe=this.store.watch(e=>{this._hasUnmounted||this.setState(t=>e===t.currentState?null:{currentState:e})})}unsubscribe(){'function'==typeof this._unsubscribe&&this._unsubscribe(),this._unsubscribe=null}},o.displayName=i+".View",o.mounted=p,o.unmounted=l,a}function t(t){return e(t,({children:e},t)=>e(t))}function r(e){if(!effector.is.store(e))throw Error('expect useStore argument to be a store');const t=n.useState({})[1],r=n.useMemo(()=>{const r=effector.sample(e);return r.updates.watch(()=>t({})),r},[e]);return a(()=>()=>{effector.clearNode(r,{deep:1})},[e]),e.getState()}function s(){return(s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var s in r)({}).hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e}).apply(this,arguments)}function o(e,r){const o=t(e),a=e=>n.createElement(o,null,t=>n.createElement(r,s({},e,t)));return a.displayName="Connect("+(r.displayName||r.name||'Unknown')+")",a}Object.defineProperty(exports,'__esModule',{value:1});var n=require('react'),effector=require('effector');const a='undefined'!=typeof window?n.useLayoutEffect:n.useEffect,{store:c}=effector.createDomain('Gate');exports.connect=e=>t=>o(t,e),exports.createComponent=e,exports.createContextComponent=function(e,r,s){var o,a;const c=t(e);return a=o=class extends n.Component{constructor(...e){super(...e),this.renderProp=e=>s(this.props,e,this.context)}render(){return n.createElement(c,null,this.renderProp)}},o.contextType=r,a},exports.createGate=function e(t="gate",r={}){const s=c(0),o=c(r),{set:a}=effector.createApi(o,{set:(e,t)=>t}),{open:u,close:i,destructor:p}=effector.createApi(s,{open:()=>l.predicate()&&1,close:()=>0,destructor:()=>0});class l extends n.PureComponent{static childGate(r="Subgate"){const s=e(t+"/"+r);s.predicate=()=>l.status.getState();let o=0,n=0;return s.open.watch(()=>{n||(o=1)}),s.close.watch(()=>{n||(o=0)}),l.status.watch(e=>{n=1,o&&e&&!s.status.getState()&&s.open(),n=0}),l.close.watch(()=>{n=1,s.close(),n=0}),l.destructor.watch(()=>s.destructor()),s}componentDidMount(){l.open()}componentWillUnmount(){l.close()}render(){return l.set(this.props),null}}l.predicate=()=>1,l.displayName="Gate:"+t,l.isOpen=0,l.current=o.getState(),l.open=u,l.close=i,l.status=s,l.state=o,l.set=a,l.destructor=p,l.isTerminated=0;const h=s.watch(e=>l.isOpen=e),d=o.watch(e=>l.current=e);s.map(e=>{e||(l.current=r)}),o.reset(i);const f=p.watch(()=>{l.isTerminated=1}),m=p.watch(()=>{m(),h(),d(),f(),l.status.off(l.open),l.status.off(l.close),l.status.off(l.destructor),l.state.off(l.set)});return l},exports.createReactState=o,exports.createStoreConsumer=t,exports.unstable_createStoreProvider=function(e){var t,r;return r=t=class extends n.Component{constructor(...e){super(...e),this.state={currentValue:null}}static getDerivedStateFromProps(t){return e.setState(t.value),{currentValue:t.value}}render(){return this.props.children}},t.displayName=e.shortName+".Provider",t.defaultProps={children:null},r},exports.useGate=(e,t={})=>{n.useEffect(()=>(e.open(),()=>e.close()),[e]),e.set(t)},exports.useStore=r,exports.useStoreMap=({store:e,keys:t,fn:s})=>{if(!effector.is.store(e))throw Error('useStoreMap expects a store');if(!Array.isArray(t))throw Error('useStoreMap expects an array as keys');if('function'!=typeof s)throw Error('useStoreMap expects a function');const o=n.useMemo(()=>e.map(e=>s(e,t)),t),c=r(o);return a(()=>()=>effector.clearNode(o,{deep:1}),t),c}; | ||
function e(e,t){var r,s,o,a;let c,u;if(effector.is.store(e))u=e;else if('function'==typeof e)c=e;else{if('object'!=typeof e||null===e)throw Error('shape should be a store or object with stores');u=effector.createStoreObject(e)}const i=null!==(r=null===(s=u)||void 0===s?void 0:s.shortName)&&void 0!==r?r:'Unknown',p=effector.createEvent(i+".View mounted"),l=effector.createEvent(i+".View unmounted");return a=o=class extends n.Component{constructor(...t){super(...t),this._unsubscribe=null,this._hasUnmounted=0,this.store='function'==typeof e?c(this.props):u,this.state={currentState:this.store.getState()}}componentDidMount(){p({props:this.props,state:this.store.getState()}),this.subscribe()}componentWillUnmount(){l({props:this.props,state:this.store.getState()}),this.unsubscribe(),this._hasUnmounted=1}render(){return t(this.props,this.state.currentState)}subscribe(){this._unsubscribe=this.store.watch(e=>{this._hasUnmounted||this.setState(t=>e===t.currentState?null:{currentState:e})})}unsubscribe(){'function'==typeof this._unsubscribe&&this._unsubscribe(),this._unsubscribe=null}},o.displayName=i+".View",o.mounted=p,o.unmounted=l,a}function t(t){return e(t,({children:e},t)=>e(t))}function r(e){if(!effector.is.store(e))throw Error('expect useStore argument to be a store');const t=n.useReducer(c,void 0,e.getState)[1];return a(()=>e.watch(t),[e]),e.getState()}function s(){return(s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var s in r)({}).hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e}).apply(this,arguments)}function o(e,r){const o=t(e),a=e=>n.createElement(o,null,t=>n.createElement(r,s({},e,t)));return a.displayName="Connect("+(r.displayName||r.name||'Unknown')+")",a}Object.defineProperty(exports,'__esModule',{value:1});var n=require('react'),effector=require('effector');const a='undefined'!=typeof window?n.useLayoutEffect:n.useEffect,c=(e,t)=>t,{store:u}=effector.createDomain('Gate');exports.connect=e=>t=>o(t,e),exports.createComponent=e,exports.createContextComponent=function(e,r,s){var o,a;const c=t(e);return a=o=class extends n.Component{constructor(...e){super(...e),this.renderProp=e=>s(this.props,e,this.context)}render(){return n.createElement(c,null,this.renderProp)}},o.contextType=r,a},exports.createGate=function e(t="gate",r={}){const s=u(0),o=u(r),{set:a}=effector.createApi(o,{set:(e,t)=>t}),{open:c,close:i,destructor:p}=effector.createApi(s,{open:()=>l.predicate()&&1,close:()=>0,destructor:()=>0});class l extends n.PureComponent{static childGate(r="Subgate"){const s=e(t+"/"+r);s.predicate=()=>l.status.getState();let o=0,n=0;return s.open.watch(()=>{n||(o=1)}),s.close.watch(()=>{n||(o=0)}),l.status.watch(e=>{n=1,o&&e&&!s.status.getState()&&s.open(),n=0}),l.close.watch(()=>{n=1,s.close(),n=0}),l.destructor.watch(()=>s.destructor()),s}componentDidMount(){l.open()}componentWillUnmount(){l.close()}render(){return l.set(this.props),null}}l.predicate=()=>1,l.displayName="Gate:"+t,l.isOpen=0,l.current=o.getState(),l.open=c,l.close=i,l.status=s,l.state=o,l.set=a,l.destructor=p,l.isTerminated=0;const h=s.watch(e=>l.isOpen=e),d=o.watch(e=>l.current=e);s.map(e=>{e||(l.current=r)}),o.reset(i);const f=p.watch(()=>{l.isTerminated=1}),m=p.watch(()=>{m(),h(),d(),f(),l.status.off(l.open),l.status.off(l.close),l.status.off(l.destructor),l.state.off(l.set)});return l},exports.createReactState=o,exports.createStoreConsumer=t,exports.unstable_createStoreProvider=function(e){var t,r;return r=t=class extends n.Component{constructor(...e){super(...e),this.state={currentValue:null}}static getDerivedStateFromProps(t){return e.setState(t.value),{currentValue:t.value}}render(){return this.props.children}},t.displayName=e.shortName+".Provider",t.defaultProps={children:null},r},exports.useGate=(e,t={})=>{n.useEffect(()=>(e.open(),()=>e.close()),[e]),e.set(t)},exports.useStore=r,exports.useStoreMap=({store:e,keys:t,fn:s})=>{if(!effector.is.store(e))throw Error('useStoreMap expects a store');if(!Array.isArray(t))throw Error('useStoreMap expects an array as keys');if('function'!=typeof s)throw Error('useStoreMap expects a function');const o=n.useMemo(()=>effector.createStore(s(e.getState(),t)).on(e,(e,r)=>s(r,t)),t),c=r(o);return a(()=>()=>{o.off(e),effector.clearNode(o,{deep:1})},t),c}; | ||
//# sourceMappingURL=effector-react.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
function t(t,e){var r,s,n,o;let u,c;if(y.store(t))c=t;else if('function'==typeof t)u=t;else{if('object'!=typeof t||null===t)throw Error('shape should be a store or object with stores');c=S(t)}const a=null!==(r=null===(s=c)||void 0===s?void 0:s.shortName)&&void 0!==r?r:'Unknown',i=g(a+".View mounted"),p=g(a+".View unmounted");return o=n=class extends l{constructor(...e){super(...e),this._unsubscribe=null,this._hasUnmounted=0,this.store='function'==typeof t?u(this.props):c,this.state={currentState:this.store.getState()}}componentDidMount(){i({props:this.props,state:this.store.getState()}),this.subscribe()}componentWillUnmount(){p({props:this.props,state:this.store.getState()}),this.unsubscribe(),this._hasUnmounted=1}render(){return e(this.props,this.state.currentState)}subscribe(){this._unsubscribe=this.store.watch(t=>{this._hasUnmounted||this.setState(e=>t===e.currentState?null:{currentState:t})})}unsubscribe(){'function'==typeof this._unsubscribe&&this._unsubscribe(),this._unsubscribe=null}},n.displayName=a+".View",n.mounted=i,n.unmounted=p,o}function e(e){return t(e,({children:t},e)=>t(e))}function r(t){var e,r;return r=e=class extends l{constructor(...t){super(...t),this.state={currentValue:null}}static getDerivedStateFromProps(e){return t.setState(e.value),{currentValue:e.value}}render(){return this.props.children}},e.displayName=t.shortName+".Provider",e.defaultProps={children:null},r}function s(t,r,s){var n,o;const u=e(t);return o=n=class extends l{constructor(...t){super(...t),this.renderProp=t=>s(this.props,t,this.context)}render(){return h(u,null,this.renderProp)}},n.contextType=r,o}function n(t){if(!y.store(t))throw Error('expect useStore argument to be a store');const e=d({})[1],r=f(()=>{const r=v(t);return r.updates.watch(()=>e({})),r},[t]);return U(()=>()=>{x(r,{deep:1})},[t]),t.getState()}function o({store:t,keys:e,fn:r}){if(!y.store(t))throw Error('useStoreMap expects a store');if(!Array.isArray(e))throw Error('useStoreMap expects an array as keys');if('function'!=typeof r)throw Error('useStoreMap expects a function');const s=f(()=>t.map(t=>r(t,e)),e),o=n(s);return U(()=>()=>x(s,{deep:1}),e),o}function u(){return(u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var s in r)({}).hasOwnProperty.call(r,s)&&(t[s]=r[s])}return t}).apply(this,arguments)}function c(t,r){const s=e(t),n=t=>h(s,null,e=>h(r,u({},t,e)));return n.displayName="Connect("+(r.displayName||r.name||'Unknown')+")",n}function a(t){return e=>c(e,t)}function i(t,e={}){w(()=>(t.open(),()=>t.close()),[t]),t.set(e)}function p(t="gate",e={}){const r=P(0),s=P(e),{set:n}=N(s,{set:(t,e)=>e}),{open:o,close:u,destructor:c}=N(r,{open:()=>a.predicate()&&1,close:()=>0,destructor:()=>0});class a extends b{static childGate(e="Subgate"){const r=p(t+"/"+e);r.predicate=()=>a.status.getState();let s=0,n=0;return r.open.watch(()=>{n||(s=1)}),r.close.watch(()=>{n||(s=0)}),a.status.watch(t=>{n=1,s&&t&&!r.status.getState()&&r.open(),n=0}),a.close.watch(()=>{n=1,r.close(),n=0}),a.destructor.watch(()=>r.destructor()),r}componentDidMount(){a.open()}componentWillUnmount(){a.close()}render(){return a.set(this.props),null}}a.predicate=()=>1,a.displayName="Gate:"+t,a.isOpen=0,a.current=s.getState(),a.open=o,a.close=u,a.status=r,a.state=s,a.set=n,a.destructor=c,a.isTerminated=0;const i=r.watch(t=>a.isOpen=t),l=s.watch(t=>a.current=t);r.map(t=>{t||(a.current=e)}),s.reset(u);const h=c.watch(()=>{a.isTerminated=1}),d=c.watch(()=>{d(),i(),l(),h(),a.status.off(a.open),a.status.off(a.close),a.status.off(a.destructor),a.state.off(a.set)});return a}import{Component as l,createElement as h,useState as d,useMemo as f,useLayoutEffect as m,useEffect as w,PureComponent as b}from'react';import{is as y,createStoreObject as S,createEvent as g,sample as v,clearNode as x,createDomain as _,createApi as N}from'effector';const U='undefined'!=typeof window?m:w,{store:P}=_('Gate');export{a as connect,t as createComponent,s as createContextComponent,p as createGate,c as createReactState,e as createStoreConsumer,r as unstable_createStoreProvider,i as useGate,n as useStore,o as useStoreMap}; | ||
function t(t,e){var r,s,n,o;let u,c;if(S.store(t))c=t;else if('function'==typeof t)u=t;else{if('object'!=typeof t||null===t)throw Error('shape should be a store or object with stores');c=y(t)}const a=null!==(r=null===(s=c)||void 0===s?void 0:s.shortName)&&void 0!==r?r:'Unknown',i=g(a+".View mounted"),p=g(a+".View unmounted");return o=n=class extends l{constructor(...e){super(...e),this._unsubscribe=null,this._hasUnmounted=0,this.store='function'==typeof t?u(this.props):c,this.state={currentState:this.store.getState()}}componentDidMount(){i({props:this.props,state:this.store.getState()}),this.subscribe()}componentWillUnmount(){p({props:this.props,state:this.store.getState()}),this.unsubscribe(),this._hasUnmounted=1}render(){return e(this.props,this.state.currentState)}subscribe(){this._unsubscribe=this.store.watch(t=>{this._hasUnmounted||this.setState(e=>t===e.currentState?null:{currentState:t})})}unsubscribe(){'function'==typeof this._unsubscribe&&this._unsubscribe(),this._unsubscribe=null}},n.displayName=a+".View",n.mounted=i,n.unmounted=p,o}function e(e){return t(e,({children:t},e)=>t(e))}function r(t){var e,r;return r=e=class extends l{constructor(...t){super(...t),this.state={currentValue:null}}static getDerivedStateFromProps(e){return t.setState(e.value),{currentValue:e.value}}render(){return this.props.children}},e.displayName=t.shortName+".Provider",e.defaultProps={children:null},r}function s(t,r,s){var n,o;const u=e(t);return o=n=class extends l{constructor(...t){super(...t),this.renderProp=t=>s(this.props,t,this.context)}render(){return h(u,null,this.renderProp)}},n.contextType=r,o}function n(t){if(!S.store(t))throw Error('expect useStore argument to be a store');const e=d(P,void 0,t.getState)[1];return U(()=>t.watch(e),[t]),t.getState()}function o({store:t,keys:e,fn:r}){if(!S.store(t))throw Error('useStoreMap expects a store');if(!Array.isArray(e))throw Error('useStoreMap expects an array as keys');if('function'!=typeof r)throw Error('useStoreMap expects a function');const s=f(()=>v(r(t.getState(),e)).on(t,(t,s)=>r(s,e)),e),o=n(s);return U(()=>()=>{s.off(t),x(s,{deep:1})},e),o}function u(){return(u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var s in r)({}).hasOwnProperty.call(r,s)&&(t[s]=r[s])}return t}).apply(this,arguments)}function c(t,r){const s=e(t),n=t=>h(s,null,e=>h(r,u({},t,e)));return n.displayName="Connect("+(r.displayName||r.name||'Unknown')+")",n}function a(t){return e=>c(e,t)}function i(t,e={}){w(()=>(t.open(),()=>t.close()),[t]),t.set(e)}function p(t="gate",e={}){const r=E(0),s=E(e),{set:n}=N(s,{set:(t,e)=>e}),{open:o,close:u,destructor:c}=N(r,{open:()=>a.predicate()&&1,close:()=>0,destructor:()=>0});class a extends b{static childGate(e="Subgate"){const r=p(t+"/"+e);r.predicate=()=>a.status.getState();let s=0,n=0;return r.open.watch(()=>{n||(s=1)}),r.close.watch(()=>{n||(s=0)}),a.status.watch(t=>{n=1,s&&t&&!r.status.getState()&&r.open(),n=0}),a.close.watch(()=>{n=1,r.close(),n=0}),a.destructor.watch(()=>r.destructor()),r}componentDidMount(){a.open()}componentWillUnmount(){a.close()}render(){return a.set(this.props),null}}a.predicate=()=>1,a.displayName="Gate:"+t,a.isOpen=0,a.current=s.getState(),a.open=o,a.close=u,a.status=r,a.state=s,a.set=n,a.destructor=c,a.isTerminated=0;const i=r.watch(t=>a.isOpen=t),l=s.watch(t=>a.current=t);r.map(t=>{t||(a.current=e)}),s.reset(u);const h=c.watch(()=>{a.isTerminated=1}),d=c.watch(()=>{d(),i(),l(),h(),a.status.off(a.open),a.status.off(a.close),a.status.off(a.destructor),a.state.off(a.set)});return a}import{Component as l,createElement as h,useReducer as d,useMemo as f,useLayoutEffect as m,useEffect as w,PureComponent as b}from'react';import{is as S,createStoreObject as y,createEvent as g,createStore as v,clearNode as x,createDomain as _,createApi as N}from'effector';const U='undefined'!=typeof window?m:w,P=(t,e)=>e,{store:E}=_('Gate');export{a as connect,t as createComponent,s as createContextComponent,p as createGate,c as createReactState,e as createStoreConsumer,r as unstable_createStoreProvider,i as useGate,n as useStore,o as useStoreMap}; | ||
//# sourceMappingURL=effector-react.es.js.map |
@@ -1,2 +0,2 @@ | ||
return e=this,t=function(e,t,effector){function r(e,r){var s,n,o,c;let a,u;if(effector.is.store(e))u=e;else if('function'==typeof e)a=e;else{if('object'!=typeof e||null===e)throw Error('shape should be a store or object with stores');u=effector.createStoreObject(e)}const i=null!==(s=null===(n=u)||void 0===n?void 0:n.shortName)&&void 0!==s?s:'Unknown',p=effector.createEvent(i+".View mounted"),l=effector.createEvent(i+".View unmounted");return c=o=class extends t.Component{constructor(...t){super(...t),this._unsubscribe=null,this._hasUnmounted=0,this.store='function'==typeof e?a(this.props):u,this.state={currentState:this.store.getState()}}componentDidMount(){p({props:this.props,state:this.store.getState()}),this.subscribe()}componentWillUnmount(){l({props:this.props,state:this.store.getState()}),this.unsubscribe(),this._hasUnmounted=1}render(){return r(this.props,this.state.currentState)}subscribe(){this._unsubscribe=this.store.watch(e=>{this._hasUnmounted||this.setState(t=>e===t.currentState?null:{currentState:e})})}unsubscribe(){'function'==typeof this._unsubscribe&&this._unsubscribe(),this._unsubscribe=null}},o.displayName=i+".View",o.mounted=p,o.unmounted=l,c}function s(e){return r(e,({children:e},t)=>e(t))}function n(e){if(!effector.is.store(e))throw Error('expect useStore argument to be a store');const r=t.useState({})[1],s=t.useMemo(()=>{const t=effector.sample(e);return t.updates.watch(()=>r({})),t},[e]);return a(()=>()=>{effector.clearNode(s,{deep:1})},[e]),e.getState()}function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var s in r)({}).hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e}).apply(this,arguments)}function c(e,r){const n=s(e),c=e=>t.createElement(n,null,s=>t.createElement(r,o({},e,s)));return c.displayName="Connect("+(r.displayName||r.name||'Unknown')+")",c}const a='undefined'!=typeof window?t.useLayoutEffect:t.useEffect,{store:u}=effector.createDomain('Gate');e.connect=e=>t=>c(t,e),e.createComponent=r,e.createContextComponent=function(e,r,n){var o,c;const a=s(e);return c=o=class extends t.Component{constructor(...e){super(...e),this.renderProp=e=>n(this.props,e,this.context)}render(){return t.createElement(a,null,this.renderProp)}},o.contextType=r,c},e.createGate=function e(r="gate",s={}){const n=u(0),o=u(s),{set:c}=effector.createApi(o,{set:(e,t)=>t}),{open:a,close:i,destructor:p}=effector.createApi(n,{open:()=>l.predicate()&&1,close:()=>0,destructor:()=>0});class l extends t.PureComponent{static childGate(t="Subgate"){const s=e(r+"/"+t);s.predicate=()=>l.status.getState();let n=0,o=0;return s.open.watch(()=>{o||(n=1)}),s.close.watch(()=>{o||(n=0)}),l.status.watch(e=>{o=1,n&&e&&!s.status.getState()&&s.open(),o=0}),l.close.watch(()=>{o=1,s.close(),o=0}),l.destructor.watch(()=>s.destructor()),s}componentDidMount(){l.open()}componentWillUnmount(){l.close()}render(){return l.set(this.props),null}}l.predicate=()=>1,l.displayName="Gate:"+r,l.isOpen=0,l.current=o.getState(),l.open=a,l.close=i,l.status=n,l.state=o,l.set=c,l.destructor=p,l.isTerminated=0;const d=n.watch(e=>l.isOpen=e),f=o.watch(e=>l.current=e);n.map(e=>{e||(l.current=s)}),o.reset(i);const h=p.watch(()=>{l.isTerminated=1}),m=p.watch(()=>{m(),d(),f(),h(),l.status.off(l.open),l.status.off(l.close),l.status.off(l.destructor),l.state.off(l.set)});return l},e.createReactState=c,e.createStoreConsumer=s,e.unstable_createStoreProvider=function(e){var r,s;return s=r=class extends t.Component{constructor(...e){super(...e),this.state={currentValue:null}}static getDerivedStateFromProps(t){return e.setState(t.value),{currentValue:t.value}}render(){return this.props.children}},r.displayName=e.shortName+".Provider",r.defaultProps={children:null},s},e.useGate=(e,r={})=>{t.useEffect(()=>(e.open(),()=>e.close()),[e]),e.set(r)},e.useStore=n,e.useStoreMap=({store:e,keys:r,fn:s})=>{if(!effector.is.store(e))throw Error('useStoreMap expects a store');if(!Array.isArray(r))throw Error('useStoreMap expects an array as keys');if('function'!=typeof s)throw Error('useStoreMap expects a function');const o=t.useMemo(()=>e.map(e=>s(e,r)),r),c=n(o);return a(()=>()=>effector.clearNode(o,{deep:1}),r),c},Object.defineProperty(e,'__esModule',{value:1})},void('object'==typeof exports&&'undefined'!=typeof module?t(exports,require('react'),require('effector')):'function'==typeof define&&define.amd?define(['exports','react','effector'],t):t((e=e||self).effectorReact={},e.React,e.effector));var e,t; | ||
return e=this,t=function(e,t,effector){function r(e,r){var s,n,o,c;let a,u;if(effector.is.store(e))u=e;else if('function'==typeof e)a=e;else{if('object'!=typeof e||null===e)throw Error('shape should be a store or object with stores');u=effector.createStoreObject(e)}const i=null!==(s=null===(n=u)||void 0===n?void 0:n.shortName)&&void 0!==s?s:'Unknown',p=effector.createEvent(i+".View mounted"),l=effector.createEvent(i+".View unmounted");return c=o=class extends t.Component{constructor(...t){super(...t),this._unsubscribe=null,this._hasUnmounted=0,this.store='function'==typeof e?a(this.props):u,this.state={currentState:this.store.getState()}}componentDidMount(){p({props:this.props,state:this.store.getState()}),this.subscribe()}componentWillUnmount(){l({props:this.props,state:this.store.getState()}),this.unsubscribe(),this._hasUnmounted=1}render(){return r(this.props,this.state.currentState)}subscribe(){this._unsubscribe=this.store.watch(e=>{this._hasUnmounted||this.setState(t=>e===t.currentState?null:{currentState:e})})}unsubscribe(){'function'==typeof this._unsubscribe&&this._unsubscribe(),this._unsubscribe=null}},o.displayName=i+".View",o.mounted=p,o.unmounted=l,c}function s(e){return r(e,({children:e},t)=>e(t))}function n(e){if(!effector.is.store(e))throw Error('expect useStore argument to be a store');const r=t.useReducer(u,void 0,e.getState)[1];return a(()=>e.watch(r),[e]),e.getState()}function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var s in r)({}).hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e}).apply(this,arguments)}function c(e,r){const n=s(e),c=e=>t.createElement(n,null,s=>t.createElement(r,o({},e,s)));return c.displayName="Connect("+(r.displayName||r.name||'Unknown')+")",c}const a='undefined'!=typeof window?t.useLayoutEffect:t.useEffect,u=(e,t)=>t,{store:i}=effector.createDomain('Gate');e.connect=e=>t=>c(t,e),e.createComponent=r,e.createContextComponent=function(e,r,n){var o,c;const a=s(e);return c=o=class extends t.Component{constructor(...e){super(...e),this.renderProp=e=>n(this.props,e,this.context)}render(){return t.createElement(a,null,this.renderProp)}},o.contextType=r,c},e.createGate=function e(r="gate",s={}){const n=i(0),o=i(s),{set:c}=effector.createApi(o,{set:(e,t)=>t}),{open:a,close:u,destructor:p}=effector.createApi(n,{open:()=>l.predicate()&&1,close:()=>0,destructor:()=>0});class l extends t.PureComponent{static childGate(t="Subgate"){const s=e(r+"/"+t);s.predicate=()=>l.status.getState();let n=0,o=0;return s.open.watch(()=>{o||(n=1)}),s.close.watch(()=>{o||(n=0)}),l.status.watch(e=>{o=1,n&&e&&!s.status.getState()&&s.open(),o=0}),l.close.watch(()=>{o=1,s.close(),o=0}),l.destructor.watch(()=>s.destructor()),s}componentDidMount(){l.open()}componentWillUnmount(){l.close()}render(){return l.set(this.props),null}}l.predicate=()=>1,l.displayName="Gate:"+r,l.isOpen=0,l.current=o.getState(),l.open=a,l.close=u,l.status=n,l.state=o,l.set=c,l.destructor=p,l.isTerminated=0;const f=n.watch(e=>l.isOpen=e),d=o.watch(e=>l.current=e);n.map(e=>{e||(l.current=s)}),o.reset(u);const h=p.watch(()=>{l.isTerminated=1}),m=p.watch(()=>{m(),f(),d(),h(),l.status.off(l.open),l.status.off(l.close),l.status.off(l.destructor),l.state.off(l.set)});return l},e.createReactState=c,e.createStoreConsumer=s,e.unstable_createStoreProvider=function(e){var r,s;return s=r=class extends t.Component{constructor(...e){super(...e),this.state={currentValue:null}}static getDerivedStateFromProps(t){return e.setState(t.value),{currentValue:t.value}}render(){return this.props.children}},r.displayName=e.shortName+".Provider",r.defaultProps={children:null},s},e.useGate=(e,r={})=>{t.useEffect(()=>(e.open(),()=>e.close()),[e]),e.set(r)},e.useStore=n,e.useStoreMap=({store:e,keys:r,fn:s})=>{if(!effector.is.store(e))throw Error('useStoreMap expects a store');if(!Array.isArray(r))throw Error('useStoreMap expects an array as keys');if('function'!=typeof s)throw Error('useStoreMap expects a function');const o=t.useMemo(()=>effector.createStore(s(e.getState(),r)).on(e,(e,t)=>s(t,r)),r),c=n(o);return a(()=>()=>{o.off(e),effector.clearNode(o,{deep:1})},r),c},Object.defineProperty(e,'__esModule',{value:1})},void('object'==typeof exports&&'undefined'!=typeof module?t(exports,require('react'),require('effector')):'function'==typeof define&&define.amd?define(['exports','react','effector'],t):t((e=e||self).effectorReact={},e.React,e.effector));var e,t; | ||
//# sourceMappingURL=effector-react.umd.js.map |
{ | ||
"name": "effector-react", | ||
"version": "19.1.1", | ||
"version": "19.1.2", | ||
"description": "React bindings for effector", | ||
@@ -5,0 +5,0 @@ "main": "effector-react.cjs.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
76708
126