react-hooks-global-states 5.0.0 → 6.0.0

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/README.md CHANGED
@@ -422,7 +422,7 @@ const initialState: CounterState = {
422
422
  count: 0,
423
423
  };
424
424
 
425
- export const [useCounterContext, CounterProvider] = createStatefulContext(initialState, () => ({
425
+ export const [useCounterContext, CounterProvider] = createContext(initialState, () => ({
426
426
  increase: (value: number = 1) => {
427
427
  return ({ setState }: StoreTools<CounterState>) => {
428
428
  setState((state) => ({
@@ -651,29 +651,18 @@ Creating a global hook that connects to an asyncStorage is made incredibly easy
651
651
  This function returns a new global state builder wrapped with the desired custom implementation, allowing you to get creative! Le'ts see and example:
652
652
 
653
653
  ```ts
654
- import { formatFromStore, formatToStore, createCustomGlobalState } = 'react-hooks-global-states'
655
-
656
- // Optional configuration available for the consumers of the builder
657
- type HookConfig = {
658
- asyncStorageKey?: string;
659
- };
660
-
661
- // This is the base metadata that all the stores created from the builder will have.
662
- type BaseMetadata = {
663
- isAsyncStorageReady?: boolean;
664
- };
665
-
666
654
  export const createGlobalState = createCustomGlobalState<
667
- BaseMetadata,
668
- HookConfig
655
+ {
656
+ asyncStorageKey?: string;
657
+ },
658
+ {
659
+ isAsyncStorageReady?: boolean;
660
+ }
669
661
  >({
670
- /**
671
- * This function executes immediately after the global state is created, before the invocations of the hook
672
- */
673
662
  onInitialize: async ({ setState, setMetadata }, config) => {
674
663
  setMetadata((metadata) => ({
675
664
  ...(metadata ?? {}),
676
- isAsyncStorageReady: null,
665
+ isAsyncStorageReady: undefined,
677
666
  }));
678
667
 
679
668
  const asyncStorageKey = config?.asyncStorageKey;
@@ -681,14 +670,13 @@ export const createGlobalState = createCustomGlobalState<
681
670
 
682
671
  const storedItem = (await asyncStorage.getItem(asyncStorageKey)) as string;
683
672
 
684
- // update the metadata, remember, metadata is not reactive
685
673
  setMetadata((metadata) => ({
686
674
  ...metadata,
687
675
  isAsyncStorageReady: true,
688
676
  }));
689
677
 
690
678
  if (storedItem === null) {
691
- return setState((state) => state, { forceUpdate: true });
679
+ return setState((state: unknown) => state, { forceUpdate: true });
692
680
  }
693
681
 
694
682
  const parsed = formatFromStore(storedItem, {
@@ -733,10 +721,10 @@ That's correct! If you add an **asyncStorageKey** to the state configuration, th
733
721
  Let's see how to use this async storage hook into our components:
734
722
 
735
723
  ```ts
736
- const [todos, setTodos, metadata] = useTodos();
724
+ const [todos, setTodos, {isAsyncStorageReady}] = useTodos();
737
725
 
738
726
  return (<>
739
- {metadata.isAsyncStorageReady ? <TodoList todos={todos} /> : <Text>Loading...</Text>}
727
+ {isAsyncStorageReady ? <TodoList todos={todos} /> : <Text>Loading...</Text>}
740
728
  <>);
741
729
  ```
742
730
 
@@ -808,58 +796,58 @@ const useData = createGlobalState(
808
796
  metadata: {
809
797
  someExtraInformation: 'someExtraInformation',
810
798
  },
811
- // onSubscribed: (StateConfigCallbackParam) => {},
812
- // onInit // etc
813
- computePreventStateChange: ({ state, previousState }) => {
814
- const prevent = isEqual(state, previousState);
815
-
816
- return prevent;
799
+ callbacks: {
800
+ // onSubscribed: (StateConfigCallbackParam) => {},
801
+ // onInit // etc
802
+ computePreventStateChange: ({ state, previousState }) => {
803
+ const prevent = isEqual(state, previousState);
804
+
805
+ return prevent;
806
+ },
817
807
  },
818
808
  }
819
809
  );
820
810
  ```
821
811
 
822
- Finally, if you have a very specific necessity but still want to use the global hooks, you can extend the **GlobalStoreAbstract** class. This will give you even more control over the state and the lifecycle of the global state.
812
+ Finally, if you have a very specific necessity but still want to use the global hooks, you can extend the **GlobalStoreAbstract** class.
823
813
 
824
814
  Let's see an example again with the **asyncStorage** custom global hook but with the abstract class.
825
815
 
826
816
  ```ts
827
817
  export class GlobalStore<
828
- TState,
829
- TMetadata extends {
830
- asyncStorageKey?: string;
818
+ State,
819
+ Metadata extends {
831
820
  isAsyncStorageReady?: boolean;
832
- } | null = null,
833
- TStateMutator extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>
834
- > extends GlobalStoreAbstract<TState, TMetadata, TStateMutator> {
821
+ },
822
+ ActionsConfig extends ActionCollectionConfig<State, Metadata> | unknown
823
+ > extends GlobalStoreAbstract<State, Metadata, ActionsConfig> {
824
+ public asyncStorageKey?: string;
825
+
835
826
  constructor(
836
- state: TState,
837
- config: GlobalStoreConfig<TState, TMetadata, TStateMutator> = {},
838
- actionsConfig: TStateMutator | null = null
827
+ state: State,
828
+ args: {
829
+ metadata?: Metadata;
830
+ callbacks?: GlobalStoreCallbacks<State, Metadata>;
831
+ actions?: ActionsConfig;
832
+ name?: string;
833
+ asyncStorageKey?: string;
834
+ } = {}
839
835
  ) {
840
- super(state, config, actionsConfig);
841
-
836
+ super(state, args);
837
+ this.asyncStorageKey = args.asyncStorageKey;
842
838
  this.initialize();
843
839
  }
844
840
 
845
841
  protected onInitialize = async ({
846
842
  setState,
847
843
  setMetadata,
848
- getMetadata,
849
844
  getState,
850
- }: StateConfigCallbackParam<TState, TMetadata, TStateMutator>) => {
851
- setMetadata({
852
- ...(metadata ?? {}),
853
- isAsyncStorageReady: null,
854
- });
855
-
856
- const metadata = getMetadata();
857
- const asyncStorageKey = metadata?.asyncStorageKey;
845
+ }: StoreTools<State, Metadata>) => {
846
+ if (!this.asyncStorageKey) return;
858
847
 
859
- if (!asyncStorageKey) return;
848
+ const storedItem = (await asyncStorage.getItem(this.asyncStorageKey)) as string | null;
860
849
 
861
- const storedItem = (await asyncStorage.getItem(asyncStorageKey)) as string;
862
- setMetadata({
850
+ setMetadata((metadata) => {
863
851
  ...metadata,
864
852
  isAsyncStorageReady: true,
865
853
  });
@@ -871,19 +859,15 @@ export class GlobalStore<
871
859
  return setState(state, { forceUpdate: true });
872
860
  }
873
861
 
874
- const items = formatFromStore<TState>(storedItem, {
862
+ const items = formatFromStore<State>(storedItem, {
875
863
  jsonParse: true,
876
864
  });
877
865
 
878
866
  setState(items, { forceUpdate: true });
879
867
  };
880
868
 
881
- protected onChange = ({
882
- getMetadata,
883
- getState,
884
- }: StateChangesParam<TState, TMetadata, NonNullable<TStateMutator>>) => {
885
- const asyncStorageKey = getMetadata()?.asyncStorageKey;
886
-
869
+ protected onChange = ({ getState }: StoreTools<State, Metadata> & StateChanges<State>) => {
870
+ const asyncStorageKey = this.asyncStorageKey;
887
871
  if (!asyncStorageKey) return;
888
872
 
889
873
  const state = getState();
@@ -900,17 +884,16 @@ export class GlobalStore<
900
884
  Then, from an instance of the global store, you will be able to access the hooks.
901
885
 
902
886
  ```ts
903
- const storage = new GlobalStore(0, {
904
- metadata: {
887
+ const useCount = new GlobalStore(1, {
888
+ config: {
905
889
  asyncStorageKey: 'counter',
906
- isAsyncStorageReady: false,
907
890
  },
908
- });
891
+ }).getHook();
909
892
 
910
- const [getState, _, getMetadata] = storage.stateControls();
911
- const useState = storage.getHook();
912
- ```
893
+ const [stateRetriever, stateMutator, getMetadata] = useCount.stateControls();
913
894
 
914
- ### **Note**: The GlobalStore class is still available in the package in case you were already extending from it.
895
+ // into a component
896
+ const [state, setState, { isAsyncStorageReady }] = useCount();
897
+ ```
915
898
 
916
899
  # That's it for now!! hope you enjoy coding!!
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "react-hooks-global-states",
3
- "version": "5.0.0",
3
+ "version": "6.0.0",
4
4
  "description": "This is a package to easily handling global-state across your react-components No-redux",
5
- "main": "lib/bundle.js",
6
- "types": "lib/src/index.d.ts",
5
+ "main": "./bundle.js",
6
+ "types": "./index.d.ts",
7
+ "sideEffects": false,
7
8
  "files": [
8
- "lib"
9
+ "./*.js",
10
+ "./*.d.ts"
9
11
  ],
10
12
  "scripts": {
11
13
  "test:debug": "node --inspect-brk node_modules/.bin/jest --watch --runInBand",
@@ -16,7 +18,8 @@
16
18
  "version": "npm run format && git add -A src",
17
19
  "postversion": "git push && git push --tags",
18
20
  "lint": "eslint src --ext .js,.jsx,.ts,.tsx --max-warnings=0",
19
- "lint:fix": "eslint --fix src --ext .js,.jsx,.ts,.tsx --max-warnings=0"
21
+ "lint:fix": "eslint --fix src --ext .js,.jsx,.ts,.tsx --max-warnings=0",
22
+ "clean": "find . -maxdepth 1 -type f \\( -name '*.js' -o -name '*.d.ts' \\) ! -name 'webpack.config.js' -exec rm {} +"
20
23
  },
21
24
  "repository": {
22
25
  "type": "git",
@@ -80,6 +83,6 @@
80
83
  }
81
84
  },
82
85
  "dependencies": {
83
- "json-storage-formatter": "^1.1.2"
86
+ "json-storage-formatter": "^2.0.5"
84
87
  }
85
88
  }
package/lib/bundle.js DELETED
@@ -1,2 +0,0 @@
1
- /*! For license information please see bundle.js.LICENSE.txt */
2
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports["react-hooks-global-states"]=e(require("react")):t["react-hooks-global-states"]=e(t.react)}(this,(t=>{return e={852:(t,e,r)=>{"use strict";function n(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,l=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(u.push(n.value),u.length!==e);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(t,e)||function(t,e){if(t){if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}Object.defineProperty(e,"__esModule",{value:!0}),e.combineRetrieverAsynchronously=e.combineRetrieverEmitterAsynchronously=void 0;var i=r(608),a=r(156);e.combineRetrieverEmitterAsynchronously=function(t){for(var e,r,n,o=arguments.length,a=new Array(o>1?o-1:0),u=1;u<o;u++)a[u-1]=arguments[u];var c=a,l=new Map(c.map((function(t,e){return[e,t()]}))),s=t.selector(Array.from(l.values())),f=void 0!==(null===(e=null==t?void 0:t.config)||void 0===e?void 0:e.isEqual)?null===(r=null==t?void 0:t.config)||void 0===r?void 0:r.isEqual:i.shallowCompare,v=new Set,d=(0,i.debounce)((function(){var e=t.selector(Array.from(l.values()));(null==f?void 0:f(s,e))||(s=e,v.forEach((function(t){return t()})))}),null===(n=null==t?void 0:t.config)||void 0===n?void 0:n.delay),p=c.map((function(t,e){return t((function(t){l.set(e,t),d()}))})),y=function(t,e,r){var n,o,a="function"==typeof e,u=a?t:null,c=a?e:t,l=a?r:e,f=Object.assign({delay:0,isEqual:i.shallowCompare},null!=l?l:{}),d=null!==(n=null==u?void 0:u(s))&&void 0!==n?n:s;f.skipFirst||c(d);var p=(0,i.debounce)((function(){var t,e,r=null!==(t=null==u?void 0:u(s))&&void 0!==t?t:s;(null===(e=f.isEqual)||void 0===e?void 0:e.call(f,d,r))||(d=r,c(r))}),null!==(o=f.delay)&&void 0!==o?o:0);return v.add(p),function(){v.delete(p)}};return[y,function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return e[0]?y.apply(void 0,e):s},function(){p.forEach((function(t){return t()}))}]},e.combineRetrieverAsynchronously=function(t){for(var r=arguments.length,o=new Array(r>1?r-1:0),u=1;u<r;u++)o[u-1]=arguments[u];var c=n(e.combineRetrieverEmitterAsynchronously.apply(void 0,[t].concat(o)),3),l=c[0],s=c[1],f=c[2];return[function(t,e){var r=n((0,a.useState)((function(){var e=s();return t?t(e):e})),2),o=r[0],u=r[1];return(0,a.useEffect)((function(){var r,n=Object.assign({delay:0,isEqual:i.shallowCompare},null!=e?e:{}),o=void 0!==n.isEqual?n.isEqual:i.shallowCompare,a=l((function(e){return t?t(e):e}),(0,i.debounce)((function(e){var r=t?t(e):e;(null==o?void 0:o(e,r))||u(r)}),null!==(r=n.delay)&&void 0!==r?r:0));return function(){a()}}),[]),[o,null,null]},s,f]}},113:(t,e,r)=>{"use strict";var n=Object.create?function(t,e,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]},o=Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e};Object.defineProperty(e,"__esModule",{value:!0}),e.createContext=void 0;var i=r(608),a=r(774),u=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)"default"!==r&&Object.prototype.hasOwnProperty.call(t,r)&&n(e,t,r);return o(e,t),e}(r(156)),c=r(684);e.createContext=function(t,e){var r=new Map,n=u.default.createContext(i.uniqueSymbol),o=function(){var t=u.default.useContext(n);if(t===i.uniqueSymbol)throw new Error("context hooks need to be used inside a provider");return t};return o.createSelectorHook=function(t,e){var n=(0,i.uniqueId)("cs:");return function(){var i,a,u=o(),l=(i=u,null!==(a=r.get(i))&&void 0!==a?a:r.set(i,new Map).get(i));l.has(n)||l.set(n,u.createSelectorHook(t,e));var s=l.get(n);if((0,c.isNil)(s))throw new Error("useSelectedHook is nil");return s.apply(void 0,arguments)}},[o,function(o){var i=o.children,l=o.value,s=o.ref,f=(0,u.useMemo)((function(){var r=void 0===l?t():(0,c.isFunction)(l)?l(t()):l,n=new a.GlobalStore(r,e);return{store:n,hook:n.getHook()}}),[]),v=f.store,d=f.hook;return r.has(d)||r.set(d,new Map),(0,u.useEffect)((function(){return function(){var t,e,n,o;r.delete(d),null===(e=null===(t=v.callbacks)||void 0===t?void 0:t.onUnMount)||void 0===e||e.call(t),null===(o=(n=v).__onUnMountContext)||void 0===o||o.call(n,v,d)}}),[]),(0,u.useImperativeHandle)(s,(function(){return s?v.getConfigCallbackParam():{}}),[v,s]),u.default.createElement(n.Provider,{value:d},i)}]}},853:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createCustomGlobalState=e.createGlobalState=void 0;var n=r(774);e.createGlobalState=function(t,e){return new n.GlobalStore(t,e).getHook()},e.createCustomGlobalState=function(t){var r=t.onInitialize,n=t.onChange;return function(t,o){return(0,e.createGlobalState)(t,{callbacks:Object.assign(Object.assign({},null==o?void 0:o.callbacks),{onInit:function(t){var e,n;null==r||r(t,null==o?void 0:o.config),null===(n=null===(e=null==o?void 0:o.callbacks)||void 0===e?void 0:e.onInit)||void 0===n||n.call(e,t)},onStateChanged:function(t){var e,r;null==n||n(t,null==o?void 0:o.config),null===(r=null===(e=null==o?void 0:o.callbacks)||void 0===e?void 0:e.onStateChanged)||void 0===r||r.call(e,t)}})})}}},774:(t,e,r)=>{"use strict";function n(t){return n="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},n(t)}function o(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,l=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(u.push(n.value),u.length!==e);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(t,e)||i(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t,e){if(t){if("string"==typeof t)return a(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(t,e):void 0}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function u(){u=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",l=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var i=e&&e.prototype instanceof p?e:p,a=Object.create(i.prototype),u=new C(n||[]);return o(a,"_invoke",{value:j(t,r,u)}),a}function v(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=f;var d={};function p(){}function y(){}function b(){}var h={};s(h,a,(function(){return this}));var m=Object.getPrototypeOf,g=m&&m(m(k([])));g&&g!==e&&r.call(g,a)&&(h=g);var S=b.prototype=p.prototype=Object.create(h);function w(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function i(o,a,u,c){var l=v(t[o],t,a);if("throw"!==l.type){var s=l.arg,f=s.value;return f&&"object"==n(f)&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){i("next",t,u,c)}),(function(t){i("throw",t,u,c)})):e.resolve(f).then((function(t){s.value=t,u(s)}),(function(t){return i("throw",t,u,c)}))}c(l.arg)}var a;o(this,"_invoke",{value:function(t,r){function n(){return new e((function(e,n){i(t,r,e,n)}))}return a=a?a.then(n,n):n()}})}function j(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=E(a,r);if(u){if(u===d)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=v(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===d)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function E(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,E(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),d;var o=v(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,d;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,d):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function x(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function A(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function C(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function k(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:_}}function _(){return{value:void 0,done:!0}}return y.prototype=b,o(S,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:y,configurable:!0}),y.displayName=s(b,l,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,s(t,l,"GeneratorFunction")),t.prototype=Object.create(S),t},t.awrap=function(t){return{__await:t}},w(O.prototype),s(O.prototype,c,(function(){return this})),t.AsyncIterator=O,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new O(f(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(S),s(S,l,"Generator"),s(S,a,(function(){return this})),s(S,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=k,C.prototype={constructor:C,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(A),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),A(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;A(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:k(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),d}},t}function c(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,l(n.key),n)}}function l(t){var e=function(t,e){if("object"!==n(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,"string");if("object"!==n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===n(e)?e:String(e)}Object.defineProperty(e,"__esModule",{value:!0}),e.GlobalStore=void 0;var s=r(608),f=r(156),v=r(684),d=function(){function t(e){var r=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{metadata:{}};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.actionsConfig=null,this.callbacks=null,this.actions=null,this.subscribers=new Map,this.initialize=function(){return t=r,e=void 0,n=void 0,o=u().mark((function t(){var e,r,n,o,i,a;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(Object.keys(null!==(e=this.actionsConfig)&&void 0!==e?e:{}).length>0&&(this.actions=this.getStoreActionsMap()),n=this.onInit,o=null!==(r=this.callbacks)&&void 0!==r?r:{},i=o.onInit,n||i){t.next=6;break}return t.abrupt("return");case 6:a=this.getConfigCallbackParam(),null==n||n(a),(0,v.isNil)(i)||null==i||i(a);case 9:case"end":return t.stop()}}),t,this)})),new(n||(n=Promise))((function(r,i){function a(t){try{c(o.next(t))}catch(t){i(t)}}function u(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}c((o=o.apply(t,e||[])).next())}));var t,e,n,o},this.executeSetStateForSubscriber=function(t,e){var n,o,i=t.selector,a=t.callback,u=t.currentState,c=t.config;if(!e.forceUpdate&&(null!==(n=null==c?void 0:c.isEqualRoot)&&void 0!==n?n:function(t,e){return t===e})(e.currentRootState,e.newRootState))return{didUpdate:!1};var l=i?i(e.newRootState):e.newRootState;return!e.forceUpdate&&(null!==(o=null==c?void 0:c.isEqual)&&void 0!==o?o:function(t,e){return t===e})(u,l)?{didUpdate:!1}:(r.partialUpdateSubscription(t.subscriptionId,{currentState:l}),a({state:l},{identifier:e.identifier}),{didUpdate:!0})},this.setState=function(t,e){var n=t.state,o=e.forceUpdate,a=e.identifier,u=r.stateWrapper.state;if(o||u!==n){r.stateWrapper={state:n};var c,l={forceUpdate:o,newRootState:n,currentRootState:u,identifier:a},s=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=i(t))){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,u=!0,c=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return u=t.done,t},e:function(t){c=!0,a=t},f:function(){try{u||null==r.return||r.return()}finally{if(c)throw a}}}}(r.subscribers.values());try{for(s.s();!(c=s.n()).done;){var f=c.value;r.executeSetStateForSubscriber(f,l)}}catch(t){s.e(t)}finally{s.f()}}},this.setMetadata=function(t){var e=(0,v.isFunction)(t)?t(r.metadata):t;r.metadata=e},this.getMetadata=function(){return r.metadata},this.getState=function(t,e,n){var o;if(!t)return r.stateWrapper.state;var i=(0,v.isFunction)(e),a=i?t:void 0,u=i?e:t,c=null!==(o=i?n:e)&&void 0!==o?o:void 0,l=a?a(r.stateWrapper.state):r.stateWrapper.state;(null==c?void 0:c.skipFirst)||u(l);var f=(0,s.uniqueId)("gs:");return r.setOrUpdateSubscription({subscriptionId:f,selector:a,config:c,currentState:l,callback:function(t){var e=t.state;return u(e)},isSetStateCallback:!1}),function(){r.subscribers.delete(f)}},this.getConfigCallbackParam=function(){var t=r.setMetadata,e=r.getMetadata,n=r.getState,o=r.actions;return{setMetadata:t,getMetadata:e,getState:n,setState:r.setStateWrapper,actions:o}},this.lastSubscriptionId=null,this.setOrUpdateSubscription=function(t){var e=t.subscriptionId;if(!e)return{isNewSubscription:!1};var n=r.subscribers.get(e);return(0,s.isRecord)(n)?(Object.assign(n,t),{isNewSubscription:!1}):(r.executeOnSubscribed(),r.subscribers.set(e,t),r.lastSubscriptionId=e,{isNewSubscription:!0})},this.partialUpdateSubscription=function(t,e){var n=r.subscribers.get(t);(0,s.isRecord)(n)&&Object.assign(n,e)},this.executeOnSubscribed=function(){var t,e=r.onSubscribed,n=null===(t=r.callbacks)||void 0===t?void 0:t.onSubscribed;if(e||n){var o=r.getConfigCallbackParam();null==e||e(o),null==n||n(o)}},this.getHook=function(){var t=function(t){var e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=(0,s.useConstantValueRef)((function(){return{subscriptionId:null,tempInitialRootState:r.stateWrapper.state}})),a=function(){return t?{state:t(r.stateWrapper.state)}:r.stateWrapper},u=o((0,f.useState)(a),2),c=u[0],l=u[1];(0,f.useEffect)((function(){if(!(0,v.isNil)(i.current)){(0,v.isNil)(i.current.subscriptionId)&&(i.current.subscriptionId=(0,s.uniqueId)("ss:"));var e=i.current.subscriptionId,o={subscriptionId:e,currentState:c.state,selector:t,config:n,callback:l,isSetStateCallback:!0};return r.setOrUpdateSubscription(o).isNewSubscription&&(r.executeSetStateForSubscriber(o,{forceUpdate:!1,newRootState:r.stateWrapper.state,currentRootState:i.current.tempInitialRootState,identifier:"on mount state update"}),i.current.tempInitialRootState=s.uniqueSymbol),function(){r.subscribers.delete(e)}}}),[]);var d=(0,v.isString)(i.current)?i.current:"",p=r.subscribers.get(d),y=(null!==(e=null==p?void 0:p.config)&&void 0!==e?e:{dependencies:n.dependencies}).dependencies;return r.partialUpdateSubscription(d,{currentState:c.state,selector:t,config:n,callback:l}),[r.computeSelectedState({selector:t,subscriptionId:d,config:n,currentDependencies:y,computeChildState:a,stateWrapperRef:c}),r.getStateOrchestrator(),r.metadata]};return t.stateControls=r.stateControls,t.createSelectorHook=r.createSelectorHook,t.createObservable=r.createObservable,t},this.computeSelectedState=function(t){var e=t.selector,n=t.subscriptionId,o=t.config,i=t.currentDependencies,a=t.computeChildState,u=t.stateWrapperRef;if(!e||!n)return u.state;var c=o.dependencies;if(i===c)return u.state;if((null==i?void 0:i.length)===(null==c?void 0:c.length)&&(0,s.shallowCompare)(i,c))return u.state;var l=a().state;return r.partialUpdateSubscription(n,{currentState:l}),u.state=l,l},this.createSelectorHook=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=n.isEqualRoot,a=n.isEqual,u=n.name,c=o(r.stateControls(),3),l=c[0],f=c[1],d=c[2],p=l(),y=(null!=e?e:function(t){return t})(p),b=new t(y,{name:null!=u?u:(0,s.uniqueId)("sh:")}),h=o(b.stateControls(),2),m=h[0],g=h[1];l((function(t){if(!(null!=i?i:Object.is)(p,t)){p=t;var r=e(t);(null!=a?a:Object.is)(y,r)||(y=r,g(r))}}),{skipFirst:!0});var S=b.getHook(),w=function(t,e){return[o((0,v.isFunction)(t)?S(t,e):S(),1)[0],f,d]};return w.stateControls=function(){return[m,f,d]},w.createSelectorHook=r.createSelectorHook.bind(w),w.createObservable=r.createObservable.bind(w),w},this.stateControls=function(){var t=r.getStateOrchestrator(),e=r.getMetadata;return[r.getState,t,e]},this.getStateOrchestrator=function(){return r.actions?r.actions:r.setStateWrapper},this.setStateWrapper=function(t){var e,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=o.forceUpdate,a=o.identifier,u=r.stateWrapper.state,c=(0,v.isFunction)(t)?t(u):t;if(i||r.stateWrapper.state!==c){var l=r.setMetadata,s=r.getMetadata,f=r.getState,d=r.actions,p={setMetadata:l,getMetadata:s,setState:r.setState,getState:f,actions:d,previousState:u,state:c,identifier:a},y=r.computePreventStateChange,b=null===(e=r.callbacks)||void 0===e?void 0:e.computePreventStateChange;if((y||b)&&((null==y?void 0:y(p))||(null==b?void 0:b(p))))return;r.setState({state:c},{forceUpdate:i,identifier:a});var h=r.onStateChanged,m=null===(n=r.callbacks)||void 0===n?void 0:n.onStateChanged;(h||m)&&(null==h||h(p),null==m||m(p))}},this.getStoreActionsMap=function(){if(!(0,s.isRecord)(r.actionsConfig))return null;var t=r.actionsConfig,e=r.setMetadata,n=r.setStateWrapper,o=r.getState,i=r.getMetadata,a=Object.keys(t).reduce((function(r,u){var c,f,v;return Object.assign(r,(c={},v=function(){for(var r=t[u],c=arguments.length,l=new Array(c),f=0;f<c;f++)l[f]=arguments[f];var v=r.apply(a,l);return"function"!=typeof v&&(0,s.throwWrongKeyOnActionCollectionConfig)(u),v.call(a,{setState:n,getState:o,setMetadata:e,getMetadata:i,actions:a})},(f=l(f=u))in c?Object.defineProperty(c,f,{value:v,enumerable:!0,configurable:!0,writable:!0}):c[f]=v,c)),r}),{});return a};var a=n.metadata,c=n.callbacks,d=n.actions,p=n.name;this.stateWrapper={state:e},this._name=null!=p?p:(0,s.uniqueId)("gs:"),this.metadata=null!=a?a:{},this.callbacks=null!=c?c:null,this.actionsConfig=null!=d?d:null,(null===globalThis||void 0===globalThis?void 0:globalThis.REACT_GLOBAL_STATE_HOOK_DEBUG)&&globalThis.REACT_GLOBAL_STATE_HOOK_DEBUG(this),this.constructor!==t||this.initialize()}var e,r;return e=t,r=[{key:"createObservable",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.isEqualRoot,n=e.isEqual,i=e.name,a=o(this.stateControls(),1)[0],u=[],c=a(),l=(null!=t?t:function(t){return t})(a());a((function(e){if(!(null!=r?r:Object.is)(c,e)){c=e;var o=t(e);(null!=n?n:Object.is)(l,o)||(l=o,u.forEach((function(t){return t()})))}}),{skipFirst:!0});var f=function(t,e,r){var n;if(!t)return l;var o=(0,v.isFunction)(e),i=o?t:void 0,a=o?e:t,c=null!==(n=o?r:e)&&void 0!==n?n:void 0,s=function(){return a(i?i(l):l)};(null==c?void 0:c.skipFirst)||s();var f=function(){s()};return u.push(f),function(){u.splice(u.indexOf(f),1)}};return f._name=null!=i?i:(0,s.uniqueId)("ob:"),f.createObservable=this.createObservable.bind(f),f.stateControls=function(){return[f]},f}}],r&&c(e.prototype,r),Object.defineProperty(e,"prototype",{writable:!1}),t}();e.GlobalStore=d},530:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0})},608:(t,e,r)=>{"use strict";function n(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,l=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(u.push(n.value),u.length!==e);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(t,e)||i(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=i(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,u=!0,c=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return u=t.done,t},e:function(t){c=!0,a=t},f:function(){try{u||null==r.return||r.return()}finally{if(c)throw a}}}}function i(t,e){if(t){if("string"==typeof t)return a(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(t,e):void 0}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function u(t){return u="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},u(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.useConstantValueRef=e.uniqueSymbol=e.isRecord=e.throwWrongKeyOnActionCollectionConfig=e.uniqueId=e.debounce=e.shallowCompare=void 0;var c,l=r(684),s=r(156);e.shallowCompare=function(t,r){if(t===r)return!0;var i=u(t),a=u(r);if(i!==a)return!1;if((0,l.isNil)(t)||(0,l.isNil)(r)||(0,l.isPrimitive)(t)&&(0,l.isPrimitive)(r)||(0,l.isDate)(t)&&(0,l.isDate)(r)||"function"===i&&"function"===a)return t===r;if(Array.isArray(t)){var c=t,s=r;if(c.length!==s.length)return!1;for(var f=0;f<c.length;f++)if(c[f]!==s[f])return!1}if(t instanceof Map){var v=t,d=r;if(v.size!==d.size)return!1;var p,y=o(v);try{for(y.s();!(p=y.n()).done;){var b=n(p.value,2),h=b[0];if(b[1]!==d.get(h))return!1}}catch(t){y.e(t)}finally{y.f()}}if(t instanceof Set){var m=t,g=r;if(m.size!==g.size)return!1;var S,w=o(m);try{for(w.s();!(S=w.n()).done;){var O=S.value;if(!g.has(O))return!1}}catch(t){w.e(t)}finally{w.f()}}if(!(0,e.isRecord)(t)||!(0,e.isRecord)(r))return t===r;var j=Object.keys(t),E=Object.keys(r);if(j.length!==E.length)return!1;for(var x=0,A=j;x<A.length;x++){var C=A[x];if(t[C]!==r[C])return!1}return!0},e.debounce=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return function(){for(var n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];e&&clearTimeout(e),e=setTimeout((function(){t.apply(void 0,o)}),r)}},e.uniqueId=(c=0,function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return c===Number.MAX_SAFE_INTEGER&&(c=0),t+Date.now().toString(36)+(c++).toString(36)}),e.throwWrongKeyOnActionCollectionConfig=function(t){throw new Error("[WRONG CONFIGURATION!]: Every key inside the storeActionsConfig must be a higher order function that returns a function \n[".concat(t,"]: key is not a valid function, try something like this: \n{\n\n ").concat(t,": (param) => ({ setState, getState, setMetadata, getMetadata, actions }) => {\n\n setState((state) => ({ ...state, ...param }))\n\n }\n\n}\n"))},e.isRecord=function(t){return!(0,l.isNil)(t)&&"object"===u(t)},e.uniqueSymbol=Symbol("unique"),e.useConstantValueRef=function(t){var r=(0,s.useRef)(e.uniqueSymbol);return r.current===e.uniqueSymbol&&(r.current=t()),r}},195:(t,e,r)=>{"use strict";function n(t){return n="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},n(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.GlobalStoreAbstract=void 0;var a=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)}(c,t);var e,r,a,u=(r=c,a=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=i(r);if(a){var o=i(this).constructor;t=Reflect.construct(e,arguments,o)}else t=e.apply(this,arguments);return function(t,e){if(e&&("object"===n(e)||"function"==typeof e))return e;if(void 0!==e)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)}(this,t)});function c(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,c),(t=u.apply(this,arguments)).onInit=function(e){t.onInitialize(e)},t.onStateChanged=function(e){t.onChange(e)},t}return e=c,Object.defineProperty(e,"prototype",{writable:!1}),e}(r(774).GlobalStore);e.GlobalStoreAbstract=a},991:(t,e,r)=>{"use strict";var n=Object.create?function(t,e,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]},o=function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),o(r(684),e),o(r(530),e),o(r(774),e),o(r(195),e),o(r(853),e),o(r(608),e),o(r(852),e),o(r(113),e)},684:function(t){t.exports=(()=>{"use strict";var t={124:(t,e,r)=>{var n=Object.create?function(t,e,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]};Object.defineProperty(e,"__esModule",{value:!0}),function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)}(r(331),e)},331:(t,e)=>{function r(t){return r="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},r(t)}function n(t,e,n){return(e=function(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function o(t,e){if(t){if("string"==typeof t)return i(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(t,e):void 0}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}Object.defineProperty(e,"__esModule",{value:!0}),e.formatToStore=e.formatFromStore=e.isPrimitive=e.isFunction=e.isRegex=e.isDate=e.isString=e.isBoolean=e.isNumber=e.isNil=e.clone=void 0,e.clone=function(t){var r,a=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).shallow;if((0,e.isPrimitive)(t)||(0,e.isDate)(t))return t;if(Array.isArray(t))return a?function(t){if(Array.isArray(t))return i(t)}(r=t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(r)||o(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}():t.map((function(t){return(0,e.clone)(t)}));if(t instanceof Map){var u=Array.from(t.entries());return a?new Map(u):new Map(u.map((function(t){return(0,e.clone)(t)})))}if(t instanceof Set){var c=Array.from(t.values());return a?new Set(c):new Set(c.map((function(t){return(0,e.clone)(t)})))}return t instanceof RegExp?new RegExp(t.toString()):(0,e.isFunction)(t)?a?t:Object.create(t):a?Object.assign({},t):t instanceof Error?new Error(t.message):Object.keys(t).reduce((function(r,o){var i=t[o];return Object.assign(Object.assign({},r),n({},o,(0,e.clone)(i)))}),{})},e.isNil=function(t){return null==t},e.isNumber=function(t){return"number"==typeof t},e.isBoolean=function(t){return"boolean"==typeof t},e.isString=function(t){return"string"==typeof t},e.isDate=function(t){return t instanceof Date},e.isRegex=function(t){return t instanceof RegExp},e.isFunction=function(t){return"function"==typeof t||t instanceof Function},e.isPrimitive=function(t){return(0,e.isNil)(t)||(0,e.isNumber)(t)||(0,e.isBoolean)(t)||(0,e.isString)(t)||"symbol"===r(t)},e.formatFromStore=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=r.jsonParse,a=r.sortKeys;return function(t){var r,i,u;if((0,e.isPrimitive)(t))return t;if("date"===(null==t?void 0:t.$t))return new Date(t.$v);if("map"===(null==t?void 0:t.$t)){var c=(null!==(r=t.$v)&&void 0!==r?r:[]).map((function(t){var r,n=(2,function(t){if(Array.isArray(t))return t}(r=t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,l=!1;try{for(i=(r=r.call(t)).next,0;!(c=(n=i.call(r)).done)&&(u.push(n.value),2!==u.length);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(r)||o(r,2)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),i=n[0],a=n[1];return[i,(0,e.formatFromStore)(a)]}));return new Map(c)}if("set"===(null==t?void 0:t.$t)){var l=null!==(i=t.$v)&&void 0!==i?i:[].map((function(t){return(0,e.formatFromStore)(t)}));return new Set(l)}return"regex"===(null==t?void 0:t.$t)?new RegExp(t.$v):"error"===(null==t?void 0:t.$t)?new Error(t.$v):Array.isArray(t)?t.map((function(t){return(0,e.formatFromStore)(t)})):"function"===(null==t?void 0:t.$t)?Function("(".concat(t.$v,")(...arguments)")):(u=Object.keys(t),a?(0,e.isFunction)(a)?u.sort(a):u.sort((function(t,e){return(null!=t?t:"").localeCompare(e)})):u).reduce((function(r,o){var i=t[o];return Object.assign(Object.assign({},r),n({},o,(0,e.formatFromStore)(i)))}),{})}(i?JSON.parse(t):(0,e.clone)(t))},e.formatToStore=function(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{stringify:!1},i=o.stringify,a=o.validator,u=o.excludeTypes,c=o.excludeKeys,l=o.sortKeys,s=new Set(null!=u?u:[]),f=new Set(null!=c?c:[]),v=s.size||f.size,d=null!=a?a:function(t){var e=t.key,n=t.value;if(!v)return!0;var o=f.has(e),i=s.has(r(n));return!o&&!i},p=function(t){if((0,e.isPrimitive)(t))return t;var r;if(Array.isArray(t))return t.map((function(t){return p(t)}));if(t instanceof Map)return{$t:"map",$v:Array.from(t.entries()).map((function(t){return p(t)}))};if(t instanceof Set)return{$t:"set",$v:Array.from(t.values()).map((function(t){return p(t)}))};if((0,e.isDate)(t))return{$t:"date",$v:t.toISOString()};if((0,e.isRegex)(t))return{$t:"regex",$v:t.toString()};if((0,e.isFunction)(t)){var o;try{o={$t:"function",$v:t.toString()}}catch(t){o={$t:"error",$v:"Error: Could not serialize function"}}return o}return t instanceof Error?{$t:"error",$v:t.message}:(r=Object.keys(t),l?(0,e.isFunction)(l)?r.sort(l):r.sort((function(t,e){return(null!=t?t:"").localeCompare(e)})):r).reduce((function(e,r){var o=t[r],i=p(o);return d({obj:t,key:r,value:i})?Object.assign(Object.assign({},e),n({},r,p(o))):e}),{})},y=p((0,e.clone)(t));return i?JSON.stringify(y):y}}},e={};return function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}(124)})()},156:e=>{"use strict";e.exports=t}},r={},function t(n){var o=r[n];if(void 0!==o)return o.exports;var i=r[n]={exports:{}};return e[n].call(i.exports,i,i.exports,t),i.exports}(991);var e,r}));
@@ -1 +0,0 @@
1
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
@@ -1,27 +0,0 @@
1
- import { StateGetter, UnsubscribeCallback, SelectorCallback, UseHookConfig, StateHook, BaseMetadata } from './GlobalStore.types';
2
- /**
3
- * @description
4
- * This function allows you to create a derivate state by merging the state of multiple hooks.
5
- * The update of the derivate state is debounced to avoid unnecessary re-renders.
6
- * By default, the debounce delay is 0, but you can change it by passing a delay in milliseconds as the third parameter.
7
- * @returns a tuple with the following elements: [subscribe, getState, dispose]
8
- */
9
- export declare const combineRetrieverEmitterAsynchronously: <TDerivate, TArguments extends StateGetter<unknown>[], TResults = { [K in keyof TArguments]: TArguments[K] extends () => infer TResult ? Exclude<TResult, UnsubscribeCallback> : never; }>(parameters: {
10
- selector: SelectorCallback<TResults, TDerivate>;
11
- config?: (UseHookConfig<TDerivate> & {
12
- delay?: number | undefined;
13
- }) | undefined;
14
- }, ...args: TArguments) => [subscribe: StateGetter<TDerivate>, getState: StateGetter<unknown>, dispose: UnsubscribeCallback];
15
- /**
16
- * @description
17
- * This function allows you to create a derivate state by merging the state of multiple hooks.
18
- * The update of the derivate state is debounced to avoid unnecessary re-renders.
19
- * By default, the debounce delay is 0, but you can change it by passing a delay in milliseconds as the third parameter.
20
- * @returns A tuple containing the subscribe function, the state getter and the dispose function
21
- */
22
- export declare const combineRetrieverAsynchronously: <TDerivate, TArguments extends readonly StateGetter<unknown>[], TResults = { [K in keyof TArguments]: TArguments[K] extends StateGetter<infer R> ? R : never; }>(parameters: {
23
- selector: SelectorCallback<TResults, TDerivate>;
24
- config?: (UseHookConfig<TDerivate> & {
25
- delay?: number | undefined;
26
- }) | undefined;
27
- }, ...args: TArguments) => [useHook: StateHook<TDerivate, null, BaseMetadata>, getState: StateGetter<TDerivate>, dispose: UnsubscribeCallback];
@@ -1,50 +0,0 @@
1
- import { ActionCollectionConfig, StateHook, StateSetter, ActionCollectionResult, StateGetter, BaseMetadata, MetadataSetter, GlobalStoreCallbacks } from './GlobalStore.types';
2
- import React, { PropsWithChildren } from 'react';
3
- export type ContextProviderAPI<Value, Metadata extends BaseMetadata | unknown> = {
4
- setMetadata: MetadataSetter<Metadata>;
5
- setState: StateSetter<Value>;
6
- getState: StateGetter<Value>;
7
- getMetadata: () => Metadata;
8
- actions: Record<string, (...args: any[]) => void>;
9
- };
10
- export type ContextProvider<Value, Metadata extends BaseMetadata | unknown> = React.FC<PropsWithChildren<{
11
- value?: Value | ((initialValue: Value) => Value);
12
- ref?: React.RefObject<ContextProviderAPI<Value, Metadata>>;
13
- }>>;
14
- export type ContextHook<Value, PublicStateMutator, Metadata extends BaseMetadata | unknown> = (() => StateHook<Value, PublicStateMutator, Metadata>) & {
15
- createSelectorHook: <RootState, RootSelectorResult, RootDerivate = RootSelectorResult extends never ? RootState : RootSelectorResult>(this: ContextHook<RootState, PublicStateMutator, Metadata>, mainSelector?: (state: Value) => RootSelectorResult, args?: {
16
- isEqual?: (current: RootDerivate, next: RootDerivate) => boolean;
17
- isEqualRoot?: (current: RootState, next: RootState) => boolean;
18
- name?: string;
19
- }) => StateHook<RootDerivate, PublicStateMutator, Metadata>;
20
- };
21
- export interface CreateContext {
22
- <Value, Hook = ContextHook<Value, StateSetter<Value>, BaseMetadata>>(builder: () => Value): readonly [
23
- Hook,
24
- ContextProvider<Hook, BaseMetadata>
25
- ];
26
- <Value, Metadata extends BaseMetadata | unknown, Hook = ContextHook<Value, StateSetter<Value>, Metadata>>(builder: () => Value, args: {
27
- name?: string;
28
- metadata?: unknown;
29
- callbacks?: GlobalStoreCallbacks<Value, Metadata> & {
30
- onUnMount?: () => void;
31
- };
32
- }): readonly [Hook, ContextProvider<Hook, Metadata>];
33
- <Value, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<Value, Metadata>, PublicStateMutator = keyof ActionsConfig extends never | undefined ? StateSetter<Value> : ActionCollectionResult<Value, Metadata, NonNullable<ActionsConfig>>, Hook = ContextHook<Value, PublicStateMutator, Metadata>>(builder: () => Value, args: {
34
- name?: string;
35
- metadata?: unknown;
36
- callbacks?: GlobalStoreCallbacks<Value, Metadata> & {
37
- onUnMount?: () => void;
38
- };
39
- actions?: ActionCollectionConfig<Value, Metadata>;
40
- }): readonly [Hook, ContextProvider<Hook, Metadata>];
41
- <Value, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<Value, Metadata>, Hook = ContextHook<Value, ActionCollectionResult<Value, Metadata, ActionsConfig>, Metadata>>(builder: () => Value, args: {
42
- name?: string;
43
- metadata?: unknown;
44
- callbacks?: GlobalStoreCallbacks<Value, Metadata> & {
45
- onUnMount?: () => void;
46
- };
47
- actions: ActionCollectionConfig<Value, Metadata>;
48
- }): readonly [Hook, ContextProvider<Hook, Metadata>];
49
- }
50
- export declare const createContext: CreateContext;
@@ -1,113 +0,0 @@
1
- import { UniqueSymbol } from './GlobalStore.utils';
2
- import { ActionCollectionConfig, StateSetter, GlobalStoreCallbacks, ActionCollectionResult, MetadataSetter, UseHookConfig, StateGetter, SelectorCallback, SubscriberParameters, MetadataGetter, StateHook, BaseMetadata, StateChanges, StoreTools, ObservableFragment } from './GlobalStore.types';
3
- /**
4
- * The GlobalStore class is the main class of the library and it is used to create a GlobalStore instances
5
- * */
6
- export declare class GlobalStore<State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, Metadata> | undefined | unknown, PublicStateMutator = keyof ActionsConfig extends never | undefined ? StateSetter<State> : ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>> {
7
- protected _name: string;
8
- actionsConfig: ActionsConfig | null;
9
- callbacks: GlobalStoreCallbacks<State, Metadata> | null;
10
- metadata: Metadata;
11
- actions: ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>> | null;
12
- subscribers: Map<string, SubscriberParameters>;
13
- stateWrapper: {
14
- state: State;
15
- };
16
- constructor(state: State);
17
- constructor(state: State, args: {
18
- metadata?: Metadata;
19
- callbacks?: GlobalStoreCallbacks<State, Metadata>;
20
- actions?: ActionsConfig;
21
- name?: string;
22
- });
23
- protected onInit?: (args: StoreTools<State, Metadata>) => void;
24
- protected onStateChanged?: (args: StoreTools<State, Metadata> & StateChanges<State>) => void;
25
- protected onSubscribed?: (args: StoreTools<State, Metadata>) => void;
26
- protected computePreventStateChange?: (parameters: StoreTools<State, Metadata> & StateChanges<State>) => boolean;
27
- protected initialize: () => Promise<void>;
28
- protected executeSetStateForSubscriber: (subscription: SubscriberParameters, args: {
29
- forceUpdate: boolean | undefined;
30
- newRootState: State;
31
- currentRootState: State | UniqueSymbol;
32
- identifier: string | undefined;
33
- }) => {
34
- didUpdate: boolean;
35
- };
36
- /**
37
- * set the state and update all the subscribers
38
- * @param {StateSetter<State>} setter - The setter function or the value to set
39
- * */
40
- protected setState: ({ state: newRootState, }: {
41
- state: State;
42
- }, { forceUpdate, identifier }: {
43
- forceUpdate?: boolean | undefined;
44
- identifier?: string | undefined;
45
- }) => void;
46
- /**
47
- * Set the value of the metadata property, this is no reactive and will not trigger a re-render
48
- * @param {MetadataSetter<Metadata>} setter - The setter function or the value to set
49
- * */
50
- protected setMetadata: MetadataSetter<Metadata>;
51
- protected getMetadata: () => Metadata;
52
- getState: StateGetter<State>;
53
- /**
54
- * get the parameters object to pass to the callback functions:
55
- * onInit, onStateChanged, onSubscribed, computePreventStateChange
56
- * */
57
- getConfigCallbackParam: () => StoreTools<State, Metadata>;
58
- protected lastSubscriptionId: string | null;
59
- protected setOrUpdateSubscription: (subscription: SubscriberParameters) => {
60
- isNewSubscription?: boolean;
61
- };
62
- protected partialUpdateSubscription: (subscriptionId: string, values: Partial<SubscriberParameters>) => void;
63
- protected executeOnSubscribed: () => void;
64
- /**
65
- * Returns a custom hook that allows to handle a global state
66
- * @returns {[State, StateMutator, Metadata]} - The state, the state setter or the actions map, the metadata
67
- * */
68
- getHook: () => StateHook<State, PublicStateMutator, Metadata>;
69
- protected computeSelectedState: ({ selector, subscriptionId, config, currentDependencies, computeChildState, stateWrapperRef, }: {
70
- selector: SelectorCallback<unknown, unknown> | undefined;
71
- subscriptionId: string;
72
- config: UseHookConfig<unknown, unknown>;
73
- currentDependencies: unknown[] | undefined;
74
- computeChildState: () => {
75
- state: unknown;
76
- };
77
- stateWrapperRef: {
78
- state: unknown;
79
- };
80
- }) => unknown;
81
- /**
82
- * @description
83
- * Use this function to create a custom global hook which contains a fragment of the state of another hook
84
- */
85
- createSelectorHook: <RootState, StateMutator, Metadata_1 extends BaseMetadata, RootSelectorResult, RootDerivate = RootSelectorResult extends never ? RootState : RootSelectorResult>(mainSelector: (state: RootState) => RootSelectorResult, { isEqualRoot: mainIsEqualRoot, isEqual: mainIsEqualFun, name: selectorName, }?: {
86
- isEqual?: ((current: RootDerivate, next: RootDerivate) => boolean) | undefined;
87
- isEqualRoot?: ((current: RootState, next: RootState) => boolean) | undefined;
88
- name?: string | undefined;
89
- }) => StateHook<RootDerivate, StateMutator, Metadata_1>;
90
- stateControls: () => [retriever: StateGetter<State>, mutator: PublicStateMutator, metadata: MetadataGetter<Metadata>];
91
- /**
92
- * Returns the state setter or the actions map
93
- * @returns {StateMutator} - The state setter or the actions map
94
- * */
95
- protected getStateOrchestrator: () => PublicStateMutator;
96
- /**
97
- * This is responsible for defining whenever or not the state change should be allowed or prevented
98
- * the function also execute the functions:
99
- * - onStateChanged (if defined) - this function is executed after the state change
100
- * - computePreventStateChange (if defined) - this function is executed before the state change and it should return a boolean value that will be used to determine if the state change should be prevented or not
101
- */
102
- protected setStateWrapper: StateSetter<State>;
103
- /**
104
- * This creates a map of actions that can be used to modify or interact with the state
105
- * @returns {ActionCollectionResult<State, Metadata, StateMutator>} - The actions map result of the configuration object passed to the constructor
106
- * */
107
- getStoreActionsMap: () => null | ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>;
108
- createObservable<Fragment>(mainSelector: (state: State) => Fragment, { isEqualRoot: mainIsEqualRoot, isEqual: mainIsEqualFun, name: selectorName, }?: {
109
- isEqual?: (current: Fragment, next: Fragment) => boolean;
110
- isEqualRoot?: (current: State, next: State) => boolean;
111
- name?: string;
112
- }): ObservableFragment<Fragment>;
113
- }
@@ -1,37 +0,0 @@
1
- import { ActionCollectionConfig, StateSetter, ActionCollectionResult, StateHook, CustomGlobalHookBuilderParams, BaseMetadata, GlobalStoreCallbacks } from './GlobalStore.types';
2
- export interface CreateGlobalState {
3
- <State>(state: State): StateHook<State, StateSetter<State>, BaseMetadata>;
4
- <State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, Metadata> | null | {}, PublicStateMutator = keyof ActionsConfig extends never | undefined ? StateSetter<State> : ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>>(state: State, args: {
5
- name?: string;
6
- metadata?: Metadata;
7
- callbacks?: GlobalStoreCallbacks<State, Metadata>;
8
- actions?: ActionsConfig;
9
- }): StateHook<State, PublicStateMutator, Metadata>;
10
- <State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, Metadata>>(state: State, args: {
11
- name?: string;
12
- metadata?: Metadata;
13
- callbacks?: GlobalStoreCallbacks<State, Metadata>;
14
- actions: ActionsConfig;
15
- }): StateHook<State, ActionCollectionResult<State, Metadata, ActionsConfig>, Metadata>;
16
- }
17
- export declare const createGlobalState: CreateGlobalState;
18
- export interface CustomCreateGlobalState<TCustomConfig extends BaseMetadata | unknown, InheritMetadata extends BaseMetadata | unknown = BaseMetadata> {
19
- <State>(state: State): StateHook<State, StateSetter<State>, BaseMetadata>;
20
- <State, Metadata extends BaseMetadata | unknown>(state: State, args: {
21
- name?: string;
22
- metadata?: Metadata;
23
- callbacks?: GlobalStoreCallbacks<State, Metadata>;
24
- config?: TCustomConfig;
25
- }): StateHook<State, StateSetter<State>, BaseMetadata>;
26
- <State, Metadata extends BaseMetadata | unknown, ActionsConfig extends Readonly<ActionCollectionConfig<State, InheritMetadata & Metadata>>>(state: State, args: {
27
- name?: string;
28
- metadata?: Metadata;
29
- callbacks?: GlobalStoreCallbacks<State, Metadata>;
30
- actions?: ActionsConfig;
31
- config?: TCustomConfig;
32
- }): StateHook<State, ActionCollectionResult<State, InheritMetadata & Metadata, ActionsConfig>, Metadata>;
33
- }
34
- /**
35
- * @description Simple custom global state hook builder
36
- */
37
- export declare const createCustomGlobalState: <TCustomConfig extends unknown, InheritMetadata extends unknown = BaseMetadata>({ onInitialize, onChange, }: CustomGlobalHookBuilderParams<TCustomConfig, InheritMetadata>) => CustomCreateGlobalState<TCustomConfig, InheritMetadata>;
@@ -1,145 +0,0 @@
1
- /// <reference types="react" />
2
- export type StateSetter<State> = (setter: State | ((state: State) => State), meta?: {
3
- /**
4
- * @description you can add an identifier to the state call
5
- * this will show up in the devtools to help you identify from where the state change was called
6
- */
7
- identifier?: string | undefined;
8
- /**
9
- * @deprecated forceUpdate normally should not be used inside components
10
- * Use this flag just in custom implementations of the global store
11
- */
12
- forceUpdate?: boolean | undefined;
13
- }) => void;
14
- export type HookExtensions<State, StateMutator, Metadata extends BaseMetadata | unknown> = {
15
- /**
16
- * @description Return the state controls of the hook
17
- * This selectors includes:
18
- * - stateRetriever: a function to get the current state or subscribe a callback to the state changes
19
- * - stateMutator: a function to set the state or a collection of actions if you pass an storeActionsConfig configuration
20
- * - metadataRetriever: a function to get the metadata of the global state
21
- */
22
- stateControls: () => Readonly<[
23
- retriever: StateGetter<State>,
24
- mutator: StateMutator,
25
- metadata: MetadataGetter<Metadata>
26
- ]>;
27
- /***
28
- * @description Creates a new hooks that returns the result of the selector passed as a parameter
29
- * Your can create selector hooks of other selectors hooks and extract as many derived states as or fragments of the state as you want
30
- * The selector hook will be evaluated only if the result of the selector changes and the equality function returns false
31
- * you can customize the equality function by passing the isEqualRoot and isEqual parameters
32
- */
33
- createSelectorHook: <Derivate>(this: StateHook<State, StateMutator, Metadata>, selector: (state: State) => Derivate, args?: Omit<UseHookConfig<Derivate, State>, 'dependencies'> & {
34
- name?: string;
35
- }) => StateHook<Derivate, StateMutator, Metadata>;
36
- createObservable: <Fragment>(this: StateHook<State, StateMutator, Metadata>, mainSelector: (state: State) => Fragment, args?: {
37
- isEqual?: (current: Fragment, next: Fragment) => boolean;
38
- isEqualRoot?: (current: State, next: State) => boolean;
39
- name?: string;
40
- }) => ObservableFragment<Fragment>;
41
- };
42
- export type ObservableFragment<State> = StateGetter<State> & {
43
- createObservable: <Fragment>(this: ObservableFragment<State>, mainSelector: (state: State) => Fragment, args?: {
44
- isEqual?: (current: Fragment, next: Fragment) => boolean;
45
- isEqualRoot?: (current: State, next: State) => boolean;
46
- name?: string;
47
- }) => ObservableFragment<Fragment>;
48
- _name: string | undefined;
49
- };
50
- export interface StateHook<State, StateMutator, Metadata extends BaseMetadata | unknown> extends HookExtensions<State, StateMutator, Metadata> {
51
- (): Readonly<[state: State, stateMutator: StateMutator, metadata: Metadata]> & HookExtensions<State, StateMutator, Metadata>;
52
- <Derivate>(selector: (state: State) => Derivate, config?: UseHookConfig<Derivate, State>): Readonly<[
53
- state: Derivate,
54
- stateMutator: StateMutator,
55
- metadata: Metadata
56
- ]> & HookExtensions<Derivate, StateMutator, Metadata>;
57
- }
58
- export type MetadataSetter<Metadata extends BaseMetadata | unknown> = (setter: Metadata | ((metadata: Metadata) => Metadata)) => void;
59
- export type StateChanges<State> = {
60
- state: State;
61
- previousState: State | undefined;
62
- identifier: string | undefined;
63
- };
64
- /**
65
- * API for the actions of the global states
66
- **/
67
- export type StoreTools<State, Metadata extends BaseMetadata | unknown = BaseMetadata, Actions extends undefined | unknown | Record<string, (...args: any[]) => any> = unknown> = {
68
- setMetadata: MetadataSetter<Metadata>;
69
- setState: StateSetter<State>;
70
- getState: StateGetter<State>;
71
- getMetadata: () => Metadata;
72
- actions: Actions;
73
- };
74
- /**
75
- * contract for the storeActionsConfig configuration
76
- */
77
- export interface ActionCollectionConfig<State, Metadata extends BaseMetadata | unknown, ThisAPI = Record<string, (...parameters: any[]) => unknown>> {
78
- readonly [key: string]: {
79
- (this: ThisAPI, ...parameters: any[]): (this: ThisAPI, storeTools: StoreTools<State, Metadata, Record<string, (...parameters: any[]) => unknown | void>>) => unknown | void;
80
- };
81
- }
82
- export type ActionCollectionResult<State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, Metadata>> = {
83
- [key in keyof ActionsConfig]: {
84
- (...params: Parameters<ActionsConfig[key]>): ReturnType<ReturnType<ActionsConfig[key]>>;
85
- };
86
- };
87
- export type GlobalStoreCallbacks<State, Metadata extends BaseMetadata | unknown> = {
88
- onInit?: (args: StoreTools<State, Metadata>) => void;
89
- onStateChanged?: (args: StoreTools<State, Metadata> & StateChanges<State>) => void;
90
- onSubscribed?: (args: StoreTools<State, Metadata>) => void;
91
- computePreventStateChange?: (args: StoreTools<State, Metadata> & StateChanges<State>) => boolean;
92
- };
93
- export type UseHookConfig<State, TRoot = unknown> = {
94
- isEqual?: (current: State, next: State) => boolean;
95
- isEqualRoot?: (current: TRoot, next: TRoot) => boolean;
96
- dependencies?: unknown[];
97
- };
98
- export type UnsubscribeCallback = () => void;
99
- export type SubscribeCallbackConfig<State> = UseHookConfig<State> & {
100
- /**
101
- * By default the callback is executed immediately after the subscription
102
- */
103
- skipFirst?: boolean;
104
- };
105
- /**
106
- * Callback function to subscribe to the store changes
107
- */
108
- export type SubscribeCallback<State> = (state: State) => void;
109
- /**
110
- * get the current state or subscribe to the state changes
111
- */
112
- export type StateGetter<State> = {
113
- (): State;
114
- (subscription: SubscribeCallback<State>, config?: SubscribeCallbackConfig<State>): UnsubscribeCallback;
115
- <TDerivate>(selector: SelectorCallback<State, TDerivate>, subscription: SubscribeCallback<TDerivate>, config?: SubscribeCallbackConfig<TDerivate>): UnsubscribeCallback;
116
- };
117
- export type BaseMetadata = Record<string, unknown>;
118
- export type MetadataGetter<Metadata extends BaseMetadata | unknown> = () => Metadata;
119
- export type CustomGlobalHookBuilderParams<TCustomConfig extends BaseMetadata | unknown, Metadata extends BaseMetadata | unknown> = {
120
- onInitialize?: (args: StoreTools<unknown, Metadata, unknown>, config: TCustomConfig | undefined) => void;
121
- onChange?: (args: StoreTools<unknown, Metadata, unknown> & StateChanges<unknown>, config: TCustomConfig | undefined) => void;
122
- };
123
- export type SelectorCallback<State, TDerivate> = (state: State) => TDerivate;
124
- export type SubscriberParameters = {
125
- subscriptionId: string;
126
- selector: SelectorCallback<unknown, unknown> | undefined;
127
- config: UseHookConfig<unknown> | SubscribeCallbackConfig<unknown> | undefined;
128
- currentState: unknown;
129
- callback: SubscriptionCallback | React.Dispatch<React.SetStateAction<{
130
- state: unknown;
131
- }>>;
132
- isSetStateCallback: boolean;
133
- };
134
- /**
135
- * @description
136
- * This is the final listener of the store changes, it can be a subscription or a setState
137
- * @param {unknown} params - The parameters of the subscription
138
- * @param {unknown} params.state - The new state
139
- * @param {string} params.identifier - Optional identifier for the setState call
140
- */
141
- export type SubscriptionCallback<State = unknown> = (params: {
142
- state: State;
143
- }, args: {
144
- identifier?: string;
145
- }) => void;
@@ -1,9 +0,0 @@
1
- /// <reference types="react" />
2
- export declare const shallowCompare: <T>(value1: T, value2: T) => boolean;
3
- export declare const debounce: <T extends (...args: Parameters<T>) => void>(callback: T, delay?: number) => (...args: Parameters<T>) => void;
4
- export declare const uniqueId: (prefix?: string) => string;
5
- export declare const throwWrongKeyOnActionCollectionConfig: (action_key: string) => never;
6
- export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
7
- export declare const uniqueSymbol: unique symbol;
8
- export type UniqueSymbol = typeof uniqueSymbol;
9
- export declare const useConstantValueRef: <T>(initializer: () => T) => import("react").RefObject<T>;
@@ -1,14 +0,0 @@
1
- import { ActionCollectionConfig, StoreTools, BaseMetadata, StateChanges } from './GlobalStore.types';
2
- import { GlobalStore } from './GlobalStore';
3
- /**
4
- * @description
5
- * Use this class to extends the capabilities of the GlobalStore.
6
- * by implementing the abstract methods onInitialize and onChange.
7
- * You can use this class to create a store with async storage.
8
- */
9
- export declare abstract class GlobalStoreAbstract<State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, Metadata> | unknown> extends GlobalStore<State, Metadata, ActionsConfig> {
10
- protected onInit: (args: StoreTools<State, Metadata>) => void;
11
- protected onStateChanged: (args: StoreTools<State, Metadata> & StateChanges<State>) => void;
12
- protected abstract onInitialize: (args: StoreTools<State, Metadata>) => void;
13
- protected abstract onChange: (args: StoreTools<State, Metadata> & StateChanges<State>) => void;
14
- }
@@ -1,8 +0,0 @@
1
- export * from 'json-storage-formatter';
2
- export * from './GlobalStore.types';
3
- export * from './GlobalStore';
4
- export * from './GlobalStoreAbstract';
5
- export * from './GlobalStore.functionHooks';
6
- export * from './GlobalStore.utils';
7
- export * from './GlobalStore.combiners';
8
- export * from './GlobalStore.context';