react-native-global-state-hooks 15.0.3 → 16.0.4-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GlobalStore.cjs +5 -0
- package/GlobalStore.d.ts +3 -3
- package/GlobalStore.js +5 -1
- package/GlobalStore.mjs +5 -0
- package/actions.cjs +1 -0
- package/actions.d.ts +1 -0
- package/actions.js +1 -0
- package/actions.mjs +1 -0
- package/asyncStorageWrapper.cjs +4 -0
- package/asyncStorageWrapper.js +4 -1
- package/asyncStorageWrapper.mjs +4 -0
- package/bundle.cjs +1 -0
- package/bundle.js +1 -1
- package/bundle.mjs +1 -0
- package/createContext.cjs +1 -0
- package/createContext.js +1 -1
- package/createContext.mjs +1 -0
- package/createGlobalState.cjs +1 -0
- package/createGlobalState.d.ts +8 -8
- package/createGlobalState.js +1 -1
- package/createGlobalState.mjs +1 -0
- package/debug.cjs +1 -0
- package/debug.d.ts +2 -0
- package/debug.js +1 -0
- package/debug.mjs +1 -0
- package/index.d.ts +11 -10
- package/isPromise.cjs +1 -0
- package/isPromise.js +1 -0
- package/isPromise.mjs +1 -0
- package/isRecord.cjs +1 -0
- package/isRecord.js +1 -1
- package/isRecord.mjs +1 -0
- package/package.json +53 -91
- package/shallowCompare.cjs +1 -0
- package/shallowCompare.js +1 -1
- package/shallowCompare.mjs +1 -0
- package/throwWrongKeyOnActionCollectionConfig.cjs +1 -0
- package/throwWrongKeyOnActionCollectionConfig.js +1 -1
- package/throwWrongKeyOnActionCollectionConfig.mjs +1 -0
- package/tryCatch.cjs +1 -0
- package/tryCatch.js +1 -0
- package/tryCatch.mjs +1 -0
- package/types.cjs +1 -0
- package/types.d.ts +15 -4
- package/types.js +1 -1
- package/types.mjs +0 -0
- package/uniqueId.cjs +1 -0
- package/uniqueId.d.ts +1 -1
- package/uniqueId.js +1 -1
- package/uniqueId.mjs +1 -0
- package/webpack.config.js +0 -132
package/GlobalStore.cjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";var k=Object.create;var d=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var I=(r,o)=>{for(var t in o)d(r,t,{get:o[t],enumerable:!0})},m=(r,o,t,e)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of b(o))!w.call(r,a)&&a!==t&&d(r,a,{get:()=>o[a],enumerable:!(e=E(o,a))||e.enumerable});return r};var S=(r,o,t)=>(t=r!=null?k(M(r)):{},m(o||!r||!r.__esModule?d(t,"default",{value:r,enumerable:!0}):t,r)),P=r=>m(d({},"__esModule",{value:!0}),r);var V={};I(V,{GlobalStore:()=>u,default:()=>F});module.exports=P(V);var v=S(require("react-hooks-global-states/GlobalStore")),c=S(require("./tryCatch.cjs")),y=S(require("json-storage-formatter/isNil")),A=S(require("json-storage-formatter/formatFromStore")),C=S(require("json-storage-formatter/formatToStore")),h=S(require("./asyncStorageWrapper.cjs")),p=-1,u=class r extends v.default{constructor(t,e={metadata:{}}){var n,s,i;super(t,e);this.asyncStorage=null;this.getMetadata=()=>this.metadata;this.isPersistStorageAvailable=()=>{var t;return!!((t=this.asyncStorage)!=null&&t.key)};this.trySetStorageItem=async t=>{let e=this.asyncStorage;if(!e)return;let{error:a}=await(0,c.default)(()=>{var s;let n=(s=e.adapter)==null?void 0:s.setItem;return n?n(e.key,t):this.setStorageItem(t)});a&&this.handleStorageError(a)};this.updateStateWithValidation=async t=>{let e=this.asyncStorage;if(!e)return;let{result:a,error:n}=(0,c.default)(()=>{var s;return(s=e.validator)==null?void 0:s.call(e,{restored:t,initial:this.getState()})});if(n){this.handleStorageError(n),await this.trySetStorageItem(this.getState());return}if(a===void 0){if(t===void 0){await this.trySetStorageItem(this.getState());return}this.setState(t,{forceUpdate:!0}),await this.trySetStorageItem(t);return}this.setState(a,{forceUpdate:!0}),await this.trySetStorageItem(a)};this.onInit=async()=>{let t=this.asyncStorage;if(!t||!this.isPersistStorageAvailable())return;this.metadata.isAsyncStorageReady=!1;let e=t.versioning,{result:a,error:n}=await(0,c.default)(async()=>{var l,g;let i=(l=t.adapter)==null?void 0:l.getItem;return i?{s:await i(t.key),v:(g=e==null?void 0:e.version)!=null?g:p}:this.getStorageItem()}),{error:s}=await(0,c.default)(async()=>{if(n){this.handleStorageError(n),await this.updateStateWithValidation(this.getState());return}if(!a){await this.updateStateWithValidation(this.getState());return}let i=a.v===(e==null?void 0:e.version),l=e==null?void 0:e.migrator;if(i||!l||t.adapter){await this.updateStateWithValidation(a.s);return}let{result:g,error:f}=(0,c.default)(()=>l({legacy:a.s,initial:this.getState()}));if(!f){await this.updateStateWithValidation(g);return}this.handleStorageError(f),await this.updateStateWithValidation(this.getState())});this.metadata.isAsyncStorageReady=!0,s&&this.handleStorageError(s)};this.onStateChanged=async t=>{let e=this.asyncStorage;if(!e||!this.isPersistStorageAvailable())return;let{error:a}=await(0,c.default)(()=>{var s;let n=(s=e.adapter)==null?void 0:s.setItem;return n?n(e.key,t.state):this.setStorageItem(t.state)});a&&this.handleStorageError(a)};this.getStorageItem=async()=>{let t=this.asyncStorage.key,e=await h.default.getItem(t),a=(0,y.default)(e)?null:(0,A.default)(e);return x(t,a),a};this.setStorageItem=async t=>{var n,s,i;let e={s:t,v:(i=(s=(n=this.asyncStorage)==null?void 0:n.versioning)==null?void 0:s.version)!=null?i:p},a=(0,C.default)(e);return h.default.setItem(this.asyncStorage.key,a)};this.handleStorageError=t=>{var e,a;if((e=this.asyncStorage)!=null&&e.onError)return this.asyncStorage.onError(t);console.error([`[react-native-global-state-hooks]
|
|
2
|
+
`," asyncStorage sync error:","[hook]:",` ${this._name}`,"[AsyncStorage Key]:",` ${(a=this.asyncStorage)==null?void 0:a.key}`,"[Error]:",` ${t!=null?t:"undefined"}
|
|
3
|
+
|
|
4
|
+
`,"Stacktrace:"].join(`
|
|
5
|
+
`),t.stack)};this.asyncStorage=(n=e.asyncStorage)!=null?n:null,Object.assign(this.getMetadata(),{isAsyncStorageReady:!1,asyncStorageKey:(i=(s=this.asyncStorage)==null?void 0:s.key)!=null?i:null}),this.constructor===r&&this.initialize()}};function x(r,o){if(!(0,y.default)(o)&&!(typeof o=="object"&&"s"in o&&"v"in o))throw new Error(`[react-native-global-state-hooks] The value of the key "${r}" is not a valid storage envelope.`)}var F=u;
|
package/GlobalStore.d.ts
CHANGED
|
@@ -6,9 +6,9 @@ import GlobalStoreBase from "react-hooks-global-states/GlobalStore";
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class GlobalStore<State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata> | undefined | unknown, PublicStateMutator = keyof ActionsConfig extends never | undefined ? React.Dispatch<React.SetStateAction<State>> : ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>> extends GlobalStoreBase<State, AsyncMetadata<Metadata>, ActionsConfig> {
|
|
8
8
|
asyncStorage: AsyncStorageConfig<State> | null;
|
|
9
|
-
constructor(state: State);
|
|
10
|
-
constructor(state: State, args: {
|
|
11
|
-
metadata?: Metadata;
|
|
9
|
+
constructor(state: State | (() => State));
|
|
10
|
+
constructor(state: State | (() => State), args: {
|
|
11
|
+
metadata?: Metadata | (() => Metadata);
|
|
12
12
|
callbacks?: GlobalStoreCallbacks<State, PublicStateMutator extends AnyFunction ? null : PublicStateMutator, Metadata>;
|
|
13
13
|
actions?: ActionsConfig;
|
|
14
14
|
name?: string;
|
package/GlobalStore.js
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
var t,e;t=this,e=(t,e,r,o,n)=>(()=>{"use strict";var a={313(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){return Boolean(t&&"function"==typeof t.then)}},70(t,e,r){Object.defineProperty(e,"__esModule",{value:!0});var o,n=(o=r(313))&&o.__esModule?o:{default:o};e.default=function(t,e){try{var r=t();return(0,n.default)(r)?r.then(function(t){return{result:t,error:null}}).catch(function(t){return{result:null!=e?e:null,error:t}}):{result:r,error:null}}catch(t){return{result:null!=e?e:null,error:t}}}},114(e){e.exports=t},330(t){t.exports=e},413(t){t.exports=r},773(t){t.exports=o},536(t){t.exports=n}};const i={};function u(t){const e=i[t];if(void 0!==e)return e.exports;const r=i[t]={exports:{}};return a[t](r,r.exports,u),r.exports}let s={};return(()=>{let t=s;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 r(){var t,e,n="function"==typeof Symbol?Symbol:{},a=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function u(r,n,a,i){var u=n&&n.prototype instanceof c?n:c,f=Object.create(u.prototype);return o(f,"_invoke",function(r,o,n){var a,i,u,c=0,f=n||[],l=!1,d={p:0,n:0,v:t,a:v,f:v.bind(t,4),d:function(e,r){return a=e,i=0,u=t,d.n=r,s}};function v(r,o){for(i=r,u=o,e=0;!l&&c&&!n&&e<f.length;e++){var n,a=f[e],v=d.p,h=a[2];r>3?(n=h===o)&&(u=a[(i=a[4])?5:(i=3,3)],a[4]=a[5]=t):a[0]<=v&&((n=r<2&&v<a[1])?(i=0,d.v=o,d.n=a[1]):v<h&&(n=r<3||a[0]>o||o>h)&&(a[4]=r,a[5]=o,d.n=h,i=0))}if(n||r>1)return s;throw l=!0,o}return function(n,f,h){if(c>1)throw TypeError("Generator is already running");for(l&&1===f&&v(f,h),i=f,u=h;(e=i<2?t:u)||!l;){a||(i?i<3?(i>1&&(d.n=-1),v(i,u)):d.n=u:d.v=u);try{if(c=2,a){if(i||(n="next"),e=a[n]){if(!(e=e.call(a,u)))throw TypeError("iterator result is not an object");if(!e.done)return e;u=e.value,i<2&&(i=0)}else 1===i&&(e=a.return)&&e.call(a),i<2&&(u=TypeError("The iterator does not provide a '"+n+"' method"),i=1);a=t}else if((e=(l=d.n<0)?u:r.call(o,d))!==s)break}catch(e){a=t,i=1,u=e}finally{c=1}}return{value:e,done:l}}}(r,a,i),!0),f}var s={};function c(){}function f(){}function l(){}e=Object.getPrototypeOf;var d=[][a]?e(e([][a]())):(o(e={},a,function(){return this}),e),v=l.prototype=c.prototype=Object.create(d);function h(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,o(t,i,"GeneratorFunction")),t.prototype=Object.create(v),t}return f.prototype=l,o(v,"constructor",l),o(l,"constructor",f),f.displayName="GeneratorFunction",o(l,i,"GeneratorFunction"),o(v),o(v,i,"Generator"),o(v,a,function(){return this}),o(v,"toString",function(){return"[object Generator]"}),(r=function(){return{w:u,m:h}})()}function o(t,e,r,n){var a=Object.defineProperty;try{a({},"",{})}catch(t){a=0}o=function(t,e,r,n){function i(e,r){o(t,e,function(t){return this._invoke(e,r,t)})}e?a?a(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},o(t,e,r,n)}function n(t,r){if(r&&("object"==e(r)||"function"==typeof r))return r;if(void 0!==r)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 a(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(a=function(){return!!t})()}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}function c(t,e){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},c(t,e)}var f=function(t,e,r,o){return new(r||(r=Promise))(function(n,a){function i(t){try{s(o.next(t))}catch(t){a(t)}}function u(t){try{s(o.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(i,u)}s((o=o.apply(t,e||[])).next())})},l=function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(t,"__esModule",{value:!0}),t.GlobalStore=void 0;var d=l(u(536)),v=l(u(70)),h=l(u(773)),y=l(u(330)),p=l(u(413)),g=l(u(114)),S=function(t){function e(t){var o,u,s,c,l,d,S,m=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),l=this,S=[t,m],d=i(d=e),(o=n(l,a()?Reflect.construct(d,S||[],i(l).constructor):d.apply(l,S))).asyncStorage=null,o.getMetadata=function(){return o.metadata},o.isPersistStorageAvailable=function(){var t;return Boolean(null===(t=o.asyncStorage)||void 0===t?void 0:t.key)},o.trySetStorageItem=function(t){return f(o,void 0,void 0,r().m(function e(){var o,n,a,i=this;return r().w(function(e){for(;;)switch(e.n){case 0:if(o=this.asyncStorage){e.n=1;break}return e.a(2);case 1:return e.n=2,(0,v.default)(function(){var e,r=null===(e=o.adapter)||void 0===e?void 0:e.setItem;return r?r(o.key,t):i.setStorageItem(t)});case 2:if(n=e.v,a=n.error){e.n=3;break}return e.a(2);case 3:this.handleStorageError(a);case 4:return e.a(2)}},e,this)}))},o.updateStateWithValidation=function(t){return f(o,void 0,void 0,r().m(function e(){var o,n,a,i,u=this;return r().w(function(e){for(;;)switch(e.n){case 0:if(o=this.asyncStorage){e.n=1;break}return e.a(2);case 1:if(n=(0,v.default)(function(){var e;return null===(e=o.validator)||void 0===e?void 0:e.call(o,{restored:t,initial:u.getState()})}),a=n.result,!(i=n.error)){e.n=3;break}return this.handleStorageError(i),e.n=2,this.trySetStorageItem(this.getState());case 2:case 4:case 6:case 8:return e.a(2);case 3:if(void 0!==a){e.n=7;break}if(void 0!==t){e.n=5;break}return e.n=4,this.trySetStorageItem(this.getState());case 5:return this.setState(t,{forceUpdate:!0}),e.n=6,this.trySetStorageItem(t);case 7:return this.setState(a,{forceUpdate:!0}),e.n=8,this.trySetStorageItem(a)}},e,this)}))},o.onInit=function(){return f(o,void 0,void 0,r().m(function t(){var e,o,n,a,i,u,s,c=this;return r().w(function(t){for(;;)switch(t.n){case 0:if((e=this.asyncStorage)&&this.isPersistStorageAvailable()){t.n=1;break}return t.a(2);case 1:return this.metadata.isAsyncStorageReady=!1,o=e.versioning,t.n=2,(0,v.default)(function(){return f(c,void 0,void 0,r().m(function t(){var n,a,i,u,s;return r().w(function(t){for(;;)switch(t.n){case 0:if(i=null===(n=e.adapter)||void 0===n?void 0:n.getItem){t.n=1;break}return t.a(2,this.getStorageItem());case 1:return t.n=2,i(e.key);case 2:return u=t.v,s=null!==(a=null==o?void 0:o.version)&&void 0!==a?a:-1,t.a(2,{s:u,v:s})}},t,this)}))});case 2:return n=t.v,a=n.result,i=n.error,t.n=3,(0,v.default)(function(){return f(c,void 0,void 0,r().m(function t(){var n,u,s,c,f,l=this;return r().w(function(t){for(;;)switch(t.n){case 0:if(!i){t.n=2;break}return this.handleStorageError(i),t.n=1,this.updateStateWithValidation(this.getState());case 1:case 3:case 5:case 7:case 9:return t.a(2);case 2:if(a){t.n=4;break}return t.n=3,this.updateStateWithValidation(this.getState());case 4:if(n=a.v===(null==o?void 0:o.version),u=null==o?void 0:o.migrator,!n&&u&&!e.adapter){t.n=6;break}return t.n=5,this.updateStateWithValidation(a.s);case 6:if(s=(0,v.default)(function(){return u({legacy:a.s,initial:l.getState()})}),c=s.result,f=s.error){t.n=8;break}return t.n=7,this.updateStateWithValidation(c);case 8:return this.handleStorageError(f),t.n=9,this.updateStateWithValidation(this.getState())}},t,this)}))});case 3:if(u=t.v,s=u.error,this.metadata.isAsyncStorageReady=!0,s){t.n=4;break}return t.a(2);case 4:this.handleStorageError(s);case 5:return t.a(2)}},t,this)}))},o.onStateChanged=function(t){return f(o,void 0,void 0,r().m(function e(){var o,n,a,i=this;return r().w(function(e){for(;;)switch(e.n){case 0:if((o=this.asyncStorage)&&this.isPersistStorageAvailable()){e.n=1;break}return e.a(2);case 1:return e.n=2,(0,v.default)(function(){var e,r=null===(e=o.adapter)||void 0===e?void 0:e.setItem;return r?r(o.key,t.state):i.setStorageItem(t.state)});case 2:if(n=e.v,a=n.error){e.n=3;break}return e.a(2);case 3:this.handleStorageError(a);case 4:return e.a(2)}},e,this)}))},o.getStorageItem=function(){return f(o,void 0,void 0,r().m(function t(){var e,o;return r().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,g.default.getItem(this.asyncStorage.key);case 1:return e=t.v,o=(0,h.default)(e)?null:(0,y.default)(e),b(this.asyncStorage.key,o),t.a(2,o)}},t,this)}))},o.setStorageItem=function(t){return f(o,void 0,void 0,r().m(function e(){var o,n,a,i,u;return r().w(function(e){for(;;)if(0===e.n)return i={s:t,v:null!==(a=null===(n=null===(o=this.asyncStorage)||void 0===o?void 0:o.versioning)||void 0===n?void 0:n.version)&&void 0!==a?a:-1},u=(0,p.default)(i),e.a(2,g.default.setItem(this.asyncStorage.key,u))},e,this)}))},o.handleStorageError=function(t){var e;if(null===(e=o.asyncStorage)||void 0===e?void 0:e.onError)return o.asyncStorage.onError(t)},o.asyncStorage=null!==(u=m.asyncStorage)&&void 0!==u?u:null,Object.assign(o.getMetadata(),{isAsyncStorageReady:!1,asyncStorageKey:null!==(c=null===(s=o.asyncStorage)||void 0===s?void 0:s.key)&&void 0!==c?c:null}),o.constructor!==e?n(o):(o.initialize(),o)}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),o=e,Object.defineProperty(o,"prototype",{writable:!1}),o;var o}(d.default);function b(t,r){if(!((0,h.default)(r)||"object"===e(r)&&"s"in r&&"v"in r))throw new Error('[react-native-global-state-hooks] The value of the key "'.concat(t,'" is not a valid storage envelope.'))}t.GlobalStore=S,t.default=S})(),s})(),"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./asyncStorageWrapper.js"),require("json-storage-formatter/formatFromStore"),require("json-storage-formatter/formatToStore"),require("json-storage-formatter/isNil"),require("react-hooks-global-states/GlobalStore")):"function"==typeof define&&define.amd?define(["./asyncStorageWrapper.js","json-storage-formatter/formatFromStore","json-storage-formatter/formatToStore","json-storage-formatter/isNil","react-hooks-global-states/GlobalStore"],e):"object"==typeof exports?exports["react-native-global-state-hooks"]=e(require("./asyncStorageWrapper.js"),require("json-storage-formatter/formatFromStore"),require("json-storage-formatter/formatToStore"),require("json-storage-formatter/isNil"),require("react-hooks-global-states/GlobalStore")):t["react-native-global-state-hooks"]=e(t["./asyncStorageWrapper.js"],t["json-storage-formatter/formatFromStore"],t["json-storage-formatter/formatToStore"],t["json-storage-formatter/isNil"],t["react-hooks-global-states/GlobalStore"]);
|
|
1
|
+
"use strict";var k=Object.create;var d=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var I=(r,o)=>{for(var t in o)d(r,t,{get:o[t],enumerable:!0})},m=(r,o,t,e)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of b(o))!w.call(r,a)&&a!==t&&d(r,a,{get:()=>o[a],enumerable:!(e=E(o,a))||e.enumerable});return r};var S=(r,o,t)=>(t=r!=null?k(M(r)):{},m(o||!r||!r.__esModule?d(t,"default",{value:r,enumerable:!0}):t,r)),P=r=>m(d({},"__esModule",{value:!0}),r);var V={};I(V,{GlobalStore:()=>u,default:()=>F});module.exports=P(V);var v=S(require("react-hooks-global-states/GlobalStore")),c=S(require("./tryCatch.js")),y=S(require("json-storage-formatter/isNil")),A=S(require("json-storage-formatter/formatFromStore")),C=S(require("json-storage-formatter/formatToStore")),h=S(require("./asyncStorageWrapper.js")),p=-1,u=class r extends v.default{constructor(t,e={metadata:{}}){var n,s,i;super(t,e);this.asyncStorage=null;this.getMetadata=()=>this.metadata;this.isPersistStorageAvailable=()=>{var t;return!!((t=this.asyncStorage)!=null&&t.key)};this.trySetStorageItem=async t=>{let e=this.asyncStorage;if(!e)return;let{error:a}=await(0,c.default)(()=>{var s;let n=(s=e.adapter)==null?void 0:s.setItem;return n?n(e.key,t):this.setStorageItem(t)});a&&this.handleStorageError(a)};this.updateStateWithValidation=async t=>{let e=this.asyncStorage;if(!e)return;let{result:a,error:n}=(0,c.default)(()=>{var s;return(s=e.validator)==null?void 0:s.call(e,{restored:t,initial:this.getState()})});if(n){this.handleStorageError(n),await this.trySetStorageItem(this.getState());return}if(a===void 0){if(t===void 0){await this.trySetStorageItem(this.getState());return}this.setState(t,{forceUpdate:!0}),await this.trySetStorageItem(t);return}this.setState(a,{forceUpdate:!0}),await this.trySetStorageItem(a)};this.onInit=async()=>{let t=this.asyncStorage;if(!t||!this.isPersistStorageAvailable())return;this.metadata.isAsyncStorageReady=!1;let e=t.versioning,{result:a,error:n}=await(0,c.default)(async()=>{var l,g;let i=(l=t.adapter)==null?void 0:l.getItem;return i?{s:await i(t.key),v:(g=e==null?void 0:e.version)!=null?g:p}:this.getStorageItem()}),{error:s}=await(0,c.default)(async()=>{if(n){this.handleStorageError(n),await this.updateStateWithValidation(this.getState());return}if(!a){await this.updateStateWithValidation(this.getState());return}let i=a.v===(e==null?void 0:e.version),l=e==null?void 0:e.migrator;if(i||!l||t.adapter){await this.updateStateWithValidation(a.s);return}let{result:g,error:f}=(0,c.default)(()=>l({legacy:a.s,initial:this.getState()}));if(!f){await this.updateStateWithValidation(g);return}this.handleStorageError(f),await this.updateStateWithValidation(this.getState())});this.metadata.isAsyncStorageReady=!0,s&&this.handleStorageError(s)};this.onStateChanged=async t=>{let e=this.asyncStorage;if(!e||!this.isPersistStorageAvailable())return;let{error:a}=await(0,c.default)(()=>{var s;let n=(s=e.adapter)==null?void 0:s.setItem;return n?n(e.key,t.state):this.setStorageItem(t.state)});a&&this.handleStorageError(a)};this.getStorageItem=async()=>{let t=this.asyncStorage.key,e=await h.default.getItem(t),a=(0,y.default)(e)?null:(0,A.default)(e);return x(t,a),a};this.setStorageItem=async t=>{var n,s,i;let e={s:t,v:(i=(s=(n=this.asyncStorage)==null?void 0:n.versioning)==null?void 0:s.version)!=null?i:p},a=(0,C.default)(e);return h.default.setItem(this.asyncStorage.key,a)};this.handleStorageError=t=>{var e,a;if((e=this.asyncStorage)!=null&&e.onError)return this.asyncStorage.onError(t);console.error([`[react-native-global-state-hooks]
|
|
2
|
+
`," asyncStorage sync error:","[hook]:",` ${this._name}`,"[AsyncStorage Key]:",` ${(a=this.asyncStorage)==null?void 0:a.key}`,"[Error]:",` ${t!=null?t:"undefined"}
|
|
3
|
+
|
|
4
|
+
`,"Stacktrace:"].join(`
|
|
5
|
+
`),t.stack)};this.asyncStorage=(n=e.asyncStorage)!=null?n:null,Object.assign(this.getMetadata(),{isAsyncStorageReady:!1,asyncStorageKey:(i=(s=this.asyncStorage)==null?void 0:s.key)!=null?i:null}),this.constructor===r&&this.initialize()}};function x(r,o){if(!(0,y.default)(o)&&!(typeof o=="object"&&"s"in o&&"v"in o))throw new Error(`[react-native-global-state-hooks] The value of the key "${r}" is not a valid storage envelope.`)}var F=u;
|
package/GlobalStore.mjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import f from"react-hooks-global-states/GlobalStore";import s from"./tryCatch.mjs";import y from"json-storage-formatter/isNil";import m from"json-storage-formatter/formatFromStore";import p from"json-storage-formatter/formatToStore";import u from"./asyncStorageWrapper.mjs";var h=-1,g=class l extends f{constructor(e,t={metadata:{}}){var r,o,n;super(e,t);this.asyncStorage=null;this.getMetadata=()=>this.metadata;this.isPersistStorageAvailable=()=>{var e;return!!((e=this.asyncStorage)!=null&&e.key)};this.trySetStorageItem=async e=>{let t=this.asyncStorage;if(!t)return;let{error:a}=await s(()=>{var o;let r=(o=t.adapter)==null?void 0:o.setItem;return r?r(t.key,e):this.setStorageItem(e)});a&&this.handleStorageError(a)};this.updateStateWithValidation=async e=>{let t=this.asyncStorage;if(!t)return;let{result:a,error:r}=s(()=>{var o;return(o=t.validator)==null?void 0:o.call(t,{restored:e,initial:this.getState()})});if(r){this.handleStorageError(r),await this.trySetStorageItem(this.getState());return}if(a===void 0){if(e===void 0){await this.trySetStorageItem(this.getState());return}this.setState(e,{forceUpdate:!0}),await this.trySetStorageItem(e);return}this.setState(a,{forceUpdate:!0}),await this.trySetStorageItem(a)};this.onInit=async()=>{let e=this.asyncStorage;if(!e||!this.isPersistStorageAvailable())return;this.metadata.isAsyncStorageReady=!1;let t=e.versioning,{result:a,error:r}=await s(async()=>{var c,S;let n=(c=e.adapter)==null?void 0:c.getItem;return n?{s:await n(e.key),v:(S=t==null?void 0:t.version)!=null?S:h}:this.getStorageItem()}),{error:o}=await s(async()=>{if(r){this.handleStorageError(r),await this.updateStateWithValidation(this.getState());return}if(!a){await this.updateStateWithValidation(this.getState());return}let n=a.v===(t==null?void 0:t.version),c=t==null?void 0:t.migrator;if(n||!c||e.adapter){await this.updateStateWithValidation(a.s);return}let{result:S,error:d}=s(()=>c({legacy:a.s,initial:this.getState()}));if(!d){await this.updateStateWithValidation(S);return}this.handleStorageError(d),await this.updateStateWithValidation(this.getState())});this.metadata.isAsyncStorageReady=!0,o&&this.handleStorageError(o)};this.onStateChanged=async e=>{let t=this.asyncStorage;if(!t||!this.isPersistStorageAvailable())return;let{error:a}=await s(()=>{var o;let r=(o=t.adapter)==null?void 0:o.setItem;return r?r(t.key,e.state):this.setStorageItem(e.state)});a&&this.handleStorageError(a)};this.getStorageItem=async()=>{let e=this.asyncStorage.key,t=await u.getItem(e),a=y(t)?null:m(t);return v(e,a),a};this.setStorageItem=async e=>{var r,o,n;let t={s:e,v:(n=(o=(r=this.asyncStorage)==null?void 0:r.versioning)==null?void 0:o.version)!=null?n:h},a=p(t);return u.setItem(this.asyncStorage.key,a)};this.handleStorageError=e=>{var t,a;if((t=this.asyncStorage)!=null&&t.onError)return this.asyncStorage.onError(e);console.error([`[react-native-global-state-hooks]
|
|
2
|
+
`," asyncStorage sync error:","[hook]:",` ${this._name}`,"[AsyncStorage Key]:",` ${(a=this.asyncStorage)==null?void 0:a.key}`,"[Error]:",` ${e!=null?e:"undefined"}
|
|
3
|
+
|
|
4
|
+
`,"Stacktrace:"].join(`
|
|
5
|
+
`),e.stack)};this.asyncStorage=(r=t.asyncStorage)!=null?r:null,Object.assign(this.getMetadata(),{isAsyncStorageReady:!1,asyncStorageKey:(n=(o=this.asyncStorage)==null?void 0:o.key)!=null?n:null}),this.constructor===l&&this.initialize()}};function v(l,i){if(!y(i)&&!(typeof i=="object"&&"s"in i&&"v"in i))throw new Error(`[react-native-global-state-hooks] The value of the key "${l}" is not a valid storage envelope.`)}var w=g;export{g as GlobalStore,w as default};
|
package/actions.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var i=Object.create;var f=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var n=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var s=(o,t)=>{for(var a in t)f(o,a,{get:t[a],enumerable:!0})},d=(o,t,a,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of m(t))!p.call(o,e)&&e!==a&&f(o,e,{get:()=>t[e],enumerable:!(c=l(t,e))||c.enumerable});return o};var u=(o,t,a)=>(a=o!=null?i(n(o)):{},d(t||!o||!o.__esModule?f(a,"default",{value:o,enumerable:!0}):a,o)),x=o=>d(f({},"__esModule",{value:!0}),o);var b={};s(b,{actions:()=>r.actions,default:()=>r.default});module.exports=x(b);var r=u(require("react-hooks-global-states/actions"));
|
package/actions.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { actions, default } from "react-hooks-global-states/actions";
|
package/actions.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var i=Object.create;var f=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var n=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var s=(o,t)=>{for(var a in t)f(o,a,{get:t[a],enumerable:!0})},d=(o,t,a,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of m(t))!p.call(o,e)&&e!==a&&f(o,e,{get:()=>t[e],enumerable:!(c=l(t,e))||c.enumerable});return o};var u=(o,t,a)=>(a=o!=null?i(n(o)):{},d(t||!o||!o.__esModule?f(a,"default",{value:o,enumerable:!0}):a,o)),x=o=>d(f({},"__esModule",{value:!0}),o);var b={};s(b,{actions:()=>r.actions,default:()=>r.default});module.exports=x(b);var r=u(require("react-hooks-global-states/actions"));
|
package/actions.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{actions as a,default as e}from"react-hooks-global-states/actions";export{a as actions,e as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";var y=Object.create;var g=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var S=(e,a)=>{for(var t in a)g(e,t,{get:a[t],enumerable:!0})},d=(e,a,t,o)=>{if(a&&typeof a=="object"||typeof a=="function")for(let s of u(a))!M.call(e,s)&&s!==t&&g(e,s,{get:()=>a[s],enumerable:!(o=m(a,s))||o.enumerable});return e};var w=(e,a,t)=>(t=e!=null?y(p(e)):{},d(a||!e||!e.__esModule?g(t,"default",{value:e,enumerable:!0}):t,e)),A=e=>d(g({},"__esModule",{value:!0}),e);var v={};S(v,{default:()=>f});module.exports=A(v);var h=(()=>{let e="pending",a=null,t=null;(async()=>{try{let r=import("@react-native-async-storage/async-storage");a=r;let{default:n}=await r,{getItem:c,setItem:l}=n;c.bind(n),l.bind(n),t={getItem:c,setItem:l},e="resolved"}catch(r){process.env.NODE_ENV==="development"&&console.warn(r),e="rejected"}finally{a=null}})();let o=()=>{throw new Error(`[AsyncStorageManager Not Found]
|
|
2
|
+
|
|
3
|
+
Please install the react-native-async-storage/async-storage to be use as the default async storage manager or
|
|
4
|
+
add an AsyncStorageManager using the asyncStorageWrapper.addAsyncStorageManager method before attempting to get or set items.`)},s=async r=>{try{e==="pending"&&a&&await a.catch(()=>{}),e="pending";let n=r();a=n,t=await n,e="resolved"}catch(n){throw a=null,e="rejected",n}},i=async()=>(e==="pending"&&a&&await a,e==="rejected"&&a&&await a.catch(r=>{throw r}),t||o());return{getItem:async r=>(await i()).getItem(r),setItem:async(r,n)=>(await i()).setItem(r,n),addAsyncStorageManager:s}})(),f=h;
|
package/asyncStorageWrapper.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";var y=Object.create;var g=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var S=(e,a)=>{for(var t in a)g(e,t,{get:a[t],enumerable:!0})},d=(e,a,t,o)=>{if(a&&typeof a=="object"||typeof a=="function")for(let s of u(a))!M.call(e,s)&&s!==t&&g(e,s,{get:()=>a[s],enumerable:!(o=m(a,s))||o.enumerable});return e};var w=(e,a,t)=>(t=e!=null?y(p(e)):{},d(a||!e||!e.__esModule?g(t,"default",{value:e,enumerable:!0}):t,e)),A=e=>d(g({},"__esModule",{value:!0}),e);var v={};S(v,{default:()=>f});module.exports=A(v);var h=(()=>{let e="pending",a=null,t=null;(async()=>{try{let r=import("@react-native-async-storage/async-storage");a=r;let{default:n}=await r,{getItem:c,setItem:l}=n;c.bind(n),l.bind(n),t={getItem:c,setItem:l},e="resolved"}catch(r){process.env.NODE_ENV==="development"&&console.warn(r),e="rejected"}finally{a=null}})();let o=()=>{throw new Error(`[AsyncStorageManager Not Found]
|
|
2
|
+
|
|
3
|
+
Please install the react-native-async-storage/async-storage to be use as the default async storage manager or
|
|
4
|
+
add an AsyncStorageManager using the asyncStorageWrapper.addAsyncStorageManager method before attempting to get or set items.`)},s=async r=>{try{e==="pending"&&a&&await a.catch(()=>{}),e="pending";let n=r();a=n,t=await n,e="resolved"}catch(n){throw a=null,e="rejected",n}},i=async()=>(e==="pending"&&a&&await a,e==="rejected"&&a&&await a.catch(r=>{throw r}),t||o());return{getItem:async r=>(await i()).getItem(r),setItem:async(r,n)=>(await i()).setItem(r,n),addAsyncStorageManager:s}})(),f=h;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var l=(()=>{let r="pending",t=null,n=null;(async()=>{try{let e=import("@react-native-async-storage/async-storage");t=e;let{default:a}=await e,{getItem:s,setItem:g}=a;s.bind(a),g.bind(a),n={getItem:s,setItem:g},r="resolved"}catch(e){process.env.NODE_ENV==="development"&&console.warn(e),r="rejected"}finally{t=null}})();let c=()=>{throw new Error(`[AsyncStorageManager Not Found]
|
|
2
|
+
|
|
3
|
+
Please install the react-native-async-storage/async-storage to be use as the default async storage manager or
|
|
4
|
+
add an AsyncStorageManager using the asyncStorageWrapper.addAsyncStorageManager method before attempting to get or set items.`)},i=async e=>{try{r==="pending"&&t&&await t.catch(()=>{}),r="pending";let a=e();t=a,n=await a,r="resolved"}catch(a){throw t=null,r="rejected",a}},o=async()=>(r==="pending"&&t&&await t,r==="rejected"&&t&&await t.catch(e=>{throw e}),n||c());return{getItem:async e=>(await o()).getItem(e),setItem:async(e,a)=>(await o()).setItem(e,a),addAsyncStorageManager:i}})(),m=l;export{m as default};
|
package/bundle.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var d=Object.create;var n=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var g=(e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})},l=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of y(t))!k.call(e,a)&&a!==o&&n(e,a,{get:()=>t[a],enumerable:!(r=u(t,a))||r.enumerable});return e};var i=(e,t,o)=>(o=e!=null?d(m(e)):{},l(t||!e||!e.__esModule?n(o,"default",{value:e,enumerable:!0}):o,e)),I=e=>l(n({},"__esModule",{value:!0}),e);var R={};g(R,{GlobalStore:()=>S.default,actions:()=>b.actions,asyncStorageWrapper:()=>A.default,createContext:()=>x.createContext,createGlobalState:()=>f.createGlobalState,isRecord:()=>p.isRecord,shallowCompare:()=>c.shallowCompare,throwWrongKeyOnActionCollectionConfig:()=>C.throwWrongKeyOnActionCollectionConfig,uniqueId:()=>s.uniqueId});module.exports=I(R);var c=require("./shallowCompare.cjs"),s=require("./uniqueId.cjs"),C=require("./throwWrongKeyOnActionCollectionConfig.cjs"),p=require("./isRecord.cjs"),b=require("./actions.cjs"),x=require("./createContext.cjs"),S=i(require("./GlobalStore.cjs")),f=require("./createGlobalState.cjs"),A=i(require("./asyncStorageWrapper.cjs"));
|
package/bundle.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";var d=Object.create;var n=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var g=(e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})},l=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of y(t))!k.call(e,a)&&a!==o&&n(e,a,{get:()=>t[a],enumerable:!(r=u(t,a))||r.enumerable});return e};var i=(e,t,o)=>(o=e!=null?d(m(e)):{},l(t||!e||!e.__esModule?n(o,"default",{value:e,enumerable:!0}):o,e)),I=e=>l(n({},"__esModule",{value:!0}),e);var R={};g(R,{GlobalStore:()=>S.default,actions:()=>b.actions,asyncStorageWrapper:()=>A.default,createContext:()=>x.createContext,createGlobalState:()=>f.createGlobalState,isRecord:()=>p.isRecord,shallowCompare:()=>c.shallowCompare,throwWrongKeyOnActionCollectionConfig:()=>C.throwWrongKeyOnActionCollectionConfig,uniqueId:()=>s.uniqueId});module.exports=I(R);var c=require("./shallowCompare.js"),s=require("./uniqueId.js"),C=require("./throwWrongKeyOnActionCollectionConfig.js"),p=require("./isRecord.js"),b=require("./actions.js"),x=require("./createContext.js"),S=i(require("./GlobalStore.js")),f=require("./createGlobalState.js"),A=i(require("./asyncStorageWrapper.js"));
|
package/bundle.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{shallowCompare as o}from"./shallowCompare.mjs";import{uniqueId as n}from"./uniqueId.mjs";import{throwWrongKeyOnActionCollectionConfig as l}from"./throwWrongKeyOnActionCollectionConfig.mjs";import{isRecord as c}from"./isRecord.mjs";import{actions as C}from"./actions.mjs";import{createContext as b}from"./createContext.mjs";import{default as S}from"./GlobalStore.mjs";import{createGlobalState as A}from"./createGlobalState.mjs";import{default as u}from"./asyncStorageWrapper.mjs";export{S as GlobalStore,C as actions,u as asyncStorageWrapper,b as createContext,A as createGlobalState,c as isRecord,o as shallowCompare,l as throwWrongKeyOnActionCollectionConfig,n as uniqueId};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var f=Object.create;var n=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,i=Object.prototype.hasOwnProperty;var c=(t,e)=>{for(var o in e)n(t,o,{get:e[o],enumerable:!0})},C=(t,e,o,x)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of a(e))!i.call(t,r)&&r!==o&&n(t,r,{get:()=>e[r],enumerable:!(x=y(e,r))||x.enumerable});return t};var k=(t,e,o)=>(o=t!=null?f(d(t)):{},C(e||!t||!t.__esModule?n(o,"default",{value:t,enumerable:!0}):o,t)),l=t=>C(n({},"__esModule",{value:!0}),t);var m={};c(m,{createContext:()=>p.createContext,default:()=>p.default});module.exports=l(m);var p=k(require("react-hooks-global-states/createContext"));
|
package/createContext.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";var f=Object.create;var n=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,i=Object.prototype.hasOwnProperty;var c=(t,e)=>{for(var o in e)n(t,o,{get:e[o],enumerable:!0})},C=(t,e,o,x)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of a(e))!i.call(t,r)&&r!==o&&n(t,r,{get:()=>e[r],enumerable:!(x=y(e,r))||x.enumerable});return t};var k=(t,e,o)=>(o=t!=null?f(d(t)):{},C(e||!t||!t.__esModule?n(o,"default",{value:t,enumerable:!0}):o,t)),l=t=>C(n({},"__esModule",{value:!0}),t);var m={};c(m,{createContext:()=>p.createContext,default:()=>p.default});module.exports=l(m);var p=k(require("react-hooks-global-states/createContext"));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createContext as o,default as r}from"react-hooks-global-states/createContext";export{o as createContext,r as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var n=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var r=Object.prototype.hasOwnProperty;var A=(t,a)=>{for(var o in a)n(t,o,{get:a[o],enumerable:!0})},d=(t,a,o,c)=>{if(a&&typeof a=="object"||typeof a=="function")for(let e of S(a))!r.call(t,e)&&e!==o&&n(t,e,{get:()=>a[e],enumerable:!(c=i(a,e))||c.enumerable});return t};var f=t=>d(n({},"__esModule",{value:!0}),t);var g={};A(g,{createGlobalState:()=>s,default:()=>C});module.exports=f(g);var l=require("./GlobalStore.cjs"),s=(...t)=>new l.GlobalStore(...t).use,C=s;
|
package/createGlobalState.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StateHook, ActionCollectionConfig, ActionCollectionResult, GlobalStoreCallbacks } from "react-hooks-global-states/types";
|
|
1
|
+
import type { StateHook, ActionCollectionConfig, ActionCollectionResult, GlobalStoreCallbacks, Any, AnyActions } from "react-hooks-global-states/types";
|
|
2
2
|
import { AsyncStorageConfig, BaseMetadata, AsyncMetadata } from "./types";
|
|
3
3
|
import React from "react";
|
|
4
4
|
export type { InferActionsType, InferStateApi, AnyActions, } from "react-hooks-global-states/createGlobalState";
|
|
@@ -22,7 +22,7 @@ interface CreateGlobalState {
|
|
|
22
22
|
* );
|
|
23
23
|
* }
|
|
24
24
|
*/
|
|
25
|
-
<State>(state: State): StateHook<State, React.Dispatch<React.SetStateAction<State>>, BaseMetadata>;
|
|
25
|
+
<State>(state: State | (() => State)): StateHook<State, React.Dispatch<React.SetStateAction<State>>, BaseMetadata>;
|
|
26
26
|
/**
|
|
27
27
|
* Creates a global state hook that you can use across your application
|
|
28
28
|
* @param state initial state value
|
|
@@ -73,10 +73,10 @@ interface CreateGlobalState {
|
|
|
73
73
|
* }
|
|
74
74
|
* ```
|
|
75
75
|
*/
|
|
76
|
-
<State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata> | null | {}, PublicStateMutator = keyof ActionsConfig extends never | undefined ? React.Dispatch<React.SetStateAction<State>> : ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>>(state: State, args: {
|
|
76
|
+
<State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata> | null | {}, PublicStateMutator = keyof ActionsConfig extends never | undefined ? React.Dispatch<React.SetStateAction<State>> : ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>>(state: State | (() => State), args: {
|
|
77
77
|
name?: string;
|
|
78
|
-
metadata?: Metadata;
|
|
79
|
-
callbacks?: GlobalStoreCallbacks<
|
|
78
|
+
metadata?: Metadata | (() => Metadata);
|
|
79
|
+
callbacks?: GlobalStoreCallbacks<Any, AnyActions, Any>;
|
|
80
80
|
actions?: ActionsConfig;
|
|
81
81
|
asyncStorage?: AsyncStorageConfig<State>;
|
|
82
82
|
}): StateHook<State, PublicStateMutator, AsyncMetadata<Metadata>>;
|
|
@@ -130,10 +130,10 @@ interface CreateGlobalState {
|
|
|
130
130
|
* }
|
|
131
131
|
* ```
|
|
132
132
|
*/
|
|
133
|
-
<State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata>, PublicStateMutator = ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>>(state: State, args: {
|
|
133
|
+
<State, Metadata extends BaseMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata>, PublicStateMutator = ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>>(state: State | (() => State), args: {
|
|
134
134
|
name?: string;
|
|
135
|
-
metadata?: Metadata;
|
|
136
|
-
callbacks?: GlobalStoreCallbacks<
|
|
135
|
+
metadata?: Metadata | (() => Metadata);
|
|
136
|
+
callbacks?: GlobalStoreCallbacks<Any, AnyActions, Any>;
|
|
137
137
|
actions: ActionsConfig;
|
|
138
138
|
asyncStorage?: AsyncStorageConfig<State>;
|
|
139
139
|
}): StateHook<State, PublicStateMutator, Metadata>;
|
package/createGlobalState.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";var n=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var r=Object.prototype.hasOwnProperty;var A=(t,a)=>{for(var o in a)n(t,o,{get:a[o],enumerable:!0})},d=(t,a,o,c)=>{if(a&&typeof a=="object"||typeof a=="function")for(let e of S(a))!r.call(t,e)&&e!==o&&n(t,e,{get:()=>a[e],enumerable:!(c=i(a,e))||c.enumerable});return t};var f=t=>d(n({},"__esModule",{value:!0}),t);var g={};A(g,{createGlobalState:()=>s,default:()=>C});module.exports=f(g);var l=require("./GlobalStore.js"),s=(...t)=>new l.GlobalStore(...t).use,C=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{GlobalStore as a}from"./GlobalStore.mjs";var e=(...t)=>new a(...t).use,n=e;export{e as createGlobalState,n as default};
|
package/debug.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var b=(p,o,i,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of x(o))!a.call(p,r)&&r!==i&&e(p,r,{get:()=>o[r],enumerable:!(t=m(o,r))||t.enumerable});return p};var c=p=>b(e({},"__esModule",{value:!0}),p);var d={};module.exports=c(d);var g=require("react-hooks-global-states/debug");
|
package/debug.d.ts
ADDED
package/debug.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var b=(p,o,i,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of x(o))!a.call(p,r)&&r!==i&&e(p,r,{get:()=>o[r],enumerable:!(t=m(o,r))||t.enumerable});return p};var c=p=>b(e({},"__esModule",{value:!0}),p);var d={};module.exports=c(d);var g=require("react-hooks-global-states/debug");
|
package/debug.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"react-hooks-global-states/debug";
|
package/index.d.ts
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
* By handling the same structure as the original library,
|
|
3
3
|
* We can add the specific overrides for web while keeping the modularity of the library.
|
|
4
4
|
*/
|
|
5
|
-
export type {
|
|
6
|
-
export { shallowCompare } from
|
|
7
|
-
export { uniqueId
|
|
8
|
-
export { throwWrongKeyOnActionCollectionConfig } from
|
|
9
|
-
export { isRecord } from
|
|
10
|
-
export {
|
|
11
|
-
export
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
5
|
+
export type { ActionCollectionConfig, ActionCollectionResult, Any, AnyActions, AnyFunction, BaseMetadata, BrandedId, CleanupFunction, ContextActionCollectionConfig, ContextActionCollectionResult, ContextHook, ContextProvider, ContextProviderExtensions, ContextPublicApi, ContextStoreTools, ContextStoreToolsExtensions, CreateContext, CreateGlobalState, GlobalStoreCallbacks, GlobalStoreContextCallbacks, InferAPI, InferActionsType, InferContextApi, InferStateApi, MetadataGetter, MetadataSetter, ObservableFragment, ReadonlyContextHook, ReadonlyContextPublicApi, ReadonlyHook, ReadonlyStateApi, SelectHook, SelectorCallback, StateApi, StateChanges, StateHook, StoreTools, SubscribeCallback, SubscribeCallbackConfig, SubscribeToState, SubscriberParameters, SubscriptionCallback, UniqueId, UnsubscribeCallback, UseHookOptions, } from './types';
|
|
6
|
+
export { shallowCompare } from './shallowCompare';
|
|
7
|
+
export { uniqueId } from './uniqueId';
|
|
8
|
+
export { throwWrongKeyOnActionCollectionConfig } from './throwWrongKeyOnActionCollectionConfig';
|
|
9
|
+
export { isRecord } from './isRecord';
|
|
10
|
+
export { actions } from './actions';
|
|
11
|
+
export { createContext } from './createContext';
|
|
12
|
+
export type { AsyncStorageConfig, AsyncMetadata, ItemEnvelope } from './types';
|
|
13
|
+
export { default as GlobalStore } from './GlobalStore';
|
|
14
|
+
export { createGlobalState } from './createGlobalState';
|
|
15
|
+
export { default as asyncStorageWrapper, type AsyncStorageManager } from './asyncStorageWrapper';
|
package/isPromise.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var f=(n,o)=>{for(var s in o)t(n,s,{get:o[s],enumerable:!0})},k=(n,o,s,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of u(o))!a.call(n,e)&&e!==s&&t(n,e,{get:()=>o[e],enumerable:!(i=r(o,e))||i.enumerable});return n};var m=n=>k(t({},"__esModule",{value:!0}),n);var c={};f(c,{default:()=>P});module.exports=m(c);var w=n=>!!(n&&typeof n.then=="function"),P=w;
|
package/isPromise.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var f=(n,o)=>{for(var s in o)t(n,s,{get:o[s],enumerable:!0})},k=(n,o,s,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of u(o))!a.call(n,e)&&e!==s&&t(n,e,{get:()=>o[e],enumerable:!(i=r(o,e))||i.enumerable});return n};var m=n=>k(t({},"__esModule",{value:!0}),n);var c={};f(c,{default:()=>P});module.exports=m(c);var w=n=>!!(n&&typeof n.then=="function"),P=w;
|
package/isPromise.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o=n=>!!(n&&typeof n.then=="function"),e=o;export{e as default};
|
package/isRecord.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var i=Object.create;var f=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty;var u=(e,o)=>{for(var r in o)f(e,r,{get:o[r],enumerable:!0})},c=(e,o,r,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let d of m(o))!s.call(e,d)&&d!==r&&f(e,d,{get:()=>o[d],enumerable:!(a=l(o,d))||a.enumerable});return e};var x=(e,o,r)=>(r=e!=null?i(p(e)):{},c(o||!e||!e.__esModule?f(r,"default",{value:e,enumerable:!0}):r,e)),R=e=>c(f({},"__esModule",{value:!0}),e);var b={};u(b,{default:()=>t.default,isRecord:()=>t.isRecord});module.exports=R(b);var t=x(require("react-hooks-global-states/isRecord"));
|
package/isRecord.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";var i=Object.create;var f=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty;var u=(e,o)=>{for(var r in o)f(e,r,{get:o[r],enumerable:!0})},c=(e,o,r,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let d of m(o))!s.call(e,d)&&d!==r&&f(e,d,{get:()=>o[d],enumerable:!(a=l(o,d))||a.enumerable});return e};var x=(e,o,r)=>(r=e!=null?i(p(e)):{},c(o||!e||!e.__esModule?f(r,"default",{value:e,enumerable:!0}):r,e)),R=e=>c(f({},"__esModule",{value:!0}),e);var b={};u(b,{default:()=>t.default,isRecord:()=>t.isRecord});module.exports=R(b);var t=x(require("react-hooks-global-states/isRecord"));
|
package/isRecord.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isRecord as r,default as d}from"react-hooks-global-states/isRecord";export{d as default,r as isRecord};
|
package/package.json
CHANGED
|
@@ -1,72 +1,80 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-global-state-hooks",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.0.4-beta",
|
|
4
4
|
"description": "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 async-storage or react-native dependencies just use version 5.0.15 or user react-hooks-global-states instead",
|
|
5
|
-
"main": "./bundle.
|
|
5
|
+
"main": "./bundle.cjs",
|
|
6
|
+
"module": "./bundle.mjs",
|
|
6
7
|
"types": "./index.d.ts",
|
|
7
8
|
"sideEffects": false,
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"import": "./bundle.mjs",
|
|
13
|
+
"require": "./bundle.cjs"
|
|
13
14
|
},
|
|
14
15
|
"./asyncStorageWrapper": {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
16
|
+
"types": "./asyncStorageWrapper.d.ts",
|
|
17
|
+
"import": "./asyncStorageWrapper.mjs",
|
|
18
|
+
"require": "./asyncStorageWrapper.cjs"
|
|
18
19
|
},
|
|
19
20
|
"./createContext": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"types": "./createContext.d.ts",
|
|
22
|
+
"import": "./createContext.mjs",
|
|
23
|
+
"require": "./createContext.cjs"
|
|
23
24
|
},
|
|
24
25
|
"./createGlobalState": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"types": "./createGlobalState.d.ts",
|
|
27
|
+
"import": "./createGlobalState.mjs",
|
|
28
|
+
"require": "./createGlobalState.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./types": {
|
|
31
|
+
"types": "./types.d.ts",
|
|
32
|
+
"import": "./types.mjs",
|
|
33
|
+
"require": "./types.cjs"
|
|
28
34
|
},
|
|
29
35
|
"./GlobalStore": {
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
36
|
+
"types": "./GlobalStore.d.ts",
|
|
37
|
+
"import": "./GlobalStore.mjs",
|
|
38
|
+
"require": "./GlobalStore.cjs"
|
|
33
39
|
},
|
|
34
40
|
"./isRecord": {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
41
|
+
"types": "./isRecord.d.ts",
|
|
42
|
+
"import": "./isRecord.mjs",
|
|
43
|
+
"require": "./isRecord.cjs"
|
|
38
44
|
},
|
|
39
45
|
"./shallowCompare": {
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
46
|
+
"types": "./shallowCompare.d.ts",
|
|
47
|
+
"import": "./shallowCompare.mjs",
|
|
48
|
+
"require": "./shallowCompare.cjs"
|
|
43
49
|
},
|
|
44
50
|
"./throwWrongKeyOnActionCollectionConfig": {
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
}
|
|
51
|
+
"types": "./throwWrongKeyOnActionCollectionConfig.d.ts",
|
|
52
|
+
"import": "./throwWrongKeyOnActionCollectionConfig.mjs",
|
|
53
|
+
"require": "./throwWrongKeyOnActionCollectionConfig.cjs"
|
|
54
|
+
},
|
|
55
|
+
"./uniqueId": {
|
|
56
|
+
"types": "./uniqueId.d.ts",
|
|
57
|
+
"import": "./uniqueId.mjs",
|
|
58
|
+
"require": "./uniqueId.cjs"
|
|
59
|
+
},
|
|
60
|
+
"./actions": {
|
|
61
|
+
"types": "./actions.d.ts",
|
|
62
|
+
"import": "./actions.mjs",
|
|
63
|
+
"require": "./actions.cjs"
|
|
64
|
+
},
|
|
65
|
+
"./debug": {
|
|
66
|
+
"types": "./debug.d.ts",
|
|
67
|
+
"import": "./debug.mjs",
|
|
68
|
+
"require": "./debug.cjs"
|
|
69
|
+
},
|
|
70
|
+
"./package.json": "./package.json"
|
|
49
71
|
},
|
|
50
72
|
"files": [
|
|
51
73
|
"*.js",
|
|
74
|
+
"*.cjs",
|
|
75
|
+
"*.mjs",
|
|
52
76
|
"*.d.ts"
|
|
53
77
|
],
|
|
54
|
-
"scripts": {
|
|
55
|
-
"format": "prettier --write . --log-level silent && yarn lint:fix",
|
|
56
|
-
"test": "yarn build && yarn jest",
|
|
57
|
-
"test:debug:no-watch": "node --inspect-brk node_modules/.bin/jest --no-watchman --runInBand",
|
|
58
|
-
"test:debug": "node --inspect-brk node_modules/.bin/jest --watch --runInBand",
|
|
59
|
-
"test:quick": "yarn test --no-coverage --maxWorkers=4 -c --no-watchman -u",
|
|
60
|
-
"test:coverage": "yarn test --maxWorkers=4 -c --colors --no-watchman --verbose --coverage",
|
|
61
|
-
"build": "yarn ts-check && yarn clean && webpack --config webpack.config.js",
|
|
62
|
-
"prepare": "yarn format && npm run build && yarn test:quick",
|
|
63
|
-
"version": "npm run format && yarn build && yarn jest && git add -A",
|
|
64
|
-
"postversion": "git push && git push --tags",
|
|
65
|
-
"lint": "eslint . --max-warnings=0",
|
|
66
|
-
"lint:fix": "eslint . --fix --max-warnings=0",
|
|
67
|
-
"clean": "find . -maxdepth 1 -type f \\( -name '*.js' -o -name '*.d.ts' \\) ! -name 'webpack.config.js' ! -name 'eslint.config.mts' -exec rm {} + && rm -rf coverage",
|
|
68
|
-
"ts-check": "tsc -p tsconfig.json --noEmit"
|
|
69
|
-
},
|
|
70
78
|
"repository": {
|
|
71
79
|
"type": "git",
|
|
72
80
|
"url": "git+https://github.com/johnny-quesada-developer/react-native-global-state-hooks.git"
|
|
@@ -89,55 +97,9 @@
|
|
|
89
97
|
"url": "https://github.com/johnny-quesada-developer/react-native-global-state-hooks/issues"
|
|
90
98
|
},
|
|
91
99
|
"homepage": "https://github.com/johnny-quesada-developer/react-native-global-state-hooks#readme",
|
|
92
|
-
"devDependencies": {
|
|
93
|
-
"@babel/core": "^7.21.3",
|
|
94
|
-
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
|
|
95
|
-
"@babel/plugin-transform-modules-commonjs": "^7.21.2",
|
|
96
|
-
"@babel/preset-env": "^7.20.2",
|
|
97
|
-
"@babel/preset-react": "^7.18.6",
|
|
98
|
-
"@babel/preset-typescript": "^7.21.0",
|
|
99
|
-
"@eslint/js": "^9.39.1",
|
|
100
|
-
"@react-native-async-storage/async-storage": ">=1.17.11",
|
|
101
|
-
"@testing-library/dom": "^10.4.0",
|
|
102
|
-
"@testing-library/react": "^16.3.0",
|
|
103
|
-
"@types/jest": "^29.5.11",
|
|
104
|
-
"@types/lodash": "^4.14.165",
|
|
105
|
-
"@types/react": "^18.0.38",
|
|
106
|
-
"@types/react-dom": "^18.0.11",
|
|
107
|
-
"@types/react-test-renderer": "^18.0.0",
|
|
108
|
-
"@typescript-eslint/eslint-plugin": "^4.9.1",
|
|
109
|
-
"@typescript-eslint/parser": "^4.9.1",
|
|
110
|
-
"babel-loader": "^9.1.2",
|
|
111
|
-
"clean-webpack-plugin": "^4.0.0",
|
|
112
|
-
"easy-cancelable-promise": "^1.0.2",
|
|
113
|
-
"eslint": "^9.39.1",
|
|
114
|
-
"eslint-config-airbnb": "^18.2.1",
|
|
115
|
-
"eslint-plugin-import": "^2.22.1",
|
|
116
|
-
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
117
|
-
"eslint-plugin-react": "^7.37.5",
|
|
118
|
-
"eslint-plugin-react-hooks": "^4.2.0",
|
|
119
|
-
"globals": "^16.5.0",
|
|
120
|
-
"jest": "^29.7.0",
|
|
121
|
-
"jest-environment-jsdom": "^29.7.0",
|
|
122
|
-
"jiti": "^2.6.1",
|
|
123
|
-
"json-storage-formatter": "^3.0.2",
|
|
124
|
-
"prettier": "^3.6.2",
|
|
125
|
-
"react": "^18.2.0",
|
|
126
|
-
"react-dom": "^18.2.0",
|
|
127
|
-
"react-native": ">=0.71.6",
|
|
128
|
-
"react-test-renderer": "^18.2.0",
|
|
129
|
-
"terser-webpack-plugin": "^5.6.1",
|
|
130
|
-
"ts-jest": "^29.1.1",
|
|
131
|
-
"ts-loader": "^9.4.2",
|
|
132
|
-
"tslib": "^2.5.0",
|
|
133
|
-
"typescript": "^5.3.3",
|
|
134
|
-
"typescript-eslint": "^8.46.3",
|
|
135
|
-
"webpack": "^5.76.3",
|
|
136
|
-
"webpack-cli": "^5.0.1"
|
|
137
|
-
},
|
|
138
100
|
"peerDependencies": {
|
|
139
101
|
"@react-native-async-storage/async-storage": ">=1.17.11",
|
|
140
|
-
"json-storage-formatter": "^
|
|
102
|
+
"json-storage-formatter": "^4.0.0",
|
|
141
103
|
"react": ">=18.0.0",
|
|
142
104
|
"react-native": ">=0.69.0"
|
|
143
105
|
},
|
|
@@ -156,6 +118,6 @@
|
|
|
156
118
|
}
|
|
157
119
|
},
|
|
158
120
|
"dependencies": {
|
|
159
|
-
"react-hooks-global-states": "^
|
|
121
|
+
"react-hooks-global-states": "^16.0.4-beta"
|
|
160
122
|
}
|
|
161
123
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=Object.create;var r=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var s=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var w=(o,a)=>{for(var e in a)r(o,e,{get:a[e],enumerable:!0})},p=(o,a,e,m)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of h(a))!u.call(o,l)&&l!==e&&r(o,l,{get:()=>a[l],enumerable:!(m=d(a,l))||m.enumerable});return o};var x=(o,a,e)=>(e=o!=null?t(s(o)):{},p(a||!o||!o.__esModule?r(e,"default",{value:o,enumerable:!0}):e,o)),C=o=>p(r({},"__esModule",{value:!0}),o);var b={};w(b,{default:()=>f.default,shallowCompare:()=>f.shallowCompare});module.exports=C(b);var f=x(require("react-hooks-global-states/shallowCompare"));
|
package/shallowCompare.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";var t=Object.create;var r=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var s=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var w=(o,a)=>{for(var e in a)r(o,e,{get:a[e],enumerable:!0})},p=(o,a,e,m)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of h(a))!u.call(o,l)&&l!==e&&r(o,l,{get:()=>a[l],enumerable:!(m=d(a,l))||m.enumerable});return o};var x=(o,a,e)=>(e=o!=null?t(s(o)):{},p(a||!o||!o.__esModule?r(e,"default",{value:o,enumerable:!0}):e,o)),C=o=>p(r({},"__esModule",{value:!0}),o);var b={};w(b,{default:()=>f.default,shallowCompare:()=>f.shallowCompare});module.exports=C(b);var f=x(require("react-hooks-global-states/shallowCompare"));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{shallowCompare as e,default as l}from"react-hooks-global-states/shallowCompare";export{l as default,e as shallowCompare};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var c=Object.create;var r=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var a=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var h=(o,n)=>{for(var t in n)r(o,t,{get:n[t],enumerable:!0})},l=(o,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of C(n))!d.call(o,e)&&e!==t&&r(o,e,{get:()=>n[e],enumerable:!(i=g(n,e))||i.enumerable});return o};var m=(o,n,t)=>(t=o!=null?c(a(o)):{},l(n||!o||!o.__esModule?r(t,"default",{value:o,enumerable:!0}):t,o)),p=o=>l(r({},"__esModule",{value:!0}),o);var u={};h(u,{default:()=>f.default,throwWrongKeyOnActionCollectionConfig:()=>f.throwWrongKeyOnActionCollectionConfig});module.exports=p(u);var f=m(require("react-hooks-global-states/throwWrongKeyOnActionCollectionConfig"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";var c=Object.create;var r=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var a=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var h=(o,n)=>{for(var t in n)r(o,t,{get:n[t],enumerable:!0})},l=(o,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of C(n))!d.call(o,e)&&e!==t&&r(o,e,{get:()=>n[e],enumerable:!(i=g(n,e))||i.enumerable});return o};var m=(o,n,t)=>(t=o!=null?c(a(o)):{},l(n||!o||!o.__esModule?r(t,"default",{value:o,enumerable:!0}):t,o)),p=o=>l(r({},"__esModule",{value:!0}),o);var u={};h(u,{default:()=>f.default,throwWrongKeyOnActionCollectionConfig:()=>f.throwWrongKeyOnActionCollectionConfig});module.exports=p(u);var f=m(require("react-hooks-global-states/throwWrongKeyOnActionCollectionConfig"));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{throwWrongKeyOnActionCollectionConfig as t,default as e}from"react-hooks-global-states/throwWrongKeyOnActionCollectionConfig";export{e as default,t as throwWrongKeyOnActionCollectionConfig};
|
package/tryCatch.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var T=Object.create;var l=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var o=Object.getPrototypeOf,i=Object.prototype.hasOwnProperty;var c=(r,e)=>{for(var t in e)l(r,t,{get:e[t],enumerable:!0})},s=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let u of y(e))!i.call(r,u)&&u!==t&&l(r,u,{get:()=>e[u],enumerable:!(n=d(e,u))||n.enumerable});return r};var R=(r,e,t)=>(t=r!=null?T(o(r)):{},s(e||!r||!r.__esModule?l(t,"default",{value:r,enumerable:!0}):t,r)),h=r=>s(l({},"__esModule",{value:!0}),r);var p={};c(p,{default:()=>x});module.exports=h(p);var a=R(require("./isPromise.cjs"));function F(r,e){try{let t=r();return(0,a.default)(t)?t.then(n=>({result:n,error:null})).catch(n=>({result:e!=null?e:null,error:n})):{result:t,error:null}}catch(t){return{result:e!=null?e:null,error:t}}}var x=F;
|
package/tryCatch.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var T=Object.create;var l=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var o=Object.getPrototypeOf,i=Object.prototype.hasOwnProperty;var c=(r,e)=>{for(var t in e)l(r,t,{get:e[t],enumerable:!0})},s=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let u of y(e))!i.call(r,u)&&u!==t&&l(r,u,{get:()=>e[u],enumerable:!(n=d(e,u))||n.enumerable});return r};var R=(r,e,t)=>(t=r!=null?T(o(r)):{},s(e||!r||!r.__esModule?l(t,"default",{value:r,enumerable:!0}):t,r)),h=r=>s(l({},"__esModule",{value:!0}),r);var p={};c(p,{default:()=>x});module.exports=h(p);var a=R(require("./isPromise.js"));function F(r,e){try{let t=r();return(0,a.default)(t)?t.then(n=>({result:n,error:null})).catch(n=>({result:e!=null?e:null,error:n})):{result:t,error:null}}catch(t){return{result:e!=null?e:null,error:t}}}var x=F;
|
package/tryCatch.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import u from"./isPromise.mjs";function l(n,e){try{let r=n();return u(r)?r.then(t=>({result:t,error:null})).catch(t=>({result:e!=null?e:null,error:t})):{result:r,error:null}}catch(r){return{result:e!=null?e:null,error:r}}}var a=l;export{a as default};
|
package/types.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var n=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var S=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of i(t))!d.call(e,a)&&a!==r&&n(e,a,{get:()=>t[a],enumerable:!(o=s(t,a))||o.enumerable});return e};var l=e=>S(n({},"__esModule",{value:!0}),e);var c={};module.exports=l(c);
|
package/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export type { StateApi, AnyFunction, StateChanges, UseHookOptions, UnsubscribeCallback, SubscribeCallbackConfig, SubscribeCallback, SelectorCallback, SubscriberParameters, SubscriptionCallback, } from "react-hooks-global-states/types";
|
|
1
|
+
export type { StateApi, AnyFunction, StateChanges, UseHookOptions, UnsubscribeCallback, SubscribeCallbackConfig, SubscribeCallback, SelectorCallback, SubscriberParameters, SubscriptionCallback, Any, AnyActions, BrandedId, CleanupFunction, ContextActionCollectionConfig, ContextActionCollectionResult, ContextHook, ContextProvider, ContextProviderExtensions, ContextPublicApi, ContextStoreTools, ContextStoreToolsExtensions, CreateContext, CreateGlobalState, GlobalStoreContextCallbacks, InferAPI, InferActionsType, InferContextApi, InferStateApi, ReadonlyContextHook, ReadonlyContextPublicApi, ReadonlyHook, ReadonlyStateApi, SelectHook, SubscribeToState, UniqueId, } from "react-hooks-global-states/types";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import type { BaseMetadata as BaseLibraryMetadata, StateApi, StateChanges, SubscriberParameters, UseHookOptions } from "react-hooks-global-states";
|
|
3
|
+
import type { BaseMetadata as BaseLibraryMetadata, CleanupFunction, StateApi, StateChanges, SubscriberParameters, UseHookOptions } from "react-hooks-global-states";
|
|
4
4
|
import { AnyFunction, SubscribeToState } from "react-hooks-global-states/types";
|
|
5
5
|
export type AsyncStorageConfig<State> = {
|
|
6
6
|
/**
|
|
@@ -124,6 +124,12 @@ export type StoreTools<State, StateMutator = React.Dispatch<React.SetStateAction
|
|
|
124
124
|
*/
|
|
125
125
|
actions: StateMutator extends AnyFunction ? null : StateMutator;
|
|
126
126
|
/**
|
|
127
|
+
* @description Metadata associated with the global state.
|
|
128
|
+
* Metadata is non-reactive; reading it will not trigger re-renders. To change it use `setMetadata`.
|
|
129
|
+
*/
|
|
130
|
+
readonly metadata: Metadata;
|
|
131
|
+
/**
|
|
132
|
+
* @deprecated Use the `metadata` property instead, e.g. `const { metadata } = storeTools;`. Metadata is stable, so it is exposed directly.
|
|
127
133
|
* @description Metadata associated with the global state
|
|
128
134
|
*/
|
|
129
135
|
getMetadata: () => Metadata;
|
|
@@ -138,7 +144,12 @@ export type StoreTools<State, StateMutator = React.Dispatch<React.SetStateAction
|
|
|
138
144
|
/**
|
|
139
145
|
* @description Function to set the state value
|
|
140
146
|
*/
|
|
141
|
-
setState: React.
|
|
147
|
+
setState: (setter: React.SetStateAction<State>, args?: {
|
|
148
|
+
/** Force update even if the state value did not change (advanced use only). */
|
|
149
|
+
forceUpdate?: boolean;
|
|
150
|
+
/** Optional identifier visible on the devtools. */
|
|
151
|
+
identifier?: string;
|
|
152
|
+
}) => void;
|
|
142
153
|
/**
|
|
143
154
|
* @description Subscribe to the state changes
|
|
144
155
|
* You can subscribe to the whole state or to a fragment of the state by passing a selector as first parameter,
|
|
@@ -179,7 +190,7 @@ export type GlobalStoreCallbacks<State, StateMutator, Metadata extends BaseMetad
|
|
|
179
190
|
/**
|
|
180
191
|
* @description Called when the store is initialized
|
|
181
192
|
*/
|
|
182
|
-
onInit?: (args: StoreTools<State, StateMutator, Metadata>) => void;
|
|
193
|
+
onInit?: (args: StoreTools<State, StateMutator, Metadata>) => void | Promise<void> | CleanupFunction;
|
|
183
194
|
/**
|
|
184
195
|
* @description Called when the state has changed
|
|
185
196
|
*/
|
package/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";var n=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var S=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of i(t))!d.call(e,a)&&a!==r&&n(e,a,{get:()=>t[a],enumerable:!(o=s(t,a))||o.enumerable});return e};var l=e=>S(n({},"__esModule",{value:!0}),e);var c={};module.exports=l(c);
|
package/types.mjs
ADDED
|
File without changes
|
package/uniqueId.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var a=Object.create;var n=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var o=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var y=(e,d)=>{for(var t in d)n(e,t,{get:d[t],enumerable:!0})},I=(e,d,t,r)=>{if(d&&typeof d=="object"||typeof d=="function")for(let u of i(d))!q.call(e,u)&&u!==t&&n(e,u,{get:()=>d[u],enumerable:!(r=f(d,u))||r.enumerable});return e};var l=(e,d,t)=>(t=e!=null?a(o(e)):{},I(d||!e||!e.__esModule?n(t,"default",{value:e,enumerable:!0}):t,e)),m=e=>I(n({},"__esModule",{value:!0}),e);var x={};y(x,{default:()=>p.default,uniqueId:()=>p.uniqueId});module.exports=m(x);var p=l(require("react-hooks-global-states/uniqueId"));
|
package/uniqueId.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { uniqueId, BrandedId,
|
|
1
|
+
export { uniqueId, default, type BrandedId, type UniqueId } from "react-hooks-global-states/uniqueId";
|
package/uniqueId.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";var a=Object.create;var n=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var o=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var y=(e,d)=>{for(var t in d)n(e,t,{get:d[t],enumerable:!0})},I=(e,d,t,r)=>{if(d&&typeof d=="object"||typeof d=="function")for(let u of i(d))!q.call(e,u)&&u!==t&&n(e,u,{get:()=>d[u],enumerable:!(r=f(d,u))||r.enumerable});return e};var l=(e,d,t)=>(t=e!=null?a(o(e)):{},I(d||!e||!e.__esModule?n(t,"default",{value:e,enumerable:!0}):t,e)),m=e=>I(n({},"__esModule",{value:!0}),e);var x={};y(x,{default:()=>p.default,uniqueId:()=>p.uniqueId});module.exports=m(x);var p=l(require("react-hooks-global-states/uniqueId"));
|
package/uniqueId.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{uniqueId as t,default as u}from"react-hooks-global-states/uniqueId";export{u as default,t as uniqueId};
|
package/webpack.config.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-undef */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const TerserPlugin = require("terser-webpack-plugin");
|
|
5
|
-
|
|
6
|
-
const individualEntries = {
|
|
7
|
-
// inherit from react-global-state-hooks
|
|
8
|
-
createContext: "./src/createContext.ts",
|
|
9
|
-
GlobalStore: "./src/GlobalStore.ts",
|
|
10
|
-
createGlobalState: "./src/createGlobalState.ts",
|
|
11
|
-
types: "./src/types.ts",
|
|
12
|
-
isRecord: "./src/isRecord.ts",
|
|
13
|
-
shallowCompare: "./src/shallowCompare.ts",
|
|
14
|
-
throwWrongKeyOnActionCollectionConfig: "./src/throwWrongKeyOnActionCollectionConfig.ts",
|
|
15
|
-
uniqueId: "./src/uniqueId.ts",
|
|
16
|
-
|
|
17
|
-
// extras
|
|
18
|
-
asyncStorageWrapper: "./src/asyncStorageWrapper.ts",
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const generateExternalEntryMappings = () => {
|
|
22
|
-
const keys = Object.keys(individualEntries);
|
|
23
|
-
const fromEntries = keys.reduce((acc, key) => {
|
|
24
|
-
acc[`./${key}`] = `./${key}.js`;
|
|
25
|
-
return acc;
|
|
26
|
-
}, {});
|
|
27
|
-
|
|
28
|
-
const fromBasePackage = keys.reduce((acc, key) => {
|
|
29
|
-
acc[`react-hooks-global-states/${key}`] = `react-hooks-global-states/${key}`;
|
|
30
|
-
return acc;
|
|
31
|
-
}, {});
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
...fromEntries,
|
|
35
|
-
...fromBasePackage,
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
module.exports = {
|
|
40
|
-
mode: "production",
|
|
41
|
-
entry: {
|
|
42
|
-
bundle: "./src/index.ts",
|
|
43
|
-
...individualEntries,
|
|
44
|
-
},
|
|
45
|
-
externals: {
|
|
46
|
-
react: "react",
|
|
47
|
-
"react-native": "react-native",
|
|
48
|
-
"@react-native-async-storage/async-storage": "@react-native-async-storage/async-storage",
|
|
49
|
-
|
|
50
|
-
// avoid bundle the base package
|
|
51
|
-
"json-storage-formatter": "json-storage-formatter",
|
|
52
|
-
"json-storage-formatter/clone": "json-storage-formatter/clone",
|
|
53
|
-
"json-storage-formatter/isNil": "json-storage-formatter/isNil",
|
|
54
|
-
"json-storage-formatter/isNumber": "json-storage-formatter/isNumber",
|
|
55
|
-
"json-storage-formatter/isBoolean": "json-storage-formatter/isBoolean",
|
|
56
|
-
"json-storage-formatter/isString": "json-storage-formatter/isString",
|
|
57
|
-
"json-storage-formatter/isDate": "json-storage-formatter/isDate",
|
|
58
|
-
"json-storage-formatter/isRegex": "json-storage-formatter/isRegex",
|
|
59
|
-
"json-storage-formatter/isFunction": "json-storage-formatter/isFunction",
|
|
60
|
-
"json-storage-formatter/isPrimitive": "json-storage-formatter/isPrimitive",
|
|
61
|
-
"json-storage-formatter/types": "json-storage-formatter/types",
|
|
62
|
-
"json-storage-formatter/formatFromStore": "json-storage-formatter/formatFromStore",
|
|
63
|
-
"json-storage-formatter/formatToStore": "json-storage-formatter/formatToStore",
|
|
64
|
-
|
|
65
|
-
"react-hooks-global-states": "react-hooks-global-states",
|
|
66
|
-
|
|
67
|
-
...generateExternalEntryMappings(),
|
|
68
|
-
},
|
|
69
|
-
output: {
|
|
70
|
-
path: path.resolve(__dirname),
|
|
71
|
-
filename: ({ chunk: { name } }) => {
|
|
72
|
-
return `${name}.js`;
|
|
73
|
-
},
|
|
74
|
-
libraryTarget: "umd",
|
|
75
|
-
library: "react-native-global-state-hooks",
|
|
76
|
-
globalObject: "this",
|
|
77
|
-
},
|
|
78
|
-
resolve: {
|
|
79
|
-
extensions: [".ts", ".js"],
|
|
80
|
-
},
|
|
81
|
-
module: {
|
|
82
|
-
rules: [
|
|
83
|
-
{
|
|
84
|
-
test: /\.ts$/,
|
|
85
|
-
use: [
|
|
86
|
-
{
|
|
87
|
-
loader: "babel-loader",
|
|
88
|
-
options: {
|
|
89
|
-
presets: ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"],
|
|
90
|
-
plugins: [
|
|
91
|
-
"@babel/plugin-transform-modules-commonjs",
|
|
92
|
-
"@babel/plugin-proposal-export-namespace-from",
|
|
93
|
-
],
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
loader: "ts-loader",
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
exclude: /node_modules/,
|
|
101
|
-
},
|
|
102
|
-
],
|
|
103
|
-
},
|
|
104
|
-
optimization: {
|
|
105
|
-
minimize: true,
|
|
106
|
-
minimizer: [
|
|
107
|
-
new TerserPlugin({
|
|
108
|
-
extractComments: false,
|
|
109
|
-
terserOptions: {
|
|
110
|
-
compress: {
|
|
111
|
-
passes: 5,
|
|
112
|
-
drop_console: true,
|
|
113
|
-
drop_debugger: true,
|
|
114
|
-
keep_fargs: false,
|
|
115
|
-
keep_infinity: true,
|
|
116
|
-
reduce_funcs: true,
|
|
117
|
-
reduce_vars: true,
|
|
118
|
-
keep_fnames: false,
|
|
119
|
-
toplevel: true,
|
|
120
|
-
},
|
|
121
|
-
mangle: {
|
|
122
|
-
toplevel: true,
|
|
123
|
-
properties: false,
|
|
124
|
-
},
|
|
125
|
-
format: {
|
|
126
|
-
comments: false,
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
}),
|
|
130
|
-
],
|
|
131
|
-
},
|
|
132
|
-
};
|