UNPKG

stockroom

Version:

Offload your store management to a worker.

3 lines (2 loc) 2.01 kB
!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 for(var o in e=function(e,t){for(var n in t)e[n]=t[n];return e}({},e),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 for(r in n={},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){var o=e(n),i=o.actions={},f={},a=0,u=[],s=[];for(var p in n)f[p]=n[p];function c(e){1===s.push(e)&&setTimeout(l)}function l(){"function"==typeof postMessage&&postMessage(s),s.length=0}function y(e){if(a>0)return u.push(e);var n=e.type,r=e.id,f=e.overwrite,s=e.update,p=e.action;if("@@STATE"===n)!0===e.partial&&(s=t(o.getState(),s),f=!0),o.setState(s,!0===f,p);else if("@@ACTION"===n){var l=i[p.type];p.params?l.apply(i,p.params):l.call(i,p.payload),r&&c({type:"@@ACTIONCOMPLETE",id:r})}}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)y(t[0]);else for(var n=0;n<t.length;n++)y(t[n]);else y(t)}),o.subscribe(function(e,t){var n=r(e,f);f=e,c({type:"@@STATE",update:n,action:t&&t.name,partial:!0})}),o.registerActions=function(e){for(var t in"function"==typeof e&&(e=e(o)),e)i[t]=o.action(e[t])},o.freeze=function(){a++},o.unfreeze=function(){if(!--a){var e=u;u=[];for(var t=0;t<e.length;t++)y(e[t])}},c({type:"@@STATE",initial:!0,update:o.getState()}),o}}); //# sourceMappingURL=index.umd.js.map