stockroom
Version:
Offload your store management to a worker.
3 lines (2 loc) • 2.01 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("unistore")):"function"==typeof define&&define.amd?define(["unistore"],t):e.stockroom=t(e.unistore)}(this,function(e){function t(e,t){if(Array.isArray(e)){e=e.slice(0,t.length);for(var r=0;r<t.length;r++)void 0!==t[r]&&(e[r]=n(t[r],e[r]))}else{e=function(e,t){for(var n in t)e[n]=t[n];return e}({},e);for(var o in t)t.hasOwnProperty(o)&&(void 0===t[o]?delete e[o]:e[o]=n(t[o],e[o]))}return e}function n(e,n){return null!=n&&null!=e&&"object"==typeof n&&"object"==typeof e?t(n,e):e}function r(e,t){var n,r;if(Array.isArray(e))for(n=new Array(e.length),r=0;r<e.length;r++)e[r]!==t[r]&&(n[r]=o(e[r],t[r]));else{n={};for(r in e)e.hasOwnProperty(r)&&e[r]!==t[r]&&(n[r]=o(e[r],t[r]))}return n}function o(e,t){return"object"==typeof e&&"object"==typeof t?r(e,t):e}return e=e&&e.hasOwnProperty("default")?e.default:e,function(n){function o(e){1===l.push(e)&&setTimeout(i)}function i(){"function"==typeof postMessage&&postMessage(l),l.length=0}function f(e){if(p>0)return c.push(e);var n=e.type,r=e.id,i=e.overwrite,f=e.partial,s=e.update,l=e.action;if("@@STATE"===n)!0===f&&(s=t(a.getState(),s),i=!0),a.setState(s,!0===i,l);else if("@@ACTION"===n){var y=u[l.type];l.params?y.apply(u,l.params):y.call(u,l.payload),r&&o({type:"@@ACTIONCOMPLETE",id:r})}}var a=e(n),u=a.actions={},s={},p=0,c=[],l=[];for(var y in n)s[y]=n[y];return"function"==typeof addEventListener&&addEventListener("message",function(e){var t=e.data;if("object"!=typeof t);else if("pop"in t)if(1===t.length)f(t[0]);else for(var n=0;n<t.length;n++)f(t[n]);else f(t)}),a.subscribe(function(e,t){var n=r(e,s);s=e,o({type:"@@STATE",update:n,action:t,partial:!0})}),a.registerActions=function(e){"function"==typeof e&&(e=e(a));for(var t in e)u[t]=a.action(e[t])},a.freeze=function(){p++},a.unfreeze=function(){if(!--p){var e=c;c=[];for(var t=0;t<e.length;t++)f(e[t])}},o({type:"@@STATE",initial:!0,update:a.getState()}),a}});
//# sourceMappingURL=index.umd.js.map