Socket
Socket
Sign inDemoInstall

react-model

Package Overview
Dependencies
Maintainers
2
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-model - npm Package Compare versions

Comparing version 4.1.2 to 4.1.3

2

dist/react-model.esm.js

@@ -1,1 +0,1 @@

import t,{enableES5 as e}from"immer";import{createContext as r,useState as n,useRef as o,useLayoutEffect as a,createElement as c,PureComponent as i}from"react";function s(){return(s=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function u(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}var l={Actions:{},AsyncState:{},Context:{__global:{}},Middlewares:{},Setter:{classSetter:void 0,functionSetter:{}},State:{},devTools:void 0,subscriptions:{},mutableState:{},uid:0,storeId:0,currentStoreId:"0",withDevTools:!1},f={logger:{enable:!1},devtools:{enable:!1},tryCatch:{enable:!0}},S=function(t,e){try{var r=t.next;return Promise.resolve(f.tryCatch.enable?r(e).catch(function(t){return console.log(t)}):r(e))}catch(t){return Promise.reject(t)}},m=function(t,e){try{var r=function(){return Promise.resolve(i(e))},n=t.action,o=t.modelName,a=t.consumerActions,c=t.params,i=t.next,u=t.Global,l=t.type,f=function(){if("u"!==l)return Promise.resolve(n(c,s({actions:a(u.Actions[o],{modelName:o}),state:u.State[o]},u.Context.__global||{},u.Context[o]||{}))).then(function(e){t.newState=e||null});t.newState=n()}();return Promise.resolve(f&&f.then?f.then(r):r())}catch(t){return Promise.reject(t)}},d=function(t,e){try{var r=t.modelName,n=t.newState,o=t.next,a=t.Global,c=t.type;return a.Setter.functionSetter[r]&&!t.disableSelectorUpdate&&Object.keys(a.Setter.functionSetter[r]).map(function(t){var e=a.Setter.functionSetter[r][t];e&&e.selector&&!e.selectorRef&&(e.selectorRef=e.selector(a.State[r]))}),Promise.resolve(function(){if(n||"u"===c)return E(r,n||{}),Promise.resolve(o(e))}())}catch(t){return Promise.reject(t)}},v=function(t,e){try{var r=t.modelName,n=t.next,o=t.Global,a=t.__hash,c=o.Setter.functionSetter[r];return"f"===t.type&&a&&c&&c[a]&&c[a].setState&&c[a].setState(o.State[r]),Promise.resolve(n(e))}catch(t){return Promise.reject(t)}},b=function(t,e){try{var r=t.next,n=t.Global.subscriptions[t.modelName+"_"+t.actionName];return n&&n.forEach(function(e){e(t)}),Promise.resolve(r(e))}catch(t){return Promise.reject(t)}},p=function(t,e){try{var r=t.Global;return!0===f.logger.enable||"function"==typeof f.logger.enable&&f.logger.enable(t)?(console.group("%c "+t.modelName+" State Change %c "+(new Date).toLocaleTimeString(),"color: gray; font-weight: lighter;","color: black; font-weight: bold;"),console.log("%c Previous","color: #9E9E9E; font-weight: bold",r.State[t.modelName]),console.log("%c Action","color: #03A9F4; font-weight: bold",t.actionName,"payload: "+t.params),Promise.resolve(t.next(e)).then(function(e){return console.log("%c Next","color: #4CAF50; font-weight: bold",r.State[t.modelName]),console.groupEnd(),e})):Promise.resolve(t.next(e))}catch(t){return Promise.reject(t)}},_=function(t,e){try{var r=t.Global;return Promise.resolve(t.next(e)).then(function(e){return r.withDevTools&&f.devtools.enable&&r.devTools.send(t.modelName+"_"+t.actionName,r.State),e})}catch(t){return Promise.reject(t)}},h=function(t,e){try{var r=t.modelName,n=t.next,o=t.Global,a=t.disableSelectorUpdate;return o.Setter.classSetter&&o.Setter.classSetter(o.State),o.Setter.functionSetter[r]&&Object.keys(o.Setter.functionSetter[r]).map(function(t){var e=o.Setter.functionSetter[r][t];if(e)if(!e.selector||a)e.setState(o.State[r]);else{var n=e.selector(o.State[r]);T(n,e.selectorRef)||(e.selectorRef=n,e.setState(o.State[r]))}}),Promise.resolve(n(e))}catch(t){return Promise.reject(t)}},y=[S,p,_,m,d,v,h,b],g={communicator:h,consoleDebugger:p,devToolsListener:_,getNewState:m,getNewStateWithCache:function(t){return void 0===t&&(t=5e3),function(e,r){try{var n=e.Global,o=e.modelName,a=e.next,c=e.actionName;return Promise.resolve(Promise.race([(0,e.action)(e.params,{actions:(0,e.consumerActions)(n.Actions[o],{modelName:o}),state:n.State[o]}),R(t,C(o,c))])).then(function(t){return e.newState=t||null,Promise.resolve(a(r))})}catch(t){return Promise.reject(t)}}},setNewState:d,stateUpdater:v,subscription:b,tryCatch:S,config:f},P=function(t,e){try{return e.next=function(t){return t.length>0?t[0](e,t.slice(1)):e.newState},Promise.resolve(t[0](e,t.slice(1)))}catch(t){return Promise.reject(t)}},w=r({}),N=w.Consumer;if(!console.group){var O=[],j="-".repeat(80);console.group=function(t){O.push(t),console.log("%c \nBEGIN GROUP: %c",j,t),console.groupEnd=function(){console.log("END GROUP: %c\n%c",O.pop(),j)}}}var A=function(t,e){var r={};return Object.keys(t).forEach(function(n){r[n]=function(t,e){return function(r,n){try{return Promise.resolve(P(y,{Global:l,action:t,actionName:t.name,consumerActions:A,middlewareConfig:n,modelName:e.modelName,newState:null,params:r,type:"o"}))}catch(t){return Promise.reject(t)}}}(t[n],e)}),r},E=function(e,r){if("function"==typeof r){var n=l.State[e];n=t(n,r),l.State=t(l.State,function(t){t[e]=n})}else l.State=t(l.State,function(t){t[e]=s({},t[e],r)});return l.State},R=function(t,e){return new Promise(function(r){return setTimeout(function(){console.log(t),r(e)},t)})},x=function(e,r){try{var n={__FROM_SERVER__:!0};return Promise.resolve(Promise.all(Object.keys(l.State).map(function(o){try{var a=function(){if(!e||!e.modelName||o===e.modelName||-1!==e.modelName.indexOf(o)){var a=function(e){r&&r.isServer?n[o]=e:l.State=t(l.State,function(t){t[o]=s({},t[o],e)})},c=l.AsyncState[o];return c?Promise.resolve(c(e)).then(a):a({})}}();return Promise.resolve(a&&a.then?a.then(function(){}):void 0)}catch(t){return Promise.reject(t)}}))).then(function(){return r&&r.isServer?n:l.State})}catch(t){return Promise.reject(t)}},C=function(t,e){var r=localStorage.getItem("__REACT_MODELX__"+t+"_"+e);return r?JSON.parse(r):null},T=function(t,e){if(t===e)return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;var r=Object.keys(t),n=Object.keys(e);if(r.length!==n.length)return!1;for(var o=0;o<r.length;o++)if(!Object.prototype.hasOwnProperty.call(e,r[o])||t[r[o]]!==e[r[o]])return!1;return!0};function G(e){var r=l.currentStoreId,n=l.mutableState[r].count;return l.mutableState[r].count+=1,l.mutableState[r].hasOwnProperty(n)||(l.mutableState[r][n]="function"==typeof e?e():e),[l.mutableState[r][n],function(e){try{return l.mutableState[r][n]="function"==typeof e?t(l.mutableState[r][n],e):l.mutableState[r][n]&&e&&"Object"===l.mutableState[r][n].constructor.name&&"Object"===e.constructor.name?s({},l.mutableState[r][n],e):e,Promise.resolve(P(y,{Global:l,action:function(){return"function"==typeof e?l.mutableState[r][n]:e},actionName:"setter",consumerActions:A,disableSelectorUpdate:!0,middlewareConfig:{},modelName:r,newState:{},params:void 0,type:"u"}))}catch(t){return Promise.reject(t)}}]}function I(t,e){var r="string"==typeof t;l.storeId+=r?0:1;var n=r?t:l.storeId.toString();l.Actions[n]||(l.Actions[n]={}),l.mutableState[n]||(l.mutableState[n]={count:0});var o=function(){return l.mutableState[n].count=0,l.currentStoreId=n,e?e():t()};return l.mutableState[n].selector=o,{useStore:function(){return V(n,o)},getState:function(){return o()}}}function D(e,r,n){if(void 0!==e.state){l.storeId+=1;var o="__"+l.storeId;l.State=t(l.State,function(t){t[o]=e.state}),e.middlewares&&(l.Middlewares[o]=e.middlewares),l.Actions[o]=e.actions,l.AsyncState[o]=e.asyncState,r&&(l.Context[o]=r);var a=F(o);return{__id:o,actions:a,getState:function(){return U(o)},subscribe:function(t,e){return k(o,t,e)},unsubscribe:function(t){return M(o,t)},useStore:function(t){return V(o,t)}}}if(e.actions){console.error("invalid model(s) schema: ",e);var c=function(t){return function(){return t}};return{__ERROR__:!0,actions:c({}),getActions:c({}),getInitialState:c({}),getState:c({}),subscribe:c(),unsubscribe:c(),useStore:c([{},{}])}}r&&!r.__FROM_SERVER__&&(l.State=t(l.State,function(t){Object.assign(t,r||{})})),n&&(l.Context.__global=n),Object.keys(e).forEach(function(n){var o=e[n];if(o.__ERROR__)return console.error(n+" model's schema is invalid"),l.State=t(l.State,function(t){t[n]={}}),void(l.Actions[n]={});!function(t){return void 0!==t.useStore}(o)?(r&&r.__FROM_SERVER__?l.State=t(l.State,function(t){t[n]=s({},o.state,r[n])}):l.State[n]||(l.State=t(l.State,function(t){t[n]=o.state})),o.middlewares&&(l.Middlewares[n]=o.middlewares),l.Actions[n]=o.actions,l.AsyncState[n]=o.asyncState):(l.State[n]&&r||(l.State=t(l.State,function(t){t[n]=t[o.__id]})),r&&r.__FROM_SERVER__&&(l.State=t(l.State,function(t){t[n]=s({},t[o.__id],r[n])})),l.Actions[n]=l.Actions[o.__id],l.AsyncState[n]=l.AsyncState[o.__id],l.Middlewares[n]=l.Middlewares[o.__id],l.Context[n]=l.Context[o.__id])});var i=Object.keys(e).reduce(function(t,e){var r;return s({},t,((r={})[e]=F(e),r))},{});return l.withDevTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__,l.withDevTools&&g.config.devtools.enable&&(l.devTools=window.__REDUX_DEVTOOLS_EXTENSION__,l.devTools.connect()),{actions:i,getActions:F,getInitialState:x,getState:U,subscribe:k,unsubscribe:M,useStore:V}}e();var M=function(t,e){k(t,e,void 0)},k=function(t,e,r){Array.isArray(e)?e.forEach(function(e){l.subscriptions[t+"_"+e]||(l.subscriptions[t+"_"+e]=[]),r?l.subscriptions[t+"_"+e].push(r):l.subscriptions[t+"_"+e]=[]}):(l.subscriptions[t+"_"+e]||(l.subscriptions[t+"_"+e]=[]),r?l.subscriptions[t+"_"+e].push(r):l.subscriptions[t+"_"+e]=[])},U=function(t){return l.State[t]},F=function(t,e){void 0===e&&(e={type:"o"});var r={};return Object.keys(l.Actions[t]).forEach(function(n){return r[n]=function(r,o){try{var a=s({action:l.Actions[t][n],actionName:n,consumerActions:A,middlewareConfig:o,modelName:t,newState:null,params:r},e,{Global:l});return Promise.resolve(P(l.Middlewares[t]?l.Middlewares[t]:y,a))}catch(t){return Promise.reject(t)}}}),r},V=function(t,e){var r,c=n({})[1],i=o(""),s=(r=[t],function(t){return r.reduce(function(t,e){return t&&t[e]?t[e]:null},t)})(l.mutableState),u=!!s,f=u?s.selector:e,S=u?s:U(t);if(a(function(){l.uid+=1;var e=""+l.uid;return i.current=e,l.Setter.functionSetter[t]||(l.Setter.functionSetter[t]={}),l.Setter.functionSetter[t][e]={setState:c,selector:f},function(){delete l.Setter.functionSetter[t][e]}},[]),u)return f(S);var m=F(t,{__hash:i.current,type:"f"});return[f?f(S):S,m]},L=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).state=l.State,e}return u(e,t),e.prototype.render=function(){var t=this.props.children;return l.Setter.classSetter=this.setState.bind(this),c(w.Provider,{value:s({},this.state)},t)},e}(i),X=function(t,e,r){return function(n){return function(o){function a(){return o.apply(this,arguments)||this}return u(a,o),a.prototype.render=function(){var o=this,a=this.props,i=a.state,u=void 0===i?{}:i,f=a.actions,S=void 0===f?{}:f;return c(N,null,function(a){var i=a[""+t],f=l.Actions[t];return c(n,Object.assign({},o.props,{state:s({},u,e?e(i):i),actions:s({},S,r?r(A(f,{modelName:t})):A(f,{modelName:t}))}))})},a}(i)}};export{N as Consumer,D as Model,L as Provider,y as actionMiddlewares,X as connect,I as createStore,x as getInitialState,U as getState,g as middlewares,G as useModel};
import t,{enableES5 as e}from"immer";import{createContext as r,useState as n,useRef as o,useLayoutEffect as i,createElement as c,PureComponent as a}from"react";function s(){return(s=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function u(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}var l={Actions:{},AsyncState:{},Context:{__global:{}},Middlewares:{},Setter:{classSetter:void 0,functionSetter:{}},State:{},devTools:void 0,subscriptions:{},mutableState:{},uid:0,storeId:0,currentStoreId:"0",withDevTools:!1},f={logger:{enable:!1},devtools:{enable:!1},tryCatch:{enable:!0}},S=function(t,e){try{var r=t.next;return Promise.resolve(f.tryCatch.enable?r(e).catch(function(t){return console.log(t)}):r(e))}catch(t){return Promise.reject(t)}},m=function(t,e){try{var r=function(){return Promise.resolve(a(e))},n=t.action,o=t.modelName,i=t.consumerActions,c=t.params,a=t.next,u=t.Global,l=t.type,f=function(){if("u"!==l)return Promise.resolve(n(c,s({actions:i(u.Actions[o],{modelName:o}),state:u.State[o]},u.Context.__global||{},u.Context[o]||{}))).then(function(e){t.newState=e||null});t.newState=n()}();return Promise.resolve(f&&f.then?f.then(r):r())}catch(t){return Promise.reject(t)}},d=function(t,e){try{var r=t.modelName,n=t.newState,o=t.next,i=t.Global,c=t.type;return i.Setter.functionSetter[r]&&!t.disableSelectorUpdate&&Object.keys(i.Setter.functionSetter[r]).map(function(t){var e=i.Setter.functionSetter[r][t];e&&e.selector&&!e.selectorRef&&(e.selectorRef=e.selector(i.State[r]))}),Promise.resolve(function(){if(n||"u"===c)return E(r,n||{}),Promise.resolve(o(e))}())}catch(t){return Promise.reject(t)}},b=function(t,e){try{var r=t.modelName,n=t.next,o=t.Global,i=t.__hash,c=o.Setter.functionSetter[r];return"f"===t.type&&i&&c&&c[i]&&c[i].setState&&c[i].setState(o.State[r]),Promise.resolve(n(e))}catch(t){return Promise.reject(t)}},v=function(t,e){try{var r=t.modelName,n=t.next,o=t.Global,i="u"===t.type?o.subscriptions[r]:o.subscriptions[r+"_"+t.actionName];return i&&i.forEach(function(e){e(t)}),Promise.resolve(n(e))}catch(t){return Promise.reject(t)}},p=function(t,e){try{var r=t.Global;return!0===f.logger.enable||"function"==typeof f.logger.enable&&f.logger.enable(t)?(console.group("%c "+t.modelName+" State Change %c "+(new Date).toLocaleTimeString(),"color: gray; font-weight: lighter;","color: black; font-weight: bold;"),console.log("%c Previous","color: #9E9E9E; font-weight: bold",r.State[t.modelName]),console.log("%c Action","color: #03A9F4; font-weight: bold",t.actionName,"payload: "+t.params),Promise.resolve(t.next(e)).then(function(e){return console.log("%c Next","color: #4CAF50; font-weight: bold",r.State[t.modelName]),console.groupEnd(),e})):Promise.resolve(t.next(e))}catch(t){return Promise.reject(t)}},_=function(t,e){try{var r=t.Global;return Promise.resolve(t.next(e)).then(function(e){return r.withDevTools&&f.devtools.enable&&r.devTools.send(t.modelName+"_"+t.actionName,r.State),e})}catch(t){return Promise.reject(t)}},h=function(t,e){try{var r=t.modelName,n=t.next,o=t.Global,i=t.disableSelectorUpdate;return o.Setter.classSetter&&o.Setter.classSetter(o.State),o.Setter.functionSetter[r]&&Object.keys(o.Setter.functionSetter[r]).map(function(t){var e=o.Setter.functionSetter[r][t];if(e)if(!e.selector||i)e.setState(o.State[r]);else{var n=e.selector(o.State[r]);T(n,e.selectorRef)||(e.selectorRef=n,e.setState(o.State[r]))}}),Promise.resolve(n(e))}catch(t){return Promise.reject(t)}},y=[S,p,_,m,d,b,h,v],g={communicator:h,consoleDebugger:p,devToolsListener:_,getNewState:m,getNewStateWithCache:function(t){return void 0===t&&(t=5e3),function(e,r){try{var n=e.Global,o=e.modelName,i=e.next,c=e.actionName;return Promise.resolve(Promise.race([(0,e.action)(e.params,{actions:(0,e.consumerActions)(n.Actions[o],{modelName:o}),state:n.State[o]}),R(t,C(o,c))])).then(function(t){return e.newState=t||null,Promise.resolve(i(r))})}catch(t){return Promise.reject(t)}}},setNewState:d,stateUpdater:b,subscription:v,tryCatch:S,config:f},P=function(t,e){try{return e.next=function(t){return t.length>0?t[0](e,t.slice(1)):e.newState},Promise.resolve(t[0](e,t.slice(1)))}catch(t){return Promise.reject(t)}},w=r({}),N=w.Consumer;if(!console.group){var O=[],j="-".repeat(80);console.group=function(t){O.push(t),console.log("%c \nBEGIN GROUP: %c",j,t),console.groupEnd=function(){console.log("END GROUP: %c\n%c",O.pop(),j)}}}var A=function(t,e){var r={};return Object.keys(t).forEach(function(n){r[n]=function(t,e){return function(r,n){try{return Promise.resolve(P(y,{Global:l,action:t,actionName:t.name,consumerActions:A,middlewareConfig:n,modelName:e.modelName,newState:null,params:r,type:"o"}))}catch(t){return Promise.reject(t)}}}(t[n],e)}),r},E=function(e,r){if("function"==typeof r){var n=l.State[e];n=t(n,r),l.State=t(l.State,function(t){t[e]=n})}else l.State=t(l.State,function(t){t[e]=s({},t[e],r)});return l.State},R=function(t,e){return new Promise(function(r){return setTimeout(function(){console.log(t),r(e)},t)})},x=function(e,r){try{var n={__FROM_SERVER__:!0};return Promise.resolve(Promise.all(Object.keys(l.State).map(function(o){try{var i=function(){if(!e||!e.modelName||o===e.modelName||-1!==e.modelName.indexOf(o)){var i=function(e){r&&r.isServer?n[o]=e:l.State=t(l.State,function(t){t[o]=s({},t[o],e)})},c=l.AsyncState[o];return c?Promise.resolve(c(e)).then(i):i({})}}();return Promise.resolve(i&&i.then?i.then(function(){}):void 0)}catch(t){return Promise.reject(t)}}))).then(function(){return r&&r.isServer?n:l.State})}catch(t){return Promise.reject(t)}},C=function(t,e){var r=localStorage.getItem("__REACT_MODELX__"+t+"_"+e);return r?JSON.parse(r):null},T=function(t,e){if(t===e)return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;var r=Object.keys(t),n=Object.keys(e);if(r.length!==n.length)return!1;for(var o=0;o<r.length;o++)if(!Object.prototype.hasOwnProperty.call(e,r[o])||t[r[o]]!==e[r[o]])return!1;return!0};function G(e){var r=l.currentStoreId,n=l.mutableState[r].count;return l.mutableState[r].count+=1,l.mutableState[r].hasOwnProperty(n)||(l.mutableState[r][n]="function"==typeof e?e():e),[l.mutableState[r][n],function(e){try{return l.mutableState[r][n]="function"==typeof e?t(l.mutableState[r][n],e):l.mutableState[r][n]&&e&&"Object"===l.mutableState[r][n].constructor.name&&"Object"===e.constructor.name?s({},l.mutableState[r][n],e):e,Promise.resolve(P(y,{Global:l,action:function(){return"function"==typeof e?l.mutableState[r][n]:e},actionName:"setter",consumerActions:A,disableSelectorUpdate:!0,middlewareConfig:{},modelName:r,newState:{},params:void 0,type:"u"}))}catch(t){return Promise.reject(t)}}]}function I(t,e){var r="string"==typeof t;l.storeId+=r?0:1;var n=r?t:l.storeId.toString();l.Actions[n]||(l.Actions[n]={}),l.mutableState[n]||(l.mutableState[n]={count:0});var o=function(){return l.mutableState[n].count=0,l.currentStoreId=n,e?e():t()};return l.mutableState[n].selector=o,{useStore:function(){return V(n,o)},getState:function(){return o()},subscribe:function(t){l.subscriptions[n]||(l.subscriptions[n]=[]),l.subscriptions[n].push(t)},unsubscribe:function(t){if(l.subscriptions[n]&&t){var e=l.subscriptions[n].indexOf(t);e>=0&&l.subscriptions[n].splice(e)}}}}function D(e,r,n){if(void 0!==e.state){l.storeId+=1;var o="__"+l.storeId;l.State=t(l.State,function(t){t[o]=e.state}),e.middlewares&&(l.Middlewares[o]=e.middlewares),l.Actions[o]=e.actions,l.AsyncState[o]=e.asyncState,r&&(l.Context[o]=r);var i=F(o);return{__id:o,actions:i,getState:function(){return U(o)},subscribe:function(t,e){return k(o,t,e)},unsubscribe:function(t){return M(o,t)},useStore:function(t){return V(o,t)}}}if(e.actions){console.error("invalid model(s) schema: ",e);var c=function(t){return function(){return t}};return{__ERROR__:!0,actions:c({}),getActions:c({}),getInitialState:c({}),getState:c({}),subscribe:c(),unsubscribe:c(),useStore:c([{},{}])}}r&&!r.__FROM_SERVER__&&(l.State=t(l.State,function(t){Object.assign(t,r||{})})),n&&(l.Context.__global=n),Object.keys(e).forEach(function(n){var o=e[n];if(o.__ERROR__)return console.error(n+" model's schema is invalid"),l.State=t(l.State,function(t){t[n]={}}),void(l.Actions[n]={});!function(t){return void 0!==t.useStore}(o)?(r&&r.__FROM_SERVER__?l.State=t(l.State,function(t){t[n]=s({},o.state,r[n])}):l.State[n]||(l.State=t(l.State,function(t){t[n]=o.state})),o.middlewares&&(l.Middlewares[n]=o.middlewares),l.Actions[n]=o.actions,l.AsyncState[n]=o.asyncState):(l.State[n]&&r||(l.State=t(l.State,function(t){t[n]=t[o.__id]})),r&&r.__FROM_SERVER__&&(l.State=t(l.State,function(t){t[n]=s({},t[o.__id],r[n])})),l.Actions[n]=l.Actions[o.__id],l.AsyncState[n]=l.AsyncState[o.__id],l.Middlewares[n]=l.Middlewares[o.__id],l.Context[n]=l.Context[o.__id])});var a=Object.keys(e).reduce(function(t,e){var r;return s({},t,((r={})[e]=F(e),r))},{});return l.withDevTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__,l.withDevTools&&g.config.devtools.enable&&(l.devTools=window.__REDUX_DEVTOOLS_EXTENSION__,l.devTools.connect()),{actions:a,getActions:F,getInitialState:x,getState:U,subscribe:k,unsubscribe:M,useStore:V}}e();var M=function(t,e){k(t,e,void 0)},k=function(t,e,r){Array.isArray(e)?e.forEach(function(e){l.subscriptions[t+"_"+e]||(l.subscriptions[t+"_"+e]=[]),r?l.subscriptions[t+"_"+e].push(r):l.subscriptions[t+"_"+e]=[]}):(l.subscriptions[t+"_"+e]||(l.subscriptions[t+"_"+e]=[]),r?l.subscriptions[t+"_"+e].push(r):l.subscriptions[t+"_"+e]=[])},U=function(t){return l.State[t]},F=function(t,e){void 0===e&&(e={type:"o"});var r={};return Object.keys(l.Actions[t]).forEach(function(n){return r[n]=function(r,o){try{var i=s({action:l.Actions[t][n],actionName:n,consumerActions:A,middlewareConfig:o,modelName:t,newState:null,params:r},e,{Global:l});return Promise.resolve(P(l.Middlewares[t]?l.Middlewares[t]:y,i))}catch(t){return Promise.reject(t)}}}),r},V=function(t,e){var r,c=n({})[1],a=o(""),s=(r=[t],function(t){return r.reduce(function(t,e){return t&&t[e]?t[e]:null},t)})(l.mutableState),u=!!s,f=u?s.selector:e,S=u?s:U(t);if(i(function(){l.uid+=1;var e=""+l.uid;return a.current=e,l.Setter.functionSetter[t]||(l.Setter.functionSetter[t]={}),l.Setter.functionSetter[t][e]={setState:c,selector:f},function(){delete l.Setter.functionSetter[t][e]}},[]),u)return f(S);var m=F(t,{__hash:a.current,type:"f"});return[f?f(S):S,m]},L=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).state=l.State,e}return u(e,t),e.prototype.render=function(){var t=this.props.children;return l.Setter.classSetter=this.setState.bind(this),c(w.Provider,{value:s({},this.state)},t)},e}(a),X=function(t,e,r){return function(n){return function(o){function i(){return o.apply(this,arguments)||this}return u(i,o),i.prototype.render=function(){var o=this,i=this.props,a=i.state,u=void 0===a?{}:a,f=i.actions,S=void 0===f?{}:f;return c(N,null,function(i){var a=i[""+t],f=l.Actions[t];return c(n,Object.assign({},o.props,{state:s({},u,e?e(a):a),actions:s({},S,r?r(A(f,{modelName:t})):A(f,{modelName:t}))}))})},i}(a)}};export{N as Consumer,D as Model,L as Provider,y as actionMiddlewares,X as connect,I as createStore,x as getInitialState,U as getState,g as middlewares,G as useModel};

@@ -1,1 +0,1 @@

var t,e=require("immer"),r=(t=e)&&"object"==typeof t&&"default"in t?t.default:t,n=require("react");function o(){return(o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function a(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}var c={Actions:{},AsyncState:{},Context:{__global:{}},Middlewares:{},Setter:{classSetter:void 0,functionSetter:{}},State:{},devTools:void 0,subscriptions:{},mutableState:{},uid:0,storeId:0,currentStoreId:"0",withDevTools:!1},i={logger:{enable:!1},devtools:{enable:!1},tryCatch:{enable:!0}},s=function(t,e){try{var r=t.next;return Promise.resolve(i.tryCatch.enable?r(e).catch(function(t){return console.log(t)}):r(e))}catch(t){return Promise.reject(t)}},u=function(t,e){try{var r=function(){return Promise.resolve(s(e))},n=t.action,a=t.modelName,c=t.consumerActions,i=t.params,s=t.next,u=t.Global,l=t.type,f=function(){if("u"!==l)return Promise.resolve(n(i,o({actions:c(u.Actions[a],{modelName:a}),state:u.State[a]},u.Context.__global||{},u.Context[a]||{}))).then(function(e){t.newState=e||null});t.newState=n()}();return Promise.resolve(f&&f.then?f.then(r):r())}catch(t){return Promise.reject(t)}},l=function(t,e){try{var r=t.modelName,n=t.newState,o=t.next,a=t.Global,c=t.type;return a.Setter.functionSetter[r]&&!t.disableSelectorUpdate&&Object.keys(a.Setter.functionSetter[r]).map(function(t){var e=a.Setter.functionSetter[r][t];e&&e.selector&&!e.selectorRef&&(e.selectorRef=e.selector(a.State[r]))}),Promise.resolve(function(){if(n||"u"===c)return N(r,n||{}),Promise.resolve(o(e))}())}catch(t){return Promise.reject(t)}},f=function(t,e){try{var r=t.modelName,n=t.next,o=t.Global,a=t.__hash,c=o.Setter.functionSetter[r];return"f"===t.type&&a&&c&&c[a]&&c[a].setState&&c[a].setState(o.State[r]),Promise.resolve(n(e))}catch(t){return Promise.reject(t)}},S=function(t,e){try{var r=t.next,n=t.Global.subscriptions[t.modelName+"_"+t.actionName];return n&&n.forEach(function(e){e(t)}),Promise.resolve(r(e))}catch(t){return Promise.reject(t)}},m=function(t,e){try{var r=t.Global;return!0===i.logger.enable||"function"==typeof i.logger.enable&&i.logger.enable(t)?(console.group("%c "+t.modelName+" State Change %c "+(new Date).toLocaleTimeString(),"color: gray; font-weight: lighter;","color: black; font-weight: bold;"),console.log("%c Previous","color: #9E9E9E; font-weight: bold",r.State[t.modelName]),console.log("%c Action","color: #03A9F4; font-weight: bold",t.actionName,"payload: "+t.params),Promise.resolve(t.next(e)).then(function(e){return console.log("%c Next","color: #4CAF50; font-weight: bold",r.State[t.modelName]),console.groupEnd(),e})):Promise.resolve(t.next(e))}catch(t){return Promise.reject(t)}},d=function(t,e){try{var r=t.Global;return Promise.resolve(t.next(e)).then(function(e){return r.withDevTools&&i.devtools.enable&&r.devTools.send(t.modelName+"_"+t.actionName,r.State),e})}catch(t){return Promise.reject(t)}},v=function(t,e){try{var r=t.modelName,n=t.next,o=t.Global,a=t.disableSelectorUpdate;return o.Setter.classSetter&&o.Setter.classSetter(o.State),o.Setter.functionSetter[r]&&Object.keys(o.Setter.functionSetter[r]).map(function(t){var e=o.Setter.functionSetter[r][t];if(e)if(!e.selector||a)e.setState(o.State[r]);else{var n=e.selector(o.State[r]);A(n,e.selectorRef)||(e.selectorRef=n,e.setState(o.State[r]))}}),Promise.resolve(n(e))}catch(t){return Promise.reject(t)}},p=[s,m,d,u,l,f,v,S],b={communicator:v,consoleDebugger:m,devToolsListener:d,getNewState:u,getNewStateWithCache:function(t){return void 0===t&&(t=5e3),function(e,r){try{var n=e.Global,o=e.modelName,a=e.next,c=e.actionName;return Promise.resolve(Promise.race([(0,e.action)(e.params,{actions:(0,e.consumerActions)(n.Actions[o],{modelName:o}),state:n.State[o]}),E(t,j(o,c))])).then(function(t){return e.newState=t||null,Promise.resolve(a(r))})}catch(t){return Promise.reject(t)}}},setNewState:l,stateUpdater:f,subscription:S,tryCatch:s,config:i},_=function(t,e){try{return e.next=function(t){return t.length>0?t[0](e,t.slice(1)):e.newState},Promise.resolve(t[0](e,t.slice(1)))}catch(t){return Promise.reject(t)}},h=n.createContext({}),y=h.Consumer;if(!console.group){var g=[],P="-".repeat(80);console.group=function(t){g.push(t),console.log("%c \nBEGIN GROUP: %c",P,t),console.groupEnd=function(){console.log("END GROUP: %c\n%c",g.pop(),P)}}}var w=function(t,e){var r={};return Object.keys(t).forEach(function(n){r[n]=function(t,e){return function(r,n){try{return Promise.resolve(_(p,{Global:c,action:t,actionName:t.name,consumerActions:w,middlewareConfig:n,modelName:e.modelName,newState:null,params:r,type:"o"}))}catch(t){return Promise.reject(t)}}}(t[n],e)}),r},N=function(t,e){if("function"==typeof e){var n=c.State[t];n=r(n,e),c.State=r(c.State,function(e){e[t]=n})}else c.State=r(c.State,function(r){r[t]=o({},r[t],e)});return c.State},E=function(t,e){return new Promise(function(r){return setTimeout(function(){console.log(t),r(e)},t)})},O=function(t,e){try{var n={__FROM_SERVER__:!0};return Promise.resolve(Promise.all(Object.keys(c.State).map(function(a){try{var i=function(){if(!t||!t.modelName||a===t.modelName||-1!==t.modelName.indexOf(a)){var i=function(t){e&&e.isServer?n[a]=t:c.State=r(c.State,function(e){e[a]=o({},e[a],t)})},s=c.AsyncState[a];return s?Promise.resolve(s(t)).then(i):i({})}}();return Promise.resolve(i&&i.then?i.then(function(){}):void 0)}catch(t){return Promise.reject(t)}}))).then(function(){return e&&e.isServer?n:c.State})}catch(t){return Promise.reject(t)}},j=function(t,e){var r=localStorage.getItem("__REACT_MODELX__"+t+"_"+e);return r?JSON.parse(r):null},A=function(t,e){if(t===e)return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;var r=Object.keys(t),n=Object.keys(e);if(r.length!==n.length)return!1;for(var o=0;o<r.length;o++)if(!Object.prototype.hasOwnProperty.call(e,r[o])||t[r[o]]!==e[r[o]])return!1;return!0};e.enableES5();var x=function(t,e){R(t,e,void 0)},R=function(t,e,r){Array.isArray(e)?e.forEach(function(e){c.subscriptions[t+"_"+e]||(c.subscriptions[t+"_"+e]=[]),r?c.subscriptions[t+"_"+e].push(r):c.subscriptions[t+"_"+e]=[]}):(c.subscriptions[t+"_"+e]||(c.subscriptions[t+"_"+e]=[]),r?c.subscriptions[t+"_"+e].push(r):c.subscriptions[t+"_"+e]=[])},C=function(t){return c.State[t]},T=function(t,e){void 0===e&&(e={type:"o"});var r={};return Object.keys(c.Actions[t]).forEach(function(n){return r[n]=function(r,a){try{var i=o({action:c.Actions[t][n],actionName:n,consumerActions:w,middlewareConfig:a,modelName:t,newState:null,params:r},e,{Global:c});return Promise.resolve(_(c.Middlewares[t]?c.Middlewares[t]:p,i))}catch(t){return Promise.reject(t)}}}),r},I=function(t,e){var r,o=n.useState({})[1],a=n.useRef(""),i=(r=[t],function(t){return r.reduce(function(t,e){return t&&t[e]?t[e]:null},t)})(c.mutableState),s=!!i,u=s?i.selector:e,l=s?i:C(t);if(n.useLayoutEffect(function(){c.uid+=1;var e=""+c.uid;return a.current=e,c.Setter.functionSetter[t]||(c.Setter.functionSetter[t]={}),c.Setter.functionSetter[t][e]={setState:o,selector:u},function(){delete c.Setter.functionSetter[t][e]}},[]),s)return u(l);var f=T(t,{__hash:a.current,type:"f"});return[u?u(l):l,f]},M=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).state=c.State,e}return a(e,t),e.prototype.render=function(){var t=this.props.children;return c.Setter.classSetter=this.setState.bind(this),n.createElement(h.Provider,{value:o({},this.state)},t)},e}(n.PureComponent);exports.Consumer=y,exports.Model=function(t,e,n){if(void 0!==t.state){c.storeId+=1;var a="__"+c.storeId;c.State=r(c.State,function(e){e[a]=t.state}),t.middlewares&&(c.Middlewares[a]=t.middlewares),c.Actions[a]=t.actions,c.AsyncState[a]=t.asyncState,e&&(c.Context[a]=e);var i=T(a);return{__id:a,actions:i,getState:function(){return C(a)},subscribe:function(t,e){return R(a,t,e)},unsubscribe:function(t){return x(a,t)},useStore:function(t){return I(a,t)}}}if(t.actions){console.error("invalid model(s) schema: ",t);var s=function(t){return function(){return t}};return{__ERROR__:!0,actions:s({}),getActions:s({}),getInitialState:s({}),getState:s({}),subscribe:s(),unsubscribe:s(),useStore:s([{},{}])}}e&&!e.__FROM_SERVER__&&(c.State=r(c.State,function(t){Object.assign(t,e||{})})),n&&(c.Context.__global=n),Object.keys(t).forEach(function(n){var a=t[n];if(a.__ERROR__)return console.error(n+" model's schema is invalid"),c.State=r(c.State,function(t){t[n]={}}),void(c.Actions[n]={});void 0===a.useStore?(e&&e.__FROM_SERVER__?c.State=r(c.State,function(t){t[n]=o({},a.state,e[n])}):c.State[n]||(c.State=r(c.State,function(t){t[n]=a.state})),a.middlewares&&(c.Middlewares[n]=a.middlewares),c.Actions[n]=a.actions,c.AsyncState[n]=a.asyncState):(c.State[n]&&e||(c.State=r(c.State,function(t){t[n]=t[a.__id]})),e&&e.__FROM_SERVER__&&(c.State=r(c.State,function(t){t[n]=o({},t[a.__id],e[n])})),c.Actions[n]=c.Actions[a.__id],c.AsyncState[n]=c.AsyncState[a.__id],c.Middlewares[n]=c.Middlewares[a.__id],c.Context[n]=c.Context[a.__id])});var u=Object.keys(t).reduce(function(t,e){var r;return o({},t,((r={})[e]=T(e),r))},{});return c.withDevTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__,c.withDevTools&&b.config.devtools.enable&&(c.devTools=window.__REDUX_DEVTOOLS_EXTENSION__,c.devTools.connect()),{actions:u,getActions:T,getInitialState:O,getState:C,subscribe:R,unsubscribe:x,useStore:I}},exports.Provider=M,exports.actionMiddlewares=p,exports.connect=function(t,e,r){return function(i){return function(s){function u(){return s.apply(this,arguments)||this}return a(u,s),u.prototype.render=function(){var a=this,s=this.props,u=s.state,l=void 0===u?{}:u,f=s.actions,S=void 0===f?{}:f;return n.createElement(y,null,function(s){var u=s[""+t],f=c.Actions[t];return n.createElement(i,Object.assign({},a.props,{state:o({},l,e?e(u):u),actions:o({},S,r?r(w(f,{modelName:t})):w(f,{modelName:t}))}))})},u}(n.PureComponent)}},exports.createStore=function(t,e){var r="string"==typeof t;c.storeId+=r?0:1;var n=r?t:c.storeId.toString();c.Actions[n]||(c.Actions[n]={}),c.mutableState[n]||(c.mutableState[n]={count:0});var o=function(){return c.mutableState[n].count=0,c.currentStoreId=n,e?e():t()};return c.mutableState[n].selector=o,{useStore:function(){return I(n,o)},getState:function(){return o()}}},exports.getInitialState=O,exports.getState=C,exports.middlewares=b,exports.useModel=function(t){var e=c.currentStoreId,n=c.mutableState[e].count;return c.mutableState[e].count+=1,c.mutableState[e].hasOwnProperty(n)||(c.mutableState[e][n]="function"==typeof t?t():t),[c.mutableState[e][n],function(t){try{return c.mutableState[e][n]="function"==typeof t?r(c.mutableState[e][n],t):c.mutableState[e][n]&&t&&"Object"===c.mutableState[e][n].constructor.name&&"Object"===t.constructor.name?o({},c.mutableState[e][n],t):t,Promise.resolve(_(p,{Global:c,action:function(){return"function"==typeof t?c.mutableState[e][n]:t},actionName:"setter",consumerActions:w,disableSelectorUpdate:!0,middlewareConfig:{},modelName:e,newState:{},params:void 0,type:"u"}))}catch(t){return Promise.reject(t)}}]};
var t,e=require("immer"),r=(t=e)&&"object"==typeof t&&"default"in t?t.default:t,n=require("react");function o(){return(o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}var a={Actions:{},AsyncState:{},Context:{__global:{}},Middlewares:{},Setter:{classSetter:void 0,functionSetter:{}},State:{},devTools:void 0,subscriptions:{},mutableState:{},uid:0,storeId:0,currentStoreId:"0",withDevTools:!1},c={logger:{enable:!1},devtools:{enable:!1},tryCatch:{enable:!0}},s=function(t,e){try{var r=t.next;return Promise.resolve(c.tryCatch.enable?r(e).catch(function(t){return console.log(t)}):r(e))}catch(t){return Promise.reject(t)}},u=function(t,e){try{var r=function(){return Promise.resolve(s(e))},n=t.action,i=t.modelName,a=t.consumerActions,c=t.params,s=t.next,u=t.Global,l=t.type,f=function(){if("u"!==l)return Promise.resolve(n(c,o({actions:a(u.Actions[i],{modelName:i}),state:u.State[i]},u.Context.__global||{},u.Context[i]||{}))).then(function(e){t.newState=e||null});t.newState=n()}();return Promise.resolve(f&&f.then?f.then(r):r())}catch(t){return Promise.reject(t)}},l=function(t,e){try{var r=t.modelName,n=t.newState,o=t.next,i=t.Global,a=t.type;return i.Setter.functionSetter[r]&&!t.disableSelectorUpdate&&Object.keys(i.Setter.functionSetter[r]).map(function(t){var e=i.Setter.functionSetter[r][t];e&&e.selector&&!e.selectorRef&&(e.selectorRef=e.selector(i.State[r]))}),Promise.resolve(function(){if(n||"u"===a)return N(r,n||{}),Promise.resolve(o(e))}())}catch(t){return Promise.reject(t)}},f=function(t,e){try{var r=t.modelName,n=t.next,o=t.Global,i=t.__hash,a=o.Setter.functionSetter[r];return"f"===t.type&&i&&a&&a[i]&&a[i].setState&&a[i].setState(o.State[r]),Promise.resolve(n(e))}catch(t){return Promise.reject(t)}},S=function(t,e){try{var r=t.modelName,n=t.next,o=t.Global,i="u"===t.type?o.subscriptions[r]:o.subscriptions[r+"_"+t.actionName];return i&&i.forEach(function(e){e(t)}),Promise.resolve(n(e))}catch(t){return Promise.reject(t)}},m=function(t,e){try{var r=t.Global;return!0===c.logger.enable||"function"==typeof c.logger.enable&&c.logger.enable(t)?(console.group("%c "+t.modelName+" State Change %c "+(new Date).toLocaleTimeString(),"color: gray; font-weight: lighter;","color: black; font-weight: bold;"),console.log("%c Previous","color: #9E9E9E; font-weight: bold",r.State[t.modelName]),console.log("%c Action","color: #03A9F4; font-weight: bold",t.actionName,"payload: "+t.params),Promise.resolve(t.next(e)).then(function(e){return console.log("%c Next","color: #4CAF50; font-weight: bold",r.State[t.modelName]),console.groupEnd(),e})):Promise.resolve(t.next(e))}catch(t){return Promise.reject(t)}},d=function(t,e){try{var r=t.Global;return Promise.resolve(t.next(e)).then(function(e){return r.withDevTools&&c.devtools.enable&&r.devTools.send(t.modelName+"_"+t.actionName,r.State),e})}catch(t){return Promise.reject(t)}},p=function(t,e){try{var r=t.modelName,n=t.next,o=t.Global,i=t.disableSelectorUpdate;return o.Setter.classSetter&&o.Setter.classSetter(o.State),o.Setter.functionSetter[r]&&Object.keys(o.Setter.functionSetter[r]).map(function(t){var e=o.Setter.functionSetter[r][t];if(e)if(!e.selector||i)e.setState(o.State[r]);else{var n=e.selector(o.State[r]);x(n,e.selectorRef)||(e.selectorRef=n,e.setState(o.State[r]))}}),Promise.resolve(n(e))}catch(t){return Promise.reject(t)}},b=[s,m,d,u,l,f,p,S],v={communicator:p,consoleDebugger:m,devToolsListener:d,getNewState:u,getNewStateWithCache:function(t){return void 0===t&&(t=5e3),function(e,r){try{var n=e.Global,o=e.modelName,i=e.next,a=e.actionName;return Promise.resolve(Promise.race([(0,e.action)(e.params,{actions:(0,e.consumerActions)(n.Actions[o],{modelName:o}),state:n.State[o]}),O(t,j(o,a))])).then(function(t){return e.newState=t||null,Promise.resolve(i(r))})}catch(t){return Promise.reject(t)}}},setNewState:l,stateUpdater:f,subscription:S,tryCatch:s,config:c},_=function(t,e){try{return e.next=function(t){return t.length>0?t[0](e,t.slice(1)):e.newState},Promise.resolve(t[0](e,t.slice(1)))}catch(t){return Promise.reject(t)}},h=n.createContext({}),y=h.Consumer;if(!console.group){var g=[],P="-".repeat(80);console.group=function(t){g.push(t),console.log("%c \nBEGIN GROUP: %c",P,t),console.groupEnd=function(){console.log("END GROUP: %c\n%c",g.pop(),P)}}}var w=function(t,e){var r={};return Object.keys(t).forEach(function(n){r[n]=function(t,e){return function(r,n){try{return Promise.resolve(_(b,{Global:a,action:t,actionName:t.name,consumerActions:w,middlewareConfig:n,modelName:e.modelName,newState:null,params:r,type:"o"}))}catch(t){return Promise.reject(t)}}}(t[n],e)}),r},N=function(t,e){if("function"==typeof e){var n=a.State[t];n=r(n,e),a.State=r(a.State,function(e){e[t]=n})}else a.State=r(a.State,function(r){r[t]=o({},r[t],e)});return a.State},O=function(t,e){return new Promise(function(r){return setTimeout(function(){console.log(t),r(e)},t)})},E=function(t,e){try{var n={__FROM_SERVER__:!0};return Promise.resolve(Promise.all(Object.keys(a.State).map(function(i){try{var c=function(){if(!t||!t.modelName||i===t.modelName||-1!==t.modelName.indexOf(i)){var c=function(t){e&&e.isServer?n[i]=t:a.State=r(a.State,function(e){e[i]=o({},e[i],t)})},s=a.AsyncState[i];return s?Promise.resolve(s(t)).then(c):c({})}}();return Promise.resolve(c&&c.then?c.then(function(){}):void 0)}catch(t){return Promise.reject(t)}}))).then(function(){return e&&e.isServer?n:a.State})}catch(t){return Promise.reject(t)}},j=function(t,e){var r=localStorage.getItem("__REACT_MODELX__"+t+"_"+e);return r?JSON.parse(r):null},x=function(t,e){if(t===e)return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;var r=Object.keys(t),n=Object.keys(e);if(r.length!==n.length)return!1;for(var o=0;o<r.length;o++)if(!Object.prototype.hasOwnProperty.call(e,r[o])||t[r[o]]!==e[r[o]])return!1;return!0};e.enableES5();var A=function(t,e){R(t,e,void 0)},R=function(t,e,r){Array.isArray(e)?e.forEach(function(e){a.subscriptions[t+"_"+e]||(a.subscriptions[t+"_"+e]=[]),r?a.subscriptions[t+"_"+e].push(r):a.subscriptions[t+"_"+e]=[]}):(a.subscriptions[t+"_"+e]||(a.subscriptions[t+"_"+e]=[]),r?a.subscriptions[t+"_"+e].push(r):a.subscriptions[t+"_"+e]=[])},C=function(t){return a.State[t]},T=function(t,e){void 0===e&&(e={type:"o"});var r={};return Object.keys(a.Actions[t]).forEach(function(n){return r[n]=function(r,i){try{var c=o({action:a.Actions[t][n],actionName:n,consumerActions:w,middlewareConfig:i,modelName:t,newState:null,params:r},e,{Global:a});return Promise.resolve(_(a.Middlewares[t]?a.Middlewares[t]:b,c))}catch(t){return Promise.reject(t)}}}),r},I=function(t,e){var r,o=n.useState({})[1],i=n.useRef(""),c=(r=[t],function(t){return r.reduce(function(t,e){return t&&t[e]?t[e]:null},t)})(a.mutableState),s=!!c,u=s?c.selector:e,l=s?c:C(t);if(n.useLayoutEffect(function(){a.uid+=1;var e=""+a.uid;return i.current=e,a.Setter.functionSetter[t]||(a.Setter.functionSetter[t]={}),a.Setter.functionSetter[t][e]={setState:o,selector:u},function(){delete a.Setter.functionSetter[t][e]}},[]),s)return u(l);var f=T(t,{__hash:i.current,type:"f"});return[u?u(l):l,f]},M=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).state=a.State,e}return i(e,t),e.prototype.render=function(){var t=this.props.children;return a.Setter.classSetter=this.setState.bind(this),n.createElement(h.Provider,{value:o({},this.state)},t)},e}(n.PureComponent);exports.Consumer=y,exports.Model=function(t,e,n){if(void 0!==t.state){a.storeId+=1;var i="__"+a.storeId;a.State=r(a.State,function(e){e[i]=t.state}),t.middlewares&&(a.Middlewares[i]=t.middlewares),a.Actions[i]=t.actions,a.AsyncState[i]=t.asyncState,e&&(a.Context[i]=e);var c=T(i);return{__id:i,actions:c,getState:function(){return C(i)},subscribe:function(t,e){return R(i,t,e)},unsubscribe:function(t){return A(i,t)},useStore:function(t){return I(i,t)}}}if(t.actions){console.error("invalid model(s) schema: ",t);var s=function(t){return function(){return t}};return{__ERROR__:!0,actions:s({}),getActions:s({}),getInitialState:s({}),getState:s({}),subscribe:s(),unsubscribe:s(),useStore:s([{},{}])}}e&&!e.__FROM_SERVER__&&(a.State=r(a.State,function(t){Object.assign(t,e||{})})),n&&(a.Context.__global=n),Object.keys(t).forEach(function(n){var i=t[n];if(i.__ERROR__)return console.error(n+" model's schema is invalid"),a.State=r(a.State,function(t){t[n]={}}),void(a.Actions[n]={});void 0===i.useStore?(e&&e.__FROM_SERVER__?a.State=r(a.State,function(t){t[n]=o({},i.state,e[n])}):a.State[n]||(a.State=r(a.State,function(t){t[n]=i.state})),i.middlewares&&(a.Middlewares[n]=i.middlewares),a.Actions[n]=i.actions,a.AsyncState[n]=i.asyncState):(a.State[n]&&e||(a.State=r(a.State,function(t){t[n]=t[i.__id]})),e&&e.__FROM_SERVER__&&(a.State=r(a.State,function(t){t[n]=o({},t[i.__id],e[n])})),a.Actions[n]=a.Actions[i.__id],a.AsyncState[n]=a.AsyncState[i.__id],a.Middlewares[n]=a.Middlewares[i.__id],a.Context[n]=a.Context[i.__id])});var u=Object.keys(t).reduce(function(t,e){var r;return o({},t,((r={})[e]=T(e),r))},{});return a.withDevTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__,a.withDevTools&&v.config.devtools.enable&&(a.devTools=window.__REDUX_DEVTOOLS_EXTENSION__,a.devTools.connect()),{actions:u,getActions:T,getInitialState:E,getState:C,subscribe:R,unsubscribe:A,useStore:I}},exports.Provider=M,exports.actionMiddlewares=b,exports.connect=function(t,e,r){return function(c){return function(s){function u(){return s.apply(this,arguments)||this}return i(u,s),u.prototype.render=function(){var i=this,s=this.props,u=s.state,l=void 0===u?{}:u,f=s.actions,S=void 0===f?{}:f;return n.createElement(y,null,function(s){var u=s[""+t],f=a.Actions[t];return n.createElement(c,Object.assign({},i.props,{state:o({},l,e?e(u):u),actions:o({},S,r?r(w(f,{modelName:t})):w(f,{modelName:t}))}))})},u}(n.PureComponent)}},exports.createStore=function(t,e){var r="string"==typeof t;a.storeId+=r?0:1;var n=r?t:a.storeId.toString();a.Actions[n]||(a.Actions[n]={}),a.mutableState[n]||(a.mutableState[n]={count:0});var o=function(){return a.mutableState[n].count=0,a.currentStoreId=n,e?e():t()};return a.mutableState[n].selector=o,{useStore:function(){return I(n,o)},getState:function(){return o()},subscribe:function(t){a.subscriptions[n]||(a.subscriptions[n]=[]),a.subscriptions[n].push(t)},unsubscribe:function(t){if(a.subscriptions[n]&&t){var e=a.subscriptions[n].indexOf(t);e>=0&&a.subscriptions[n].splice(e)}}}},exports.getInitialState=E,exports.getState=C,exports.middlewares=v,exports.useModel=function(t){var e=a.currentStoreId,n=a.mutableState[e].count;return a.mutableState[e].count+=1,a.mutableState[e].hasOwnProperty(n)||(a.mutableState[e][n]="function"==typeof t?t():t),[a.mutableState[e][n],function(t){try{return a.mutableState[e][n]="function"==typeof t?r(a.mutableState[e][n],t):a.mutableState[e][n]&&t&&"Object"===a.mutableState[e][n].constructor.name&&"Object"===t.constructor.name?o({},a.mutableState[e][n],t):t,Promise.resolve(_(b,{Global:a,action:function(){return"function"==typeof t?a.mutableState[e][n]:t},actionName:"setter",consumerActions:w,disableSelectorUpdate:!0,middlewareConfig:{},modelName:e,newState:{},params:void 0,type:"u"}))}catch(t){return Promise.reject(t)}}]};

@@ -1,1 +0,1 @@

import t,{enableES5 as e}from"immer";import{createContext as o,useState as a,useRef as n,useLayoutEffect as s,PureComponent as r,createElement as c}from"react";var i={Actions:{},AsyncState:{},Context:{__global:{}},Middlewares:{},Setter:{classSetter:void 0,functionSetter:{}},State:{},devTools:void 0,subscriptions:{},mutableState:{},uid:0,storeId:0,currentStoreId:"0",withDevTools:!1};const l={logger:{enable:!1},devtools:{enable:!1},tryCatch:{enable:!0}},u=async(t,e)=>{const{next:o}=t;return l.tryCatch.enable?await o(e).catch(t=>console.log(t)):await o(e)},S=async(t,e)=>{const{action:o,modelName:a,consumerActions:n,params:s,next:r,Global:c,type:i}=t;return t.newState="u"===i?o():await o(s,{actions:n(c.Actions[a],{modelName:a}),state:c.State[a],...c.Context.__global||{},...c.Context[a]||{}})||null,await r(e)},d=async(t,e)=>{const{modelName:o,newState:a,next:n,Global:s,disableSelectorUpdate:r,type:c}=t;if(s.Setter.functionSetter[o]&&!r&&Object.keys(s.Setter.functionSetter[o]).map(t=>{const e=s.Setter.functionSetter[o][t];e&&e.selector&&!e.selectorRef&&(e.selectorRef=e.selector(s.State[o]))}),a||"u"===c)return A(o,a||{}),await n(e)},m=async(t,e)=>{const{modelName:o,next:a,Global:n,__hash:s}=t,r=n.Setter.functionSetter[o];return"f"===t.type&&s&&r&&r[s]&&r[s].setState&&r[s].setState(n.State[o]),await a(e)},b=async(t,e)=>{const{modelName:o,actionName:a,next:n,Global:s}=t,r=s.subscriptions[`${o}_${a}`];return r&&r.forEach(e=>{e(t)}),await n(e)},_=async(t,e)=>{const{Global:o}=t;if(!0===l.logger.enable||"function"==typeof l.logger.enable&&l.logger.enable(t)){console.group(`%c ${t.modelName} State Change %c ${(new Date).toLocaleTimeString()}`,"color: gray; font-weight: lighter;","color: black; font-weight: bold;"),console.log("%c Previous","color: #9E9E9E; font-weight: bold",o.State[t.modelName]),console.log("%c Action","color: #03A9F4; font-weight: bold",t.actionName,"payload: "+t.params);const a=await t.next(e);return console.log("%c Next","color: #4CAF50; font-weight: bold",o.State[t.modelName]),console.groupEnd(),a}return await t.next(e)},f=async(t,e)=>{const{Global:o}=t,a=await t.next(e);return o.withDevTools&&l.devtools.enable&&o.devTools.send(`${t.modelName}_${t.actionName}`,o.State),a},p=async(t,e)=>{const{modelName:o,next:a,Global:n,disableSelectorUpdate:s}=t;return n.Setter.classSetter&&n.Setter.classSetter(n.State),n.Setter.functionSetter[o]&&Object.keys(n.Setter.functionSetter[o]).map(t=>{const e=n.Setter.functionSetter[o][t];if(e)if(!e.selector||s)e.setState(n.State[o]);else{const t=e.selector(n.State[o]);$(t,e.selectorRef)||(e.selectorRef=t,e.setState(n.State[o]))}}),await a(e)},w=[u,_,f,S,d,m,p,b],g={communicator:p,consoleDebugger:_,devToolsListener:f,getNewState:S,getNewStateWithCache:(t=5e3)=>async(e,o)=>{const{action:a,Global:n,modelName:s,consumerActions:r,params:c,next:i,actionName:l}=e;return e.newState=await Promise.race([a(c,{actions:r(n.Actions[s],{modelName:s}),state:n.State[s]}),E(t,R(s,l))])||null,await i(o)},setNewState:d,stateUpdater:m,subscription:b,tryCatch:u,config:l},y=async(t,e)=>(e.next=t=>t.length>0?t[0](e,t.slice(1)):e.newState,await t[0](e,t.slice(1))),h=o({}),N=h.Consumer;if(!console.group){const t=[],e="-".repeat(80);console.group=function(o){t.push(o),console.log("%c \nBEGIN GROUP: %c",e,o),console.groupEnd=function(){console.log("END GROUP: %c\n%c",t.pop(),e)}}}const O=(t,e)=>{const o={};return Object.keys(t).forEach(a=>{o[a]=((t,e)=>async(o,a)=>{const n={Global:i,action:t,actionName:t.name,consumerActions:O,middlewareConfig:a,modelName:e.modelName,newState:null,params:o,type:"o"};return await y(w,n)})(t[a],e)}),o},A=(e,o)=>{if("function"==typeof o){let a=i.State[e];a=t(a,o),i.State=t(i.State,t=>{t[e]=a})}else i.State=t(i.State,t=>{t[e]={...t[e],...o}});return i.State},E=(t,e)=>new Promise(o=>setTimeout(()=>{console.log(t),o(e)},t)),v=async(e,o)=>{const a={__FROM_SERVER__:!0};return await Promise.all(Object.keys(i.State).map(async n=>{if(!e||!e.modelName||n===e.modelName||-1!==e.modelName.indexOf(n)){const s=i.AsyncState[n],r=s?await s(e):{};o&&o.isServer?a[n]=r:i.State=t(i.State,t=>{t[n]={...t[n],...r}})}})),o&&o.isServer?a:i.State},R=(t,e)=>{const o=localStorage.getItem(`__REACT_MODELX__${t}_${e}`);return o?JSON.parse(o):null},$=(t,e)=>{if(t===e)return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;const o=Object.keys(t),a=Object.keys(e);if(o.length!==a.length)return!1;for(let a=0;a<o.length;a++)if(!Object.prototype.hasOwnProperty.call(e,o[a])||t[o[a]]!==e[o[a]])return!1;return!0};function x(e){const o=i.currentStoreId,a=i.mutableState[o].count;return i.mutableState[o].count+=1,i.mutableState[o].hasOwnProperty(a)||(i.mutableState[o][a]="function"==typeof e?e():e),[i.mutableState[o][a],async e=>{i.mutableState[o][a]="function"==typeof e?t(i.mutableState[o][a],e):i.mutableState[o][a]&&e&&"Object"===i.mutableState[o][a].constructor.name&&"Object"===e.constructor.name?{...i.mutableState[o][a],...e}:e;const n={Global:i,action:()=>"function"==typeof e?i.mutableState[o][a]:e,actionName:"setter",consumerActions:O,disableSelectorUpdate:!0,middlewareConfig:{},modelName:o,newState:{},params:void 0,type:"u"};return await y(w,n)}]}function C(t,e){const o="string"==typeof t;i.storeId+=o?0:1;const a=o?t:i.storeId.toString();i.Actions[a]||(i.Actions[a]={}),i.mutableState[a]||(i.mutableState[a]={count:0});const n=()=>(i.mutableState[a].count=0,i.currentStoreId=a,e?e():t());return i.mutableState[a].selector=n,{useStore:()=>M(a,n),getState:()=>n()}}function j(e,o,a){if(void 0!==e.state){i.storeId+=1;const a="__"+i.storeId;i.State=t(i.State,t=>{t[a]=e.state}),e.middlewares&&(i.Middlewares[a]=e.middlewares),i.Actions[a]=e.actions,i.AsyncState[a]=e.asyncState,o&&(i.Context[a]=o);const n=D(a);return{__id:a,actions:n,getState:()=>I(a),subscribe:(t,e)=>G(a,t,e),unsubscribe:t=>T(a,t),useStore:t=>M(a,t)}}{if(e.actions){console.error("invalid model(s) schema: ",e);const t=t=>(...e)=>t;return{__ERROR__:!0,actions:t({}),getActions:t({}),getInitialState:t({}),getState:t({}),subscribe:t(),unsubscribe:t(),useStore:t([{},{}])}}o&&!o.__FROM_SERVER__&&(i.State=t(i.State,t=>{Object.assign(t,o||{})})),a&&(i.Context.__global=a),Object.keys(e).forEach(a=>{const n=e[a];if(n.__ERROR__)return console.error(a+" model's schema is invalid"),i.State=t(i.State,t=>{t[a]={}}),void(i.Actions[a]={});(t=>void 0!==t.useStore)(n)?(i.State[a]&&o||(i.State=t(i.State,t=>{t[a]=t[n.__id]})),o&&o.__FROM_SERVER__&&(i.State=t(i.State,t=>{t[a]={...t[n.__id],...o[a]}})),i.Actions[a]=i.Actions[n.__id],i.AsyncState[a]=i.AsyncState[n.__id],i.Middlewares[a]=i.Middlewares[n.__id],i.Context[a]=i.Context[n.__id]):(o&&o.__FROM_SERVER__?i.State=t(i.State,t=>{t[a]={...n.state,...o[a]}}):i.State[a]||(i.State=t(i.State,t=>{t[a]=n.state})),n.middlewares&&(i.Middlewares[a]=n.middlewares),i.Actions[a]=n.actions,i.AsyncState[a]=n.asyncState)});const n=Object.keys(e).reduce((t,e)=>({...t,[e]:D(e)}),{});return i.withDevTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__,i.withDevTools&&g.config.devtools.enable&&(i.devTools=window.__REDUX_DEVTOOLS_EXTENSION__,i.devTools.connect()),{actions:n,getActions:D,getInitialState:v,getState:I,subscribe:G,unsubscribe:T,useStore:M}}}e();const T=(t,e)=>{G(t,e,void 0)},G=(t,e,o)=>{Array.isArray(e)?e.forEach(e=>{i.subscriptions[`${t}_${e}`]||(i.subscriptions[`${t}_${e}`]=[]),o?i.subscriptions[`${t}_${e}`].push(o):i.subscriptions[`${t}_${e}`]=[]}):(i.subscriptions[`${t}_${e}`]||(i.subscriptions[`${t}_${e}`]=[]),o?i.subscriptions[`${t}_${e}`].push(o):i.subscriptions[`${t}_${e}`]=[])},I=t=>i.State[t],D=(t,e={type:"o"})=>{const o={};return Object.keys(i.Actions[t]).forEach(a=>o[a]=async(o,n)=>{const s={action:i.Actions[t][a],actionName:a,consumerActions:O,middlewareConfig:n,modelName:t,newState:null,params:o,...e,Global:i};return i.Middlewares[t]?await y(i.Middlewares[t],s):await y(w,s)}),o},M=(t,e)=>{const o=a({})[1],r=n(""),c=(l=[t],t=>l.reduce((t,e)=>t&&t[e]?t[e]:null,t))(i.mutableState);var l;const u=!!c,S=u?c.selector:e,d=u?c:I(t);if(s(()=>{i.uid+=1;const e=""+i.uid;return r.current=e,i.Setter.functionSetter[t]||(i.Setter.functionSetter[t]={}),i.Setter.functionSetter[t][e]={setState:o,selector:S},function(){delete i.Setter.functionSetter[t][e]}},[]),u)return S(d);{const e=D(t,{__hash:r.current,type:"f"});return[S?S(d):d,e]}};class k extends r{constructor(){super(...arguments),this.state=i.State}render(){const{children:t}=this.props;return i.Setter.classSetter=this.setState.bind(this),c(h.Provider,{value:{...this.state}},t)}}const P=(t,e,o)=>a=>class extends r{render(){const{state:n={},actions:s={}}=this.props;return c(N,null,r=>{const{[""+t]:l}=r,u=i.Actions[t];return c(a,Object.assign({},this.props,{state:{...n,...e?e(l):l},actions:{...s,...o?o(O(u,{modelName:t})):O(u,{modelName:t})}}))})}};export{N as Consumer,j as Model,k as Provider,w as actionMiddlewares,P as connect,C as createStore,v as getInitialState,I as getState,g as middlewares,x as useModel};
import t,{enableES5 as e}from"immer";import{createContext as o,useState as n,useRef as a,useLayoutEffect as s,PureComponent as r,createElement as c}from"react";var i={Actions:{},AsyncState:{},Context:{__global:{}},Middlewares:{},Setter:{classSetter:void 0,functionSetter:{}},State:{},devTools:void 0,subscriptions:{},mutableState:{},uid:0,storeId:0,currentStoreId:"0",withDevTools:!1};const l={logger:{enable:!1},devtools:{enable:!1},tryCatch:{enable:!0}},u=async(t,e)=>{const{next:o}=t;return l.tryCatch.enable?await o(e).catch(t=>console.log(t)):await o(e)},S=async(t,e)=>{const{action:o,modelName:n,consumerActions:a,params:s,next:r,Global:c,type:i}=t;return t.newState="u"===i?o():await o(s,{actions:a(c.Actions[n],{modelName:n}),state:c.State[n],...c.Context.__global||{},...c.Context[n]||{}})||null,await r(e)},d=async(t,e)=>{const{modelName:o,newState:n,next:a,Global:s,disableSelectorUpdate:r,type:c}=t;if(s.Setter.functionSetter[o]&&!r&&Object.keys(s.Setter.functionSetter[o]).map(t=>{const e=s.Setter.functionSetter[o][t];e&&e.selector&&!e.selectorRef&&(e.selectorRef=e.selector(s.State[o]))}),n||"u"===c)return A(o,n||{}),await a(e)},m=async(t,e)=>{const{modelName:o,next:n,Global:a,__hash:s}=t,r=a.Setter.functionSetter[o];return"f"===t.type&&s&&r&&r[s]&&r[s].setState&&r[s].setState(a.State[o]),await n(e)},b=async(t,e)=>{const{modelName:o,actionName:n,next:a,Global:s}=t,r="u"===t.type?s.subscriptions[o]:s.subscriptions[`${o}_${n}`];return r&&r.forEach(e=>{e(t)}),await a(e)},_=async(t,e)=>{const{Global:o}=t;if(!0===l.logger.enable||"function"==typeof l.logger.enable&&l.logger.enable(t)){console.group(`%c ${t.modelName} State Change %c ${(new Date).toLocaleTimeString()}`,"color: gray; font-weight: lighter;","color: black; font-weight: bold;"),console.log("%c Previous","color: #9E9E9E; font-weight: bold",o.State[t.modelName]),console.log("%c Action","color: #03A9F4; font-weight: bold",t.actionName,"payload: "+t.params);const n=await t.next(e);return console.log("%c Next","color: #4CAF50; font-weight: bold",o.State[t.modelName]),console.groupEnd(),n}return await t.next(e)},p=async(t,e)=>{const{Global:o}=t,n=await t.next(e);return o.withDevTools&&l.devtools.enable&&o.devTools.send(`${t.modelName}_${t.actionName}`,o.State),n},f=async(t,e)=>{const{modelName:o,next:n,Global:a,disableSelectorUpdate:s}=t;return a.Setter.classSetter&&a.Setter.classSetter(a.State),a.Setter.functionSetter[o]&&Object.keys(a.Setter.functionSetter[o]).map(t=>{const e=a.Setter.functionSetter[o][t];if(e)if(!e.selector||s)e.setState(a.State[o]);else{const t=e.selector(a.State[o]);x(t,e.selectorRef)||(e.selectorRef=t,e.setState(a.State[o]))}}),await n(e)},w=[u,_,p,S,d,m,f,b],g={communicator:f,consoleDebugger:_,devToolsListener:p,getNewState:S,getNewStateWithCache:(t=5e3)=>async(e,o)=>{const{action:n,Global:a,modelName:s,consumerActions:r,params:c,next:i,actionName:l}=e;return e.newState=await Promise.race([n(c,{actions:r(a.Actions[s],{modelName:s}),state:a.State[s]}),E(t,R(s,l))])||null,await i(o)},setNewState:d,stateUpdater:m,subscription:b,tryCatch:u,config:l},y=async(t,e)=>(e.next=t=>t.length>0?t[0](e,t.slice(1)):e.newState,await t[0](e,t.slice(1))),h=o({}),N=h.Consumer;if(!console.group){const t=[],e="-".repeat(80);console.group=function(o){t.push(o),console.log("%c \nBEGIN GROUP: %c",e,o),console.groupEnd=function(){console.log("END GROUP: %c\n%c",t.pop(),e)}}}const O=(t,e)=>{const o={};return Object.keys(t).forEach(n=>{o[n]=((t,e)=>async(o,n)=>{const a={Global:i,action:t,actionName:t.name,consumerActions:O,middlewareConfig:n,modelName:e.modelName,newState:null,params:o,type:"o"};return await y(w,a)})(t[n],e)}),o},A=(e,o)=>{if("function"==typeof o){let n=i.State[e];n=t(n,o),i.State=t(i.State,t=>{t[e]=n})}else i.State=t(i.State,t=>{t[e]={...t[e],...o}});return i.State},E=(t,e)=>new Promise(o=>setTimeout(()=>{console.log(t),o(e)},t)),v=async(e,o)=>{const n={__FROM_SERVER__:!0};return await Promise.all(Object.keys(i.State).map(async a=>{if(!e||!e.modelName||a===e.modelName||-1!==e.modelName.indexOf(a)){const s=i.AsyncState[a],r=s?await s(e):{};o&&o.isServer?n[a]=r:i.State=t(i.State,t=>{t[a]={...t[a],...r}})}})),o&&o.isServer?n:i.State},R=(t,e)=>{const o=localStorage.getItem(`__REACT_MODELX__${t}_${e}`);return o?JSON.parse(o):null},x=(t,e)=>{if(t===e)return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;const o=Object.keys(t),n=Object.keys(e);if(o.length!==n.length)return!1;for(let n=0;n<o.length;n++)if(!Object.prototype.hasOwnProperty.call(e,o[n])||t[o[n]]!==e[o[n]])return!1;return!0};function $(e){const o=i.currentStoreId,n=i.mutableState[o].count;return i.mutableState[o].count+=1,i.mutableState[o].hasOwnProperty(n)||(i.mutableState[o][n]="function"==typeof e?e():e),[i.mutableState[o][n],async e=>{i.mutableState[o][n]="function"==typeof e?t(i.mutableState[o][n],e):i.mutableState[o][n]&&e&&"Object"===i.mutableState[o][n].constructor.name&&"Object"===e.constructor.name?{...i.mutableState[o][n],...e}:e;const a={Global:i,action:()=>"function"==typeof e?i.mutableState[o][n]:e,actionName:"setter",consumerActions:O,disableSelectorUpdate:!0,middlewareConfig:{},modelName:o,newState:{},params:void 0,type:"u"};return await y(w,a)}]}function C(t,e){const o="string"==typeof t;i.storeId+=o?0:1;const n=o?t:i.storeId.toString();i.Actions[n]||(i.Actions[n]={}),i.mutableState[n]||(i.mutableState[n]={count:0});const a=()=>(i.mutableState[n].count=0,i.currentStoreId=n,e?e():t());return i.mutableState[n].selector=a,{useStore:()=>M(n,a),getState:()=>a(),subscribe:t=>{i.subscriptions[n]||(i.subscriptions[n]=[]),i.subscriptions[n].push(t)},unsubscribe:t=>{if(i.subscriptions[n]&&t){const e=i.subscriptions[n].indexOf(t);e>=0&&i.subscriptions[n].splice(e)}}}}function j(e,o,n){if(void 0!==e.state){i.storeId+=1;const n="__"+i.storeId;i.State=t(i.State,t=>{t[n]=e.state}),e.middlewares&&(i.Middlewares[n]=e.middlewares),i.Actions[n]=e.actions,i.AsyncState[n]=e.asyncState,o&&(i.Context[n]=o);const a=D(n);return{__id:n,actions:a,getState:()=>I(n),subscribe:(t,e)=>G(n,t,e),unsubscribe:t=>T(n,t),useStore:t=>M(n,t)}}{if(e.actions){console.error("invalid model(s) schema: ",e);const t=t=>(...e)=>t;return{__ERROR__:!0,actions:t({}),getActions:t({}),getInitialState:t({}),getState:t({}),subscribe:t(),unsubscribe:t(),useStore:t([{},{}])}}o&&!o.__FROM_SERVER__&&(i.State=t(i.State,t=>{Object.assign(t,o||{})})),n&&(i.Context.__global=n),Object.keys(e).forEach(n=>{const a=e[n];if(a.__ERROR__)return console.error(n+" model's schema is invalid"),i.State=t(i.State,t=>{t[n]={}}),void(i.Actions[n]={});(t=>void 0!==t.useStore)(a)?(i.State[n]&&o||(i.State=t(i.State,t=>{t[n]=t[a.__id]})),o&&o.__FROM_SERVER__&&(i.State=t(i.State,t=>{t[n]={...t[a.__id],...o[n]}})),i.Actions[n]=i.Actions[a.__id],i.AsyncState[n]=i.AsyncState[a.__id],i.Middlewares[n]=i.Middlewares[a.__id],i.Context[n]=i.Context[a.__id]):(o&&o.__FROM_SERVER__?i.State=t(i.State,t=>{t[n]={...a.state,...o[n]}}):i.State[n]||(i.State=t(i.State,t=>{t[n]=a.state})),a.middlewares&&(i.Middlewares[n]=a.middlewares),i.Actions[n]=a.actions,i.AsyncState[n]=a.asyncState)});const a=Object.keys(e).reduce((t,e)=>({...t,[e]:D(e)}),{});return i.withDevTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__,i.withDevTools&&g.config.devtools.enable&&(i.devTools=window.__REDUX_DEVTOOLS_EXTENSION__,i.devTools.connect()),{actions:a,getActions:D,getInitialState:v,getState:I,subscribe:G,unsubscribe:T,useStore:M}}}e();const T=(t,e)=>{G(t,e,void 0)},G=(t,e,o)=>{Array.isArray(e)?e.forEach(e=>{i.subscriptions[`${t}_${e}`]||(i.subscriptions[`${t}_${e}`]=[]),o?i.subscriptions[`${t}_${e}`].push(o):i.subscriptions[`${t}_${e}`]=[]}):(i.subscriptions[`${t}_${e}`]||(i.subscriptions[`${t}_${e}`]=[]),o?i.subscriptions[`${t}_${e}`].push(o):i.subscriptions[`${t}_${e}`]=[])},I=t=>i.State[t],D=(t,e={type:"o"})=>{const o={};return Object.keys(i.Actions[t]).forEach(n=>o[n]=async(o,a)=>{const s={action:i.Actions[t][n],actionName:n,consumerActions:O,middlewareConfig:a,modelName:t,newState:null,params:o,...e,Global:i};return i.Middlewares[t]?await y(i.Middlewares[t],s):await y(w,s)}),o},M=(t,e)=>{const o=n({})[1],r=a(""),c=(l=[t],t=>l.reduce((t,e)=>t&&t[e]?t[e]:null,t))(i.mutableState);var l;const u=!!c,S=u?c.selector:e,d=u?c:I(t);if(s(()=>{i.uid+=1;const e=""+i.uid;return r.current=e,i.Setter.functionSetter[t]||(i.Setter.functionSetter[t]={}),i.Setter.functionSetter[t][e]={setState:o,selector:S},function(){delete i.Setter.functionSetter[t][e]}},[]),u)return S(d);{const e=D(t,{__hash:r.current,type:"f"});return[S?S(d):d,e]}};class k extends r{constructor(){super(...arguments),this.state=i.State}render(){const{children:t}=this.props;return i.Setter.classSetter=this.setState.bind(this),c(h.Provider,{value:{...this.state}},t)}}const P=(t,e,o)=>n=>class extends r{render(){const{state:a={},actions:s={}}=this.props;return c(N,null,r=>{const{[""+t]:l}=r,u=i.Actions[t];return c(n,Object.assign({},this.props,{state:{...a,...e?e(l):l},actions:{...s,...o?o(O(u,{modelName:t})):O(u,{modelName:t})}}))})}};export{N as Consumer,j as Model,k as Provider,w as actionMiddlewares,P as connect,C as createStore,v as getInitialState,I as getState,g as middlewares,$ as useModel};

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("immer"),require("react")):"function"==typeof define&&define.amd?define(["exports","immer","react"],t):t((e=e||self).reactModel={},e.immer,e.react)}(this,function(e,t,r){var n="default"in t?t.default:t;function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function a(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var c={Actions:{},AsyncState:{},Context:{__global:{}},Middlewares:{},Setter:{classSetter:void 0,functionSetter:{}},State:{},devTools:void 0,subscriptions:{},mutableState:{},uid:0,storeId:0,currentStoreId:"0",withDevTools:!1},i={logger:{enable:!1},devtools:{enable:!1},tryCatch:{enable:!0}},s=function(e,t){try{var r=e.next;return Promise.resolve(i.tryCatch.enable?r(t).catch(function(e){return console.log(e)}):r(t))}catch(e){return Promise.reject(e)}},u=function(e,t){try{var r=function(){return Promise.resolve(s(t))},n=e.action,a=e.modelName,c=e.consumerActions,i=e.params,s=e.next,u=e.Global,l=e.type,f=function(){if("u"!==l)return Promise.resolve(n(i,o({actions:c(u.Actions[a],{modelName:a}),state:u.State[a]},u.Context.__global||{},u.Context[a]||{}))).then(function(t){e.newState=t||null});e.newState=n()}();return Promise.resolve(f&&f.then?f.then(r):r())}catch(e){return Promise.reject(e)}},l=function(e,t){try{var r=e.modelName,n=e.newState,o=e.next,a=e.Global,c=e.type;return a.Setter.functionSetter[r]&&!e.disableSelectorUpdate&&Object.keys(a.Setter.functionSetter[r]).map(function(e){var t=a.Setter.functionSetter[r][e];t&&t.selector&&!t.selectorRef&&(t.selectorRef=t.selector(a.State[r]))}),Promise.resolve(function(){if(n||"u"===c)return N(r,n||{}),Promise.resolve(o(t))}())}catch(e){return Promise.reject(e)}},f=function(e,t){try{var r=e.modelName,n=e.next,o=e.Global,a=e.__hash,c=o.Setter.functionSetter[r];return"f"===e.type&&a&&c&&c[a]&&c[a].setState&&c[a].setState(o.State[r]),Promise.resolve(n(t))}catch(e){return Promise.reject(e)}},m=function(e,t){try{var r=e.next,n=e.Global.subscriptions[e.modelName+"_"+e.actionName];return n&&n.forEach(function(t){t(e)}),Promise.resolve(r(t))}catch(e){return Promise.reject(e)}},S=function(e,t){try{var r=e.Global;return!0===i.logger.enable||"function"==typeof i.logger.enable&&i.logger.enable(e)?(console.group("%c "+e.modelName+" State Change %c "+(new Date).toLocaleTimeString(),"color: gray; font-weight: lighter;","color: black; font-weight: bold;"),console.log("%c Previous","color: #9E9E9E; font-weight: bold",r.State[e.modelName]),console.log("%c Action","color: #03A9F4; font-weight: bold",e.actionName,"payload: "+e.params),Promise.resolve(e.next(t)).then(function(t){return console.log("%c Next","color: #4CAF50; font-weight: bold",r.State[e.modelName]),console.groupEnd(),t})):Promise.resolve(e.next(t))}catch(e){return Promise.reject(e)}},d=function(e,t){try{var r=e.Global;return Promise.resolve(e.next(t)).then(function(t){return r.withDevTools&&i.devtools.enable&&r.devTools.send(e.modelName+"_"+e.actionName,r.State),t})}catch(e){return Promise.reject(e)}},v=function(e,t){try{var r=e.modelName,n=e.next,o=e.Global,a=e.disableSelectorUpdate;return o.Setter.classSetter&&o.Setter.classSetter(o.State),o.Setter.functionSetter[r]&&Object.keys(o.Setter.functionSetter[r]).map(function(e){var t=o.Setter.functionSetter[r][e];if(t)if(!t.selector||a)t.setState(o.State[r]);else{var n=t.selector(o.State[r]);A(n,t.selectorRef)||(t.selectorRef=n,t.setState(o.State[r]))}}),Promise.resolve(n(t))}catch(e){return Promise.reject(e)}},b=[s,S,d,u,l,f,v,m],p={communicator:v,consoleDebugger:S,devToolsListener:d,getNewState:u,getNewStateWithCache:function(e){return void 0===e&&(e=5e3),function(t,r){try{var n=t.Global,o=t.modelName,a=t.next,c=t.actionName;return Promise.resolve(Promise.race([(0,t.action)(t.params,{actions:(0,t.consumerActions)(n.Actions[o],{modelName:o}),state:n.State[o]}),E(e,j(o,c))])).then(function(e){return t.newState=e||null,Promise.resolve(a(r))})}catch(e){return Promise.reject(e)}}},setNewState:l,stateUpdater:f,subscription:m,tryCatch:s,config:i},_=function(e,t){try{return t.next=function(e){return e.length>0?e[0](t,e.slice(1)):t.newState},Promise.resolve(e[0](t,e.slice(1)))}catch(e){return Promise.reject(e)}},h=r.createContext({}),y=h.Consumer;if(!console.group){var g=[],P="-".repeat(80);console.group=function(e){g.push(e),console.log("%c \nBEGIN GROUP: %c",P,e),console.groupEnd=function(){console.log("END GROUP: %c\n%c",g.pop(),P)}}}var w=function(e,t){var r={};return Object.keys(e).forEach(function(n){r[n]=function(e,t){return function(r,n){try{return Promise.resolve(_(b,{Global:c,action:e,actionName:e.name,consumerActions:w,middlewareConfig:n,modelName:t.modelName,newState:null,params:r,type:"o"}))}catch(e){return Promise.reject(e)}}}(e[n],t)}),r},N=function(e,t){if("function"==typeof t){var r=c.State[e];r=n(r,t),c.State=n(c.State,function(t){t[e]=r})}else c.State=n(c.State,function(r){r[e]=o({},r[e],t)});return c.State},E=function(e,t){return new Promise(function(r){return setTimeout(function(){console.log(e),r(t)},e)})},O=function(e,t){try{var r={__FROM_SERVER__:!0};return Promise.resolve(Promise.all(Object.keys(c.State).map(function(a){try{var i=function(){if(!e||!e.modelName||a===e.modelName||-1!==e.modelName.indexOf(a)){var i=function(e){t&&t.isServer?r[a]=e:c.State=n(c.State,function(t){t[a]=o({},t[a],e)})},s=c.AsyncState[a];return s?Promise.resolve(s(e)).then(i):i({})}}();return Promise.resolve(i&&i.then?i.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}))).then(function(){return t&&t.isServer?r:c.State})}catch(e){return Promise.reject(e)}},j=function(e,t){var r=localStorage.getItem("__REACT_MODELX__"+e+"_"+t);return r?JSON.parse(r):null},A=function(e,t){if(e===t)return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;var r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(var o=0;o<r.length;o++)if(!Object.prototype.hasOwnProperty.call(t,r[o])||e[r[o]]!==t[r[o]])return!1;return!0};t.enableES5();var R=function(e,t){x(e,t,void 0)},x=function(e,t,r){Array.isArray(t)?t.forEach(function(t){c.subscriptions[e+"_"+t]||(c.subscriptions[e+"_"+t]=[]),r?c.subscriptions[e+"_"+t].push(r):c.subscriptions[e+"_"+t]=[]}):(c.subscriptions[e+"_"+t]||(c.subscriptions[e+"_"+t]=[]),r?c.subscriptions[e+"_"+t].push(r):c.subscriptions[e+"_"+t]=[])},C=function(e){return c.State[e]},M=function(e,t){void 0===t&&(t={type:"o"});var r={};return Object.keys(c.Actions[e]).forEach(function(n){return r[n]=function(r,a){try{var i=o({action:c.Actions[e][n],actionName:n,consumerActions:w,middlewareConfig:a,modelName:e,newState:null,params:r},t,{Global:c});return Promise.resolve(_(c.Middlewares[e]?c.Middlewares[e]:b,i))}catch(e){return Promise.reject(e)}}}),r},T=function(e,t){var n,o=r.useState({})[1],a=r.useRef(""),i=(n=[e],function(e){return n.reduce(function(e,t){return e&&e[t]?e[t]:null},e)})(c.mutableState),s=!!i,u=s?i.selector:t,l=s?i:C(e);if(r.useLayoutEffect(function(){c.uid+=1;var t=""+c.uid;return a.current=t,c.Setter.functionSetter[e]||(c.Setter.functionSetter[e]={}),c.Setter.functionSetter[e][t]={setState:o,selector:u},function(){delete c.Setter.functionSetter[e][t]}},[]),s)return u(l);var f=M(e,{__hash:a.current,type:"f"});return[u?u(l):l,f]},I=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).state=c.State,t}return a(t,e),t.prototype.render=function(){var e=this.props.children;return c.Setter.classSetter=this.setState.bind(this),r.createElement(h.Provider,{value:o({},this.state)},e)},t}(r.PureComponent);e.Consumer=y,e.Model=function(e,t,r){if(void 0!==e.state){c.storeId+=1;var a="__"+c.storeId;c.State=n(c.State,function(t){t[a]=e.state}),e.middlewares&&(c.Middlewares[a]=e.middlewares),c.Actions[a]=e.actions,c.AsyncState[a]=e.asyncState,t&&(c.Context[a]=t);var i=M(a);return{__id:a,actions:i,getState:function(){return C(a)},subscribe:function(e,t){return x(a,e,t)},unsubscribe:function(e){return R(a,e)},useStore:function(e){return T(a,e)}}}if(e.actions){console.error("invalid model(s) schema: ",e);var s=function(e){return function(){return e}};return{__ERROR__:!0,actions:s({}),getActions:s({}),getInitialState:s({}),getState:s({}),subscribe:s(),unsubscribe:s(),useStore:s([{},{}])}}t&&!t.__FROM_SERVER__&&(c.State=n(c.State,function(e){Object.assign(e,t||{})})),r&&(c.Context.__global=r),Object.keys(e).forEach(function(r){var a=e[r];if(a.__ERROR__)return console.error(r+" model's schema is invalid"),c.State=n(c.State,function(e){e[r]={}}),void(c.Actions[r]={});void 0===a.useStore?(t&&t.__FROM_SERVER__?c.State=n(c.State,function(e){e[r]=o({},a.state,t[r])}):c.State[r]||(c.State=n(c.State,function(e){e[r]=a.state})),a.middlewares&&(c.Middlewares[r]=a.middlewares),c.Actions[r]=a.actions,c.AsyncState[r]=a.asyncState):(c.State[r]&&t||(c.State=n(c.State,function(e){e[r]=e[a.__id]})),t&&t.__FROM_SERVER__&&(c.State=n(c.State,function(e){e[r]=o({},e[a.__id],t[r])})),c.Actions[r]=c.Actions[a.__id],c.AsyncState[r]=c.AsyncState[a.__id],c.Middlewares[r]=c.Middlewares[a.__id],c.Context[r]=c.Context[a.__id])});var u=Object.keys(e).reduce(function(e,t){var r;return o({},e,((r={})[t]=M(t),r))},{});return c.withDevTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__,c.withDevTools&&p.config.devtools.enable&&(c.devTools=window.__REDUX_DEVTOOLS_EXTENSION__,c.devTools.connect()),{actions:u,getActions:M,getInitialState:O,getState:C,subscribe:x,unsubscribe:R,useStore:T}},e.Provider=I,e.actionMiddlewares=b,e.connect=function(e,t,n){return function(i){return function(s){function u(){return s.apply(this,arguments)||this}return a(u,s),u.prototype.render=function(){var a=this,s=this.props,u=s.state,l=void 0===u?{}:u,f=s.actions,m=void 0===f?{}:f;return r.createElement(y,null,function(s){var u=s[""+e],f=c.Actions[e];return r.createElement(i,Object.assign({},a.props,{state:o({},l,t?t(u):u),actions:o({},m,n?n(w(f,{modelName:e})):w(f,{modelName:e}))}))})},u}(r.PureComponent)}},e.createStore=function(e,t){var r="string"==typeof e;c.storeId+=r?0:1;var n=r?e:c.storeId.toString();c.Actions[n]||(c.Actions[n]={}),c.mutableState[n]||(c.mutableState[n]={count:0});var o=function(){return c.mutableState[n].count=0,c.currentStoreId=n,t?t():e()};return c.mutableState[n].selector=o,{useStore:function(){return T(n,o)},getState:function(){return o()}}},e.getInitialState=O,e.getState=C,e.middlewares=p,e.useModel=function(e){var t=c.currentStoreId,r=c.mutableState[t].count;return c.mutableState[t].count+=1,c.mutableState[t].hasOwnProperty(r)||(c.mutableState[t][r]="function"==typeof e?e():e),[c.mutableState[t][r],function(e){try{return c.mutableState[t][r]="function"==typeof e?n(c.mutableState[t][r],e):c.mutableState[t][r]&&e&&"Object"===c.mutableState[t][r].constructor.name&&"Object"===e.constructor.name?o({},c.mutableState[t][r],e):e,Promise.resolve(_(b,{Global:c,action:function(){return"function"==typeof e?c.mutableState[t][r]:e},actionName:"setter",consumerActions:w,disableSelectorUpdate:!0,middlewareConfig:{},modelName:t,newState:{},params:void 0,type:"u"}))}catch(e){return Promise.reject(e)}}]}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("immer"),require("react")):"function"==typeof define&&define.amd?define(["exports","immer","react"],t):t((e=e||self).reactModel={},e.immer,e.react)}(this,function(e,t,n){var r="default"in t?t.default:t;function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function i(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var c={Actions:{},AsyncState:{},Context:{__global:{}},Middlewares:{},Setter:{classSetter:void 0,functionSetter:{}},State:{},devTools:void 0,subscriptions:{},mutableState:{},uid:0,storeId:0,currentStoreId:"0",withDevTools:!1},a={logger:{enable:!1},devtools:{enable:!1},tryCatch:{enable:!0}},s=function(e,t){try{var n=e.next;return Promise.resolve(a.tryCatch.enable?n(t).catch(function(e){return console.log(e)}):n(t))}catch(e){return Promise.reject(e)}},u=function(e,t){try{var n=function(){return Promise.resolve(s(t))},r=e.action,i=e.modelName,c=e.consumerActions,a=e.params,s=e.next,u=e.Global,l=e.type,f=function(){if("u"!==l)return Promise.resolve(r(a,o({actions:c(u.Actions[i],{modelName:i}),state:u.State[i]},u.Context.__global||{},u.Context[i]||{}))).then(function(t){e.newState=t||null});e.newState=r()}();return Promise.resolve(f&&f.then?f.then(n):n())}catch(e){return Promise.reject(e)}},l=function(e,t){try{var n=e.modelName,r=e.newState,o=e.next,i=e.Global,c=e.type;return i.Setter.functionSetter[n]&&!e.disableSelectorUpdate&&Object.keys(i.Setter.functionSetter[n]).map(function(e){var t=i.Setter.functionSetter[n][e];t&&t.selector&&!t.selectorRef&&(t.selectorRef=t.selector(i.State[n]))}),Promise.resolve(function(){if(r||"u"===c)return N(n,r||{}),Promise.resolve(o(t))}())}catch(e){return Promise.reject(e)}},f=function(e,t){try{var n=e.modelName,r=e.next,o=e.Global,i=e.__hash,c=o.Setter.functionSetter[n];return"f"===e.type&&i&&c&&c[i]&&c[i].setState&&c[i].setState(o.State[n]),Promise.resolve(r(t))}catch(e){return Promise.reject(e)}},m=function(e,t){try{var n=e.modelName,r=e.next,o=e.Global,i="u"===e.type?o.subscriptions[n]:o.subscriptions[n+"_"+e.actionName];return i&&i.forEach(function(t){t(e)}),Promise.resolve(r(t))}catch(e){return Promise.reject(e)}},S=function(e,t){try{var n=e.Global;return!0===a.logger.enable||"function"==typeof a.logger.enable&&a.logger.enable(e)?(console.group("%c "+e.modelName+" State Change %c "+(new Date).toLocaleTimeString(),"color: gray; font-weight: lighter;","color: black; font-weight: bold;"),console.log("%c Previous","color: #9E9E9E; font-weight: bold",n.State[e.modelName]),console.log("%c Action","color: #03A9F4; font-weight: bold",e.actionName,"payload: "+e.params),Promise.resolve(e.next(t)).then(function(t){return console.log("%c Next","color: #4CAF50; font-weight: bold",n.State[e.modelName]),console.groupEnd(),t})):Promise.resolve(e.next(t))}catch(e){return Promise.reject(e)}},d=function(e,t){try{var n=e.Global;return Promise.resolve(e.next(t)).then(function(t){return n.withDevTools&&a.devtools.enable&&n.devTools.send(e.modelName+"_"+e.actionName,n.State),t})}catch(e){return Promise.reject(e)}},b=function(e,t){try{var n=e.modelName,r=e.next,o=e.Global,i=e.disableSelectorUpdate;return o.Setter.classSetter&&o.Setter.classSetter(o.State),o.Setter.functionSetter[n]&&Object.keys(o.Setter.functionSetter[n]).map(function(e){var t=o.Setter.functionSetter[n][e];if(t)if(!t.selector||i)t.setState(o.State[n]);else{var r=t.selector(o.State[n]);A(r,t.selectorRef)||(t.selectorRef=r,t.setState(o.State[n]))}}),Promise.resolve(r(t))}catch(e){return Promise.reject(e)}},p=[s,S,d,u,l,f,b,m],v={communicator:b,consoleDebugger:S,devToolsListener:d,getNewState:u,getNewStateWithCache:function(e){return void 0===e&&(e=5e3),function(t,n){try{var r=t.Global,o=t.modelName,i=t.next,c=t.actionName;return Promise.resolve(Promise.race([(0,t.action)(t.params,{actions:(0,t.consumerActions)(r.Actions[o],{modelName:o}),state:r.State[o]}),O(e,j(o,c))])).then(function(e){return t.newState=e||null,Promise.resolve(i(n))})}catch(e){return Promise.reject(e)}}},setNewState:l,stateUpdater:f,subscription:m,tryCatch:s,config:a},_=function(e,t){try{return t.next=function(e){return e.length>0?e[0](t,e.slice(1)):t.newState},Promise.resolve(e[0](t,e.slice(1)))}catch(e){return Promise.reject(e)}},h=n.createContext({}),y=h.Consumer;if(!console.group){var g=[],P="-".repeat(80);console.group=function(e){g.push(e),console.log("%c \nBEGIN GROUP: %c",P,e),console.groupEnd=function(){console.log("END GROUP: %c\n%c",g.pop(),P)}}}var w=function(e,t){var n={};return Object.keys(e).forEach(function(r){n[r]=function(e,t){return function(n,r){try{return Promise.resolve(_(p,{Global:c,action:e,actionName:e.name,consumerActions:w,middlewareConfig:r,modelName:t.modelName,newState:null,params:n,type:"o"}))}catch(e){return Promise.reject(e)}}}(e[r],t)}),n},N=function(e,t){if("function"==typeof t){var n=c.State[e];n=r(n,t),c.State=r(c.State,function(t){t[e]=n})}else c.State=r(c.State,function(n){n[e]=o({},n[e],t)});return c.State},O=function(e,t){return new Promise(function(n){return setTimeout(function(){console.log(e),n(t)},e)})},E=function(e,t){try{var n={__FROM_SERVER__:!0};return Promise.resolve(Promise.all(Object.keys(c.State).map(function(i){try{var a=function(){if(!e||!e.modelName||i===e.modelName||-1!==e.modelName.indexOf(i)){var a=function(e){t&&t.isServer?n[i]=e:c.State=r(c.State,function(t){t[i]=o({},t[i],e)})},s=c.AsyncState[i];return s?Promise.resolve(s(e)).then(a):a({})}}();return Promise.resolve(a&&a.then?a.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}))).then(function(){return t&&t.isServer?n:c.State})}catch(e){return Promise.reject(e)}},j=function(e,t){var n=localStorage.getItem("__REACT_MODELX__"+e+"_"+t);return n?JSON.parse(n):null},A=function(e,t){if(e===t)return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;var n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(var o=0;o<n.length;o++)if(!Object.prototype.hasOwnProperty.call(t,n[o])||e[n[o]]!==t[n[o]])return!1;return!0};t.enableES5();var R=function(e,t){x(e,t,void 0)},x=function(e,t,n){Array.isArray(t)?t.forEach(function(t){c.subscriptions[e+"_"+t]||(c.subscriptions[e+"_"+t]=[]),n?c.subscriptions[e+"_"+t].push(n):c.subscriptions[e+"_"+t]=[]}):(c.subscriptions[e+"_"+t]||(c.subscriptions[e+"_"+t]=[]),n?c.subscriptions[e+"_"+t].push(n):c.subscriptions[e+"_"+t]=[])},C=function(e){return c.State[e]},M=function(e,t){void 0===t&&(t={type:"o"});var n={};return Object.keys(c.Actions[e]).forEach(function(r){return n[r]=function(n,i){try{var a=o({action:c.Actions[e][r],actionName:r,consumerActions:w,middlewareConfig:i,modelName:e,newState:null,params:n},t,{Global:c});return Promise.resolve(_(c.Middlewares[e]?c.Middlewares[e]:p,a))}catch(e){return Promise.reject(e)}}}),n},T=function(e,t){var r,o=n.useState({})[1],i=n.useRef(""),a=(r=[e],function(e){return r.reduce(function(e,t){return e&&e[t]?e[t]:null},e)})(c.mutableState),s=!!a,u=s?a.selector:t,l=s?a:C(e);if(n.useLayoutEffect(function(){c.uid+=1;var t=""+c.uid;return i.current=t,c.Setter.functionSetter[e]||(c.Setter.functionSetter[e]={}),c.Setter.functionSetter[e][t]={setState:o,selector:u},function(){delete c.Setter.functionSetter[e][t]}},[]),s)return u(l);var f=M(e,{__hash:i.current,type:"f"});return[u?u(l):l,f]},I=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).state=c.State,t}return i(t,e),t.prototype.render=function(){var e=this.props.children;return c.Setter.classSetter=this.setState.bind(this),n.createElement(h.Provider,{value:o({},this.state)},e)},t}(n.PureComponent);e.Consumer=y,e.Model=function(e,t,n){if(void 0!==e.state){c.storeId+=1;var i="__"+c.storeId;c.State=r(c.State,function(t){t[i]=e.state}),e.middlewares&&(c.Middlewares[i]=e.middlewares),c.Actions[i]=e.actions,c.AsyncState[i]=e.asyncState,t&&(c.Context[i]=t);var a=M(i);return{__id:i,actions:a,getState:function(){return C(i)},subscribe:function(e,t){return x(i,e,t)},unsubscribe:function(e){return R(i,e)},useStore:function(e){return T(i,e)}}}if(e.actions){console.error("invalid model(s) schema: ",e);var s=function(e){return function(){return e}};return{__ERROR__:!0,actions:s({}),getActions:s({}),getInitialState:s({}),getState:s({}),subscribe:s(),unsubscribe:s(),useStore:s([{},{}])}}t&&!t.__FROM_SERVER__&&(c.State=r(c.State,function(e){Object.assign(e,t||{})})),n&&(c.Context.__global=n),Object.keys(e).forEach(function(n){var i=e[n];if(i.__ERROR__)return console.error(n+" model's schema is invalid"),c.State=r(c.State,function(e){e[n]={}}),void(c.Actions[n]={});void 0===i.useStore?(t&&t.__FROM_SERVER__?c.State=r(c.State,function(e){e[n]=o({},i.state,t[n])}):c.State[n]||(c.State=r(c.State,function(e){e[n]=i.state})),i.middlewares&&(c.Middlewares[n]=i.middlewares),c.Actions[n]=i.actions,c.AsyncState[n]=i.asyncState):(c.State[n]&&t||(c.State=r(c.State,function(e){e[n]=e[i.__id]})),t&&t.__FROM_SERVER__&&(c.State=r(c.State,function(e){e[n]=o({},e[i.__id],t[n])})),c.Actions[n]=c.Actions[i.__id],c.AsyncState[n]=c.AsyncState[i.__id],c.Middlewares[n]=c.Middlewares[i.__id],c.Context[n]=c.Context[i.__id])});var u=Object.keys(e).reduce(function(e,t){var n;return o({},e,((n={})[t]=M(t),n))},{});return c.withDevTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__,c.withDevTools&&v.config.devtools.enable&&(c.devTools=window.__REDUX_DEVTOOLS_EXTENSION__,c.devTools.connect()),{actions:u,getActions:M,getInitialState:E,getState:C,subscribe:x,unsubscribe:R,useStore:T}},e.Provider=I,e.actionMiddlewares=p,e.connect=function(e,t,r){return function(a){return function(s){function u(){return s.apply(this,arguments)||this}return i(u,s),u.prototype.render=function(){var i=this,s=this.props,u=s.state,l=void 0===u?{}:u,f=s.actions,m=void 0===f?{}:f;return n.createElement(y,null,function(s){var u=s[""+e],f=c.Actions[e];return n.createElement(a,Object.assign({},i.props,{state:o({},l,t?t(u):u),actions:o({},m,r?r(w(f,{modelName:e})):w(f,{modelName:e}))}))})},u}(n.PureComponent)}},e.createStore=function(e,t){var n="string"==typeof e;c.storeId+=n?0:1;var r=n?e:c.storeId.toString();c.Actions[r]||(c.Actions[r]={}),c.mutableState[r]||(c.mutableState[r]={count:0});var o=function(){return c.mutableState[r].count=0,c.currentStoreId=r,t?t():e()};return c.mutableState[r].selector=o,{useStore:function(){return T(r,o)},getState:function(){return o()},subscribe:function(e){c.subscriptions[r]||(c.subscriptions[r]=[]),c.subscriptions[r].push(e)},unsubscribe:function(e){if(c.subscriptions[r]&&e){var t=c.subscriptions[r].indexOf(e);t>=0&&c.subscriptions[r].splice(t)}}}},e.getInitialState=E,e.getState=C,e.middlewares=v,e.useModel=function(e){var t=c.currentStoreId,n=c.mutableState[t].count;return c.mutableState[t].count+=1,c.mutableState[t].hasOwnProperty(n)||(c.mutableState[t][n]="function"==typeof e?e():e),[c.mutableState[t][n],function(e){try{return c.mutableState[t][n]="function"==typeof e?r(c.mutableState[t][n],e):c.mutableState[t][n]&&e&&"Object"===c.mutableState[t][n].constructor.name&&"Object"===e.constructor.name?o({},c.mutableState[t][n],e):e,Promise.resolve(_(p,{Global:c,action:function(){return"function"==typeof e?c.mutableState[t][n]:e},actionName:"setter",consumerActions:w,disableSelectorUpdate:!0,middlewareConfig:{},modelName:t,newState:{},params:void 0,type:"u"}))}catch(e){return Promise.reject(e)}}]}});
{
"name": "react-model",
"version": "4.1.2",
"version": "4.1.3",
"description": "The State management library for React",

@@ -5,0 +5,0 @@ "main": "./dist/react-model.js",

@@ -159,2 +159,4 @@ type Setter = {

getState: () => S
subscribe: (callback: () => void) => void
unsubscribe: (callback: () => void) => void
}

@@ -161,0 +163,0 @@

@@ -117,3 +117,6 @@ import { getCache, setPartialState, timeout, shallowEqual } from './helper'

const { modelName, actionName, next, Global } = context
const subscriptions = Global.subscriptions[`${modelName}_${actionName}`]
const subscriptions =
context.type === 'u'
? Global.subscriptions[modelName]
: Global.subscriptions[`${modelName}_${actionName}`]
if (subscriptions) {

@@ -120,0 +123,0 @@ subscriptions.forEach((callback) => {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc