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.54 kB
var t,e;t=this,e=(t,e,o)=>(()=>{"use strict";var r={266:e=>{e.exports=t},683:t=>{t.exports=e},959:t=>{t.exports=o}},a={};function n(t){var e=a[t];if(void 0!==e)return e.exports;var o=a[t]={exports:{}};return r[t](o,o.exports,n),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,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 function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function r(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(r=function(){return!!t})()}function a(t){return a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},a(t)}function c(t,e){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},c(t,e)}Object.defineProperty(t,"__esModule",{value:!0}),t.GlobalStore=void 0;var i=n(266),u=n(959),s=n(683),f=function(t){function e(t){var n,l,c,i,f,b=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,e),c=this,f=[t,b],i=a(i=e),(n=o(c,r()?Reflect.construct(i,f||[],a(c).constructor):i.apply(c,f))).localStorage=null,n.isLocalStorageAvailable=function(t){return Boolean((null==t?void 0:t.key)&&(null===globalThis||void 0===globalThis?void 0:globalThis.localStorage))},n._onInitialize=function(t){var e=t.setState,o=t.getState;if(n.isLocalStorageAvailable(n.localStorage)){var r=(0,u.getLocalStorageItem)(n.localStorage);if(null===r){var a=o();return(0,s.setLocalStorageItem)(a,n.localStorage)}e(r)}},n._onChange=function(t){var e=t.getState;n.isLocalStorageAvailable(n.localStorage)&&(0,s.setLocalStorageItem)(e(),n.localStorage)},n.onInitialize=null,n.onChange=null,n.onInit=function(t){var e;null===(e=n._onInitialize)||void 0===e||e.call(n,t)},n.onStateChanged=function(t){var e;null===(e=n._onChange)||void 0===e||e.call(n,t)},n.localStorage=null!==(l=b.localStorage)&&void 0!==l?l:null,n.constructor!==e?o(n):(n.initialize(),n)}return 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&&c(t,e)}(e,t),n=e,Object.defineProperty(n,"prototype",{writable:!1}),n;var n}(i.GlobalStoreAbstract);t.GlobalStore=f,t.default=f})(),l})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react-hooks-global-states/GlobalStoreAbstract"),require("./setLocalStorageItem.js"),require("./getLocalStorageItem.js")):"function"==typeof define&&define.amd?define(["react-hooks-global-states/GlobalStoreAbstract","./setLocalStorageItem.js","./getLocalStorageItem.js"],e):"object"==typeof exports?exports["react-global-state-hooks"]=e(require("react-hooks-global-states/GlobalStoreAbstract"),require("./setLocalStorageItem.js"),require("./getLocalStorageItem.js")):t["react-global-state-hooks"]=e(t["react-hooks-global-states/GlobalStoreAbstract"],t["./setLocalStorageItem.js"],t["./getLocalStorageItem.js"]);