UNPKG

simple-store-js

Version:

Simple State Management: isomorphic, slim, quick

1 lines 2.78 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["simple-store-js"]=e():t["simple-store-js"]=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=r(1),i=function(t){return t&&t.__esModule?t:{default:t}}(o),u=function(){return{_store:arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},_watchers:{},getStore:function(){return Object.assign({},this._store)},get:function(t){return n(this._store[t]),this._store[t]},set:function(t,e){var r=this._store[t];(0,i.default)(r,e)||(this._store[t]=e,this._watchers[t]&&this._watchers[t].forEach(function(t){(0,t[1])(e,r)}))},watch:function(t,e){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];this._watchers[t]||(this._watchers[t]=[]),this._watchers[t].push([r,e])},unwatch:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this._watchers[t]=!1!==e?this._watchers[t].filter(function(t){return t[0]!==e}):this._watchers[t]=[]}}};document&&(document.SimpleStore=u),e.default=u},function(t,e,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};t.exports=function t(e,r){if(e===r)return!0;var o,i=Array.isArray(e),u=Array.isArray(r);if(i&&u){if(e.length!=r.length)return!1;for(o=0;o<e.length;o++)if(!t(e[o],r[o]))return!1;return!0}if(i!=u)return!1;if(e&&r&&"object"===(void 0===e?"undefined":n(e))&&"object"===(void 0===r?"undefined":n(r))){var f=Object.keys(e);if(f.length!==Object.keys(r).length)return!1;var s=e instanceof Date,c=r instanceof Date;if(s&&c)return e.getTime()==r.getTime();if(s!=c)return!1;var a=e instanceof RegExp,l=r instanceof RegExp;if(a&&l)return e.toString()==r.toString();if(a!=l)return!1;for(o=0;o<f.length;o++)if(!Object.prototype.hasOwnProperty.call(r,f[o]))return!1;for(o=0;o<f.length;o++)if(!t(e[f[o]],r[f[o]]))return!1;return!0}return!1}}])});