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.0.0-rc.5 to 4.0.0-rc.6

2

dist/react-model.esm.js

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

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

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

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

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

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

@@ -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,n){function r(){return(r=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 o(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;var i={Actions:{},AsyncState:{},Context:{__global:{}},Middlewares:{},Setter:{classSetter:void 0,functionSetter:{}},State:{},devTools:void 0,subscriptions:{},uid:0,withDevTools:!1},c={logger:{enable:!1},devtools:{enable:!1},tryCatch:{enable:!0}},a=function(e,t){try{var n=e.next,r=c.tryCatch.enable?Promise.resolve(n(t).catch(function(e){return console.log(e)})).then(function(){}):Promise.resolve(n(t)).then(function(){});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},s=function(e,t){try{var n=e.modelName,o=e.next,i=e.Global;return Promise.resolve((0,e.action)(e.params,r({actions:(0,e.consumerActions)(i.Actions[n],{modelName:n}),state:i.State[n]},i.Context.__global||{},i.Context[n]||{}))).then(function(n){return e.newState=n||null,Promise.resolve(o(t)).then(function(){})})}catch(e){return Promise.reject(e)}},u=function(e,t){try{var n=e.modelName,r=e.newState,o=e.next,i=e.Global;i.Setter.functionSetter[n]&&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]))});var c=function(){if(r)return w(n,r),Promise.resolve(o(t)).then(function(){})}();return Promise.resolve(c&&c.then?c.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},l=function(e,t){try{var n=e.modelName,r=e.next,o=e.Global,i=e.__hash,c=o.Setter.functionSetter[n];return"function"===e.type&&i&&c&&c[i]&&c[i].setState&&c[i].setState(o.State[n]),Promise.resolve(r(t)).then(function(){})}catch(e){return Promise.reject(e)}},f=function(e,t){try{var n=e.next,r=e.Global.subscriptions[e.modelName+"_"+e.actionName];return r&&r.forEach(function(e){e()}),Promise.resolve(n(t)).then(function(){})}catch(e){return Promise.reject(e)}},m=function(e,t){try{var n=e.Global,r=!0===c.logger.enable||"function"==typeof c.logger.enable&&c.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(){console.log("%c Next","color: #4CAF50; font-weight: bold",n.State[e.modelName]),console.groupEnd()})):Promise.resolve(e.next(t)).then(function(){});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},d=function(e,t){try{var n=e.Global;return Promise.resolve(e.next(t)).then(function(){n.withDevTools&&c.devtools.enable&&n.devTools.send(e.modelName+"_"+e.actionName,n.State)})}catch(e){return Promise.reject(e)}},S=function(e,t){try{var n=e.modelName,r=e.next,o=e.Global;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){var r=t.selector(o.State[n]);j(r,t.selectorRef)||(t.selectorRef=r,t.setState(o.State[n]))}else t.setState(o.State[n])}),Promise.resolve(r(t)).then(function(){})}catch(e){return Promise.reject(e)}},v=[a,m,d,s,u,l,S,f],h={communicator:S,consoleDebugger:m,devToolsListener:d,getNewState:s,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]}),N(e,O(o,c))])).then(function(e){return t.newState=e||null,Promise.resolve(i(n)).then(function(){})})}catch(e){return Promise.reject(e)}}},setNewState:u,stateUpdater:l,subscription:f,tryCatch:a,config:c},_=function(e,t){try{t.next=function(e){return e.length>0&&e[0](t,e.slice(1))};var n=function(){if(e.length>0)return Promise.resolve(e[0](t,e.slice(1))).then(function(){})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},p=n.createContext({}),b=p.Consumer;if(!console.group){var y=[],g="-".repeat(80);console.group=function(e){y.push(e),console.log("%c \nBEGIN GROUP: %c",g,e),console.groupEnd=function(){console.log("END GROUP: %c\n%c",y.pop(),g)}}}var P=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(_(v,{Global:i,action:e,actionName:e.name,consumerActions:P,middlewareConfig:r,modelName:t.modelName,newState:null,params:n,type:"outer"})).then(function(){})}catch(e){return Promise.reject(e)}}}(e[r],t)}),n},w=function(e,n){if("function"==typeof n){var o=i.State[e];o=t(o,n),i.State=t(i.State,function(t){t[e]=o})}else i.State=t(i.State,function(t){t[e]=r({},t[e],n)});return i.State},N=function(e,t){return new Promise(function(n){return setTimeout(function(){console.log(e),n(t)},e)})},E=function(e,n){try{var o={__FROM_SERVER__:!0};return Promise.resolve(Promise.all(Object.keys(i.State).map(function(c){try{var a=function(){if(!e||!e.modelName||c===e.modelName||-1!==e.modelName.indexOf(c)){var a=function(e){n&&n.isServer?o[c]=e:i.State=t(i.State,function(t){t[c]=r({},t[c],e)})},s=i.AsyncState[c];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 n&&n.isServer?o:i.State})}catch(e){return Promise.reject(e)}},O=function(e,t){var n=localStorage.getItem("__REACT_MODELX__"+e+"_"+t);return n?JSON.parse(n):null},j=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},A=function(e,t){R(e,t,void 0)},R=function(e,t,n){Array.isArray(t)?t.forEach(function(t){i.subscriptions[e+"_"+t]||(i.subscriptions[e+"_"+t]=[]),n?i.subscriptions[e+"_"+t].push(n):i.subscriptions[e+"_"+t]=[]}):(i.subscriptions[e+"_"+t]||(i.subscriptions[e+"_"+t]=[]),n?i.subscriptions[e+"_"+t].push(n):i.subscriptions[e+"_"+t]=[])},x=function(e){return i.State[e]},C=function(e,t){void 0===t&&(t={type:"outer"});var n={};return Object.keys(i.Actions[e]).forEach(function(o){return n[o]=function(n,c){try{var a=r({action:i.Actions[e][o],actionName:o,consumerActions:P,middlewareConfig:c,modelName:e,newState:null,params:n},t,{Global:i}),s=i.Middlewares[e]?Promise.resolve(_(i.Middlewares[e],a)).then(function(){}):Promise.resolve(_(v,a)).then(function(){});return Promise.resolve(s&&s.then?s.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}}),n},T=function(e,t){var r=n.useState({})[1],o=n.useRef("");n.useEffect(function(){i.uid+=1;var n=""+i.uid;return o.current=n,i.Setter.functionSetter[e]||(i.Setter.functionSetter[e]={}),i.Setter.functionSetter[e][n]={setState:r,selector:t},function(){delete i.Setter.functionSetter[e][n]}},[]);var c=C(e,{__hash:o.current,type:"function"});return[t?t(x(e)):x(e),c]},M=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).state=i.State,t}return o(t,e),t.prototype.render=function(){var e=this.props.children;return i.Setter.classSetter=this.setState.bind(this),n.createElement(p.Provider,{value:r({},this.state)},e)},t}(n.PureComponent);e.Consumer=b,e.Model=function(e,n,o){if(void 0!==e.state){i.uid+=1;var c="__"+i.uid;i.State=t(i.State,function(t){t[c]=e.state}),e.middlewares&&(i.Middlewares[c]=e.middlewares),i.Actions[c]=e.actions,i.AsyncState[c]=e.asyncState,n&&(i.Context[c]=n);var a=C(c);return{__id:c,actions:a,getState:function(){return x(c)},subscribe:function(e,t){return R(c,e,t)},unsubscribe:function(e){return A(c,e)},useStore:function(e){return T(c,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([{},{}])}}n&&!n.__FROM_SERVER__&&(i.State=t(i.State,function(e){Object.assign(e,n||{})})),o&&(i.Context.__global=o),Object.keys(e).forEach(function(o){var c=e[o];if(c.__ERROR__)return console.error(o+" model's schema is invalid"),i.State=t(i.State,function(e){e[o]={}}),void(i.Actions[o]={});void 0===c.useStore?(n&&n.__FROM_SERVER__?i.State=t(i.State,function(e){e[o]=r({},c.state,n[o])}):i.State[o]||(i.State=t(i.State,function(e){e[o]=c.state})),c.middlewares&&(i.Middlewares[o]=c.middlewares),i.Actions[o]=c.actions,i.AsyncState[o]=c.asyncState):(i.State[o]&&n||(i.State=t(i.State,function(e){e[o]=e[c.__id]})),n&&n.__FROM_SERVER__&&(i.State=t(i.State,function(e){e[o]=r({},e[c.__id],n[o])})),i.Actions[o]=i.Actions[c.__id],i.AsyncState[o]=i.AsyncState[c.__id],i.Middlewares[o]=i.Middlewares[c.__id],i.Context[o]=i.Context[c.__id])});var u=Object.keys(e).reduce(function(e,t){var n;return r({},e,((n={})[t]=C(t),n))},{});return i.withDevTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__,i.withDevTools&&(i.devTools=window.__REDUX_DEVTOOLS_EXTENSION__,i.devTools.connect()),{actions:u,getActions:C,getInitialState:E,getState:x,subscribe:R,unsubscribe:A,useStore:T}},e.Provider=M,e.actionMiddlewares=v,e.connect=function(e,t,c){return function(a){return function(s){function u(){return s.apply(this,arguments)||this}return o(u,s),u.prototype.render=function(){var o=this,s=this.props,u=s.state,l=void 0===u?{}:u,f=s.actions,m=void 0===f?{}:f;return n.createElement(b,null,function(s){var u=s[""+e],f=i.Actions[e];return n.createElement(a,Object.assign({},o.props,{state:r({},l,t?t(u):u),actions:r({},m,c?c(P(f,{modelName:e})):P(f,{modelName:e}))}))})},u}(n.PureComponent)}},e.getInitialState=E,e.getState=x,e.middlewares=h});
!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:{},uid:0,withDevTools:!1},a={logger:{enable:!1},devtools:{enable:!1},tryCatch:{enable:!0}},s=function(e,t){try{var n=e.next,r=a.tryCatch.enable?Promise.resolve(n(t).catch(function(e){return console.log(e)})).then(function(){}):Promise.resolve(n(t)).then(function(){});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},u=function(e,t){try{var n=e.modelName,r=e.next,i=e.Global;return Promise.resolve((0,e.action)(e.params,o({actions:(0,e.consumerActions)(i.Actions[n],{modelName:n}),state:i.State[n]},i.Context.__global||{},i.Context[n]||{}))).then(function(n){return e.newState=n||null,Promise.resolve(r(t)).then(function(){})})}catch(e){return Promise.reject(e)}},l=function(e,t){try{var n=e.modelName,r=e.newState,o=e.next,i=e.Global;i.Setter.functionSetter[n]&&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]))});var c=function(){if(r)return E(n,r),Promise.resolve(o(t)).then(function(){})}();return Promise.resolve(c&&c.then?c.then(function(){}):void 0)}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"function"===e.type&&i&&c&&c[i]&&c[i].setState&&c[i].setState(o.State[n]),Promise.resolve(r(t)).then(function(){})}catch(e){return Promise.reject(e)}},m=function(e,t){try{var n=e.next,r=e.Global.subscriptions[e.modelName+"_"+e.actionName];return r&&r.forEach(function(e){e()}),Promise.resolve(n(t)).then(function(){})}catch(e){return Promise.reject(e)}},d=function(e,t){try{var n=e.Global,r=!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(){console.log("%c Next","color: #4CAF50; font-weight: bold",n.State[e.modelName]),console.groupEnd()})):Promise.resolve(e.next(t)).then(function(){});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},S=function(e,t){try{var n=e.Global;return Promise.resolve(e.next(t)).then(function(){n.withDevTools&&a.devtools.enable&&n.devTools.send(e.modelName+"_"+e.actionName,n.State)})}catch(e){return Promise.reject(e)}},v=function(e,t){try{var n=e.modelName,r=e.next,o=e.Global;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){var r=t.selector(o.State[n]);A(r,t.selectorRef)||(t.selectorRef=r,t.setState(o.State[n]))}else t.setState(o.State[n])}),Promise.resolve(r(t)).then(function(){})}catch(e){return Promise.reject(e)}},h=[s,d,S,u,l,f,v,m],_={communicator:v,consoleDebugger:d,devToolsListener:S,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]}),N(e,j(o,c))])).then(function(e){return t.newState=e||null,Promise.resolve(i(n)).then(function(){})})}catch(e){return Promise.reject(e)}}},setNewState:l,stateUpdater:f,subscription:m,tryCatch:s,config:a},p=function(e,t){try{t.next=function(e){return e.length>0&&e[0](t,e.slice(1))};var n=function(){if(e.length>0)return Promise.resolve(e[0](t,e.slice(1))).then(function(){})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},b=n.createContext({}),y=b.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(h,{Global:c,action:e,actionName:e.name,consumerActions:w,middlewareConfig:r,modelName:t.modelName,newState:null,params:n,type:"outer"})).then(function(){})}catch(e){return Promise.reject(e)}}}(e[r],t)}),n},E=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},N=function(e,t){return new Promise(function(n){return setTimeout(function(){console.log(e),n(t)},e)})},O=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]},T=function(e,t){void 0===t&&(t={type:"outer"});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}),s=c.Middlewares[e]?Promise.resolve(p(c.Middlewares[e],a)).then(function(){}):Promise.resolve(p(h,a)).then(function(){});return Promise.resolve(s&&s.then?s.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}}),n},M=function(e,t){var r=n.useState({})[1],o=n.useRef("");n.useEffect(function(){c.uid+=1;var n=""+c.uid;return o.current=n,c.Setter.functionSetter[e]||(c.Setter.functionSetter[e]={}),c.Setter.functionSetter[e][n]={setState:r,selector:t},function(){delete c.Setter.functionSetter[e][n]}},[]);var i=T(e,{__hash:o.current,type:"function"});return[t?t(C(e)):C(e),i]},G=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(b.Provider,{value:o({},this.state)},e)},t}(n.PureComponent);e.Consumer=y,e.Model=function(e,t,n){if(void 0!==e.state){c.uid+=1;var i="__"+c.uid;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=T(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 M(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]=T(t),n))},{});return c.withDevTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__,c.withDevTools&&(c.devTools=window.__REDUX_DEVTOOLS_EXTENSION__,c.devTools.connect()),{actions:u,getActions:T,getInitialState:O,getState:C,subscribe:x,unsubscribe:R,useStore:M}},e.Provider=G,e.actionMiddlewares=h,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.getInitialState=O,e.getState=C,e.middlewares=_});
{
"name": "react-model",
"version": "4.0.0-rc.5",
"version": "4.0.0-rc.6",
"description": "The State management library for React",
"main": "./dist/react-model.js",
"module": "./dist/react-model.esm.js",
"umd:main": "./dist/react-model.umd.js",

@@ -7,0 +8,0 @@ "types": "./src/index",

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