UNPKG

react-native-global-state-hooks

Version:

This is a package to easily handling global-state across your react-native-components No-redux... The library now includes @react-native-async-storage/async-storage to persist your state across sessions... if you want to keep using the old version without

1 lines 6.67 kB
var t,e;t=this,e=(t,e,n)=>(()=>{"use strict";var r={266:e=>{e.exports=t},512:t=>{t.exports=e},868:t=>{t.exports=n}},o={};function a(t){var e=o[t];if(void 0!==e)return e.exports;var n=o[t]={exports:{}};return r[t](n,n.exports,a),n.exports}var c={};return(()=>{var t=c;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 n(){var t,e,o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",c=o.toStringTag||"@@toStringTag";function i(n,o,a,c){var i=o&&o.prototype instanceof s?o:s,l=Object.create(i.prototype);return r(l,"_invoke",function(n,r,o){var a,c,i,s=0,l=o||[],f=!1,y={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return a=e,c=0,i=t,y.n=n,u}};function p(n,r){for(c=n,i=r,e=0;!f&&s&&!o&&e<l.length;e++){var o,a=l[e],p=y.p,b=a[2];n>3?(o=b===r)&&(i=a[(c=a[4])?5:(c=3,3)],a[4]=a[5]=t):a[0]<=p&&((o=n<2&&p<a[1])?(c=0,y.v=r,y.n=a[1]):p<b&&(o=n<3||a[0]>r||r>b)&&(a[4]=n,a[5]=r,y.n=b,c=0))}if(o||n>1)return u;throw f=!0,r}return function(o,l,b){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,b),c=l,i=b;(e=c<2?t:i)||!f;){a||(c?c<3?(c>1&&(y.n=-1),p(c,i)):y.n=i:y.v=i);try{if(s=2,a){if(c||(o="next"),e=a[o]){if(!(e=e.call(a,i)))throw TypeError("iterator result is not an object");if(!e.done)return e;i=e.value,c<2&&(c=0)}else 1===c&&(e=a.return)&&e.call(a),c<2&&(i=TypeError("The iterator does not provide a '"+o+"' method"),c=1);a=t}else if((e=(f=y.n<0)?i:n.call(r,y))!==u)break}catch(e){a=t,c=1,i=e}finally{s=1}}return{value:e,done:f}}}(n,a,c),!0),l}var u={};function s(){}function l(){}function f(){}e=Object.getPrototypeOf;var y=[][a]?e(e([][a]())):(r(e={},a,function(){return this}),e),p=f.prototype=s.prototype=Object.create(y);function b(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,f):(t.__proto__=f,r(t,c,"GeneratorFunction")),t.prototype=Object.create(p),t}return l.prototype=f,r(p,"constructor",f),r(f,"constructor",l),l.displayName="GeneratorFunction",r(f,c,"GeneratorFunction"),r(p),r(p,c,"Generator"),r(p,a,function(){return this}),r(p,"toString",function(){return"[object Generator]"}),(n=function(){return{w:i,m:b}})()}function r(t,e,n,o){var a=Object.defineProperty;try{a({},"",{})}catch(t){a=0}r=function(t,e,n,o){if(e)a?a(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n;else{var c=function(e,n){r(t,e,function(t){return this._invoke(e,n,t)})};c("next",0),c("throw",1),c("return",2)}},r(t,e,n,o)}function o(t,n){if(n&&("object"==e(n)||"function"==typeof n))return n;if(void 0!==n)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 i(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(i=function(){return!!t})()}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(t,e)}Object.defineProperty(t,"__esModule",{value:!0}),t.GlobalStore=void 0;var l=a(266),f=a(512),y=a(868),p=function(t){function e(t){var r,a,c,s,l,p=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,l=[t,p],s=u(s=e),(r=o(c,i()?Reflect.construct(s,l||[],u(c).constructor):s.apply(c,l))).asyncStorage=null,r.getMetadata=function(){var t,e;return(null===(t=r.asyncStorage)||void 0===t?void 0:t.key)?Object.assign({isAsyncStorageReady:!1,asyncStorageKey:r.asyncStorage.key},null!==(e=r.metadata)&&void 0!==e?e:{}):r.metadata},r._onInitialize=function(t){return o=r,a=[t],i=function(t){var r=this,o=t.setState,a=t.getState,c=t.setMetadata;return n().m(function t(){var i;return n().w(function(t){for(;;)switch(t.n){case 0:if(e.isAsyncStorageAvailable(r.asyncStorage)){t.n=1;break}return t.a(2);case 1:return c(function(t){return Object.assign(Object.assign({},null!=t?t:{}),{isAsyncStorageReady:!1})}),t.n=2,(0,f.getAsyncStorageItem)(r.asyncStorage);case 2:i=t.v,c(function(t){return Object.assign(Object.assign({},null!=t?t:{}),{isAsyncStorageReady:!0})}),null===i&&(i=a(),(0,y.setAsyncStorageItem)(i,r.asyncStorage)),o(i,{forceUpdate:!0});case 3:return t.a(2)}},t)})()},new((c=void 0)||(c=Promise))(function(t,e){function n(t){try{u(i.next(t))}catch(t){e(t)}}function r(t){try{u(i.throw(t))}catch(t){e(t)}}function u(e){var o;e.done?t(e.value):(o=e.value,o instanceof c?o:new c(function(t){t(o)})).then(n,r)}u((i=i.apply(o,a||[])).next())});var o,a,c,i},r._onChange=function(t){var n=t.getState;e.isAsyncStorageAvailable(r.asyncStorage)&&(0,y.setAsyncStorageItem)(n(),r.asyncStorage)},r.onInitialize=null,r.onChange=null,r.onInit=function(t){var e;null===(e=r._onInitialize)||void 0===e||e.call(r,t)},r.onStateChanged=function(t){var e;null===(e=r._onChange)||void 0===e||e.call(r,t)},r.asyncStorage=null!==(a=p.asyncStorage)&&void 0!==a?a:null,r.setMetadata(function(t){var e,n;return Object.assign(Object.assign({},null!=t?t:{}),{isAsyncStorageReady:!1,asyncStorageKey:null!==(n=null===(e=r.asyncStorage)||void 0===e?void 0:e.key)&&void 0!==n?n:null})}),r.constructor!==e?o(r):(r.initialize(),r)}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&&s(t,e)}(e,t),r=e,Object.defineProperty(r,"prototype",{writable:!1}),r;var r}(l.GlobalStoreAbstract);t.GlobalStore=p,p.isAsyncStorageAvailable=function(t){return Boolean(null==t?void 0:t.key)},t.default=p})(),c})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react-hooks-global-states/GlobalStoreAbstract"),require("./getAsyncStorageItem.js"),require("./setAsyncStorageItem.js")):"function"==typeof define&&define.amd?define(["react-hooks-global-states/GlobalStoreAbstract","./getAsyncStorageItem.js","./setAsyncStorageItem.js"],e):"object"==typeof exports?exports["react-native-global-state-hooks"]=e(require("react-hooks-global-states/GlobalStoreAbstract"),require("./getAsyncStorageItem.js"),require("./setAsyncStorageItem.js")):t["react-native-global-state-hooks"]=e(t["react-hooks-global-states/GlobalStoreAbstract"],t["./getAsyncStorageItem.js"],t["./setAsyncStorageItem.js"]);