UNPKG

react-global-state-hooks

Version:

This is a package to easily handling global-state across your react components No-redux, No-context.

1 lines 3.74 kB
var t,e;t=this,e=(t,e,o)=>(()=>{"use strict";var r={897:e=>{e.exports=t},182:t=>{t.exports=e},413:t=>{t.exports=o}},n={};function a(t){var e=n[t];if(void 0!==e)return e.exports;var o=n[t]={exports:{}};return r[t](o,o.exports,a),o.exports}var l={};return(()=>{var t=l;function e(t){return e="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},e(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function r(t,o){if(o&&("object"===e(o)||"function"==typeof o))return o;if(void 0!==o)throw new TypeError("Derived constructors may only return object or undefined");return n(t)}function n(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function c(t){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},c(t)}Object.defineProperty(t,"__esModule",{value:!0}),t.GlobalStore=void 0;var i=a(413),u=a(897),s=a(182),f=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&o(t,e)}(f,t);var e,a,l,i=(a=f,l=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,e=c(a);if(l){var o=c(this).constructor;t=Reflect.construct(e,arguments,o)}else t=e.apply(this,arguments);return r(this,t)});function f(t){var e,o,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{metadata:{}};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,f),(e=i.call(this,t,a)).localStorage=null,e.isLocalStorageAvailable=function(t){return Boolean((null==t?void 0:t.key)&&(null===globalThis||void 0===globalThis?void 0:globalThis.localStorage))},e._onInitialize=function(t){var o=t.setState,r=t.getState;if(e.isLocalStorageAvailable(e.localStorage)){var n=(0,u.getLocalStorageItem)(e.localStorage);if(null===n){var a=r();return(0,s.setLocalStorageItem)(a,e.localStorage)}o(n)}},e._onChange=function(t){var o=t.getState;e.isLocalStorageAvailable(e.localStorage)&&(0,s.setLocalStorageItem)(o(),e.localStorage)},e.onInitialize=null,e.onChange=null,e.onInit=function(t){var o;null===(o=e._onInitialize)||void 0===o||o.call(n(e),t)},e.onStateChanged=function(t){var o;null===(o=e._onChange)||void 0===o||o.call(n(e),t)},e.localStorage=null!==(o=a.localStorage)&&void 0!==o?o:null,e.constructor!==f?r(e):(e.initialize(),e)}return e=f,Object.defineProperty(e,"prototype",{writable:!1}),e}(i.GlobalStoreAbstract);t.GlobalStore=f,t.default=f})(),l})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./getLocalStorageItem.js"),require("./setLocalStorageItem.js"),require("react-hooks-global-states/GlobalStoreAbstract")):"function"==typeof define&&define.amd?define(["./getLocalStorageItem.js","./setLocalStorageItem.js","react-hooks-global-states/GlobalStoreAbstract"],e):"object"==typeof exports?exports["react-global-state-hooks"]=e(require("./getLocalStorageItem.js"),require("./setLocalStorageItem.js"),require("react-hooks-global-states/GlobalStoreAbstract")):t["react-global-state-hooks"]=e(t["./getLocalStorageItem.js"],t["./setLocalStorageItem.js"],t["react-hooks-global-states/GlobalStoreAbstract"]);