"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _utils=_interopRequireDefault(require("../utils/utils")),_data=require("./data");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,o)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach(function(t){_defineProperty(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperty(e,t,r){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"===_typeof(t)?t:String(t)}function _toPrimitive(e,t){if("object"!==_typeof(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,t||"default");if("object"!==_typeof(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var Store=_createClass(function e(){var t=this;_classCallCheck(this,e),_defineProperty(this,"_getByStr",function(e){if(!e)return t.state;var r=e.split(".");return r.reduce(function(e,t,o){return!e[t]&&o<r.length-1?{}:e[t]},t.state)}),_defineProperty(this,"get",function(e){if(_utils.default.isString(e))return t._getByStr(e);if(_utils.default.isObj(e)){var r=_objectSpread({},e);return Object.keys(r).forEach(function(e){var o=r[e];t.callbacks[e]||(t.callbacks[e]=[]),t.callbacks[e].indexOf(o)<0&&t.callbacks[e].push(o),o(t._getByStr(e))}),function(){Object.keys(r).forEach(function(e){var o=r[e],n=t.callbacks[e].indexOf(o);t.callbacks[e].splice(n,1)})}}}),_defineProperty(this,"_setByStr",function(e,r){try{var o=e.split(".");o.reduce(function(e,t,n){return n===o.length-1&&(e[t]=r),e[t]=void 0===e[t]?{}:e[t],e[t]},t.state)}catch(e){console.error("error",e)}}),_defineProperty(this,"_setItem",function(e,r){try{if(r!==t._getByStr(e)){var o=_utils.default.deepCopy(t._getByStr(e));t._setByStr(e,r),(t.callbacks[e]||[]).forEach(function(r){r(t._getByStr(e),o)})}}catch(e){console.error("error",e)}}),_defineProperty(this,"set",function(e,r){if(_utils.default.isString(e)&&t._setItem(e,r),_utils.default.isObj(e)){var o=_objectSpread({},e);Object.keys(o).forEach(function(e){var r=o[e];t._setItem(e,r)})}}),_defineProperty(this,"reset",function(){t.state={}}),this.state=_objectSpread({},(0,_data.initDefaultData)()),this.callbacks={}}),_default=Store;exports.default=_default;