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