Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 3.1.3 to 3.1.4

2

dist/react-model.js

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

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

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

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

@@ -101,6 +101,5 @@ import produce from 'immer'

} else {
Global.State[modelName] = {
...Global.State[modelName],
...asyncState
}
Global.State = produce(Global.State, (s) => {
s[modelName] = { ...s[modelName], ...asyncState }
})
}

@@ -107,0 +106,0 @@ }

Sorry, the diff of this file is not supported yet

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