react-native-global-state-hooks 4.0.7 → 5.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
@@ -46,7 +46,7 @@ export const useContacts = createGlobalState({
46
46
  });
47
47
  ```
48
48
 
49
- Now, let's say I want to have a filter bar for the contacts that will only have access to the filter.
49
+ Now, let's say we want to have a filter bar for the contacts that will only have access to the filter.
50
50
 
51
51
  **FilterBar.tsx**
52
52
 
@@ -58,38 +58,67 @@ return (
58
58
  );
59
59
  ```
60
60
 
61
+ There you have it again, super simple! By adding a **selector** function, you are able to create a derivative hook that will only trigger when the result of the **selector** changes.
62
+
63
+ By the way, in the example, the **selector** returning a new object is not a problem at all. This is because, by default, there is a shallow comparison between the previous and current versions of the state, so the render won't trigger if it's not necessary.
64
+
65
+ ## What if you want to reuse the selector?
66
+
67
+ It will be super common to have the necessity of reusing a specific **selector**, and it can be a little annoying to have to do the same thing again and again. Right?
68
+
69
+ No problem, you can create a reusable **derivative-state** and use it across your components. Let's create one for our filter.
70
+
71
+ ```ts
72
+ const useFilter = createDerivate(useContacts, ({ filter }) => ({ filter }));
73
+ ```
74
+
75
+ Well, that's it! Now you can simply call **useFilter** inside your component, and everything will continue to work the same.
76
+
77
+ **FilterBar.tsx**
78
+
79
+ ```ts
80
+ const [{ filter }, setState] = useFilter();
81
+
82
+ return (
83
+ <TextInput onChangeText={() => setState((state) => ({ ...state, filter }))} />
84
+ );
85
+ ```
86
+
87
+ Notice that the **state** changes, but the **setter** does not. This is because this is a **DERIVATE state**, and it cannot be directly changed. It will always be derived from the main hook.
88
+
61
89
  # State actions
62
90
 
63
91
  Is common and often necessary to restrict the manipulation of state to a specific set of actions or operations. To achieve this, we can simplify the process by adding a custom API to the configuration of our **useContacts**.
64
92
 
65
- By defining a custom API for the **useContacts**, we can encapsulate and expose only the necessary actions or operations that are allowed to modify the state. This provides a controlled interface for interacting with the state, ensuring that modifications adhere to the desired restrictions.
93
+ By defining a custom API for the **useContacts**, we can encapsulate and expose only the necessary actions or operations that are allowed to modify the state. This provides a controlled interface for interacting with the state, ensuring that modifications stick to the desired restrictions.
66
94
 
67
95
  ```ts
68
96
  import { createGlobalState } from "react-native-global-state-hooks";
69
97
 
70
- export const useContacts = createGlobalState(
71
- {
72
- isLoading: true,
73
- filter: "",
74
- items: [] as Contact[],
75
- },
76
- {
77
- // this are the actions available for this state
78
- actions: {
79
- setFilter(filter: string) {
80
- return ({ setState }: StoreTools<number>) => {
81
- setState((state) => ({
82
- ...state,
83
- filter,
84
- }));
85
- };
86
- },
87
- } as const,
88
- onInit: async ({ setState }: StoreTools) => {
89
- // fetch contacts
98
+ const initialState = {
99
+ isLoading: true,
100
+ filter: "",
101
+ items: [] as Contact[],
102
+ };
103
+
104
+ type State = typeof initialState;
105
+
106
+ export const useContacts = createGlobalState(initialState, {
107
+ // this are the actions available for this state
108
+ actions: {
109
+ setFilter(filter: string) {
110
+ return ({ setState }: StoreTools<State>) => {
111
+ setState((state) => ({
112
+ ...state,
113
+ filter,
114
+ }));
115
+ };
90
116
  },
91
- }
92
- );
117
+ } as const,
118
+ onInit: async ({ setState }: StoreTools<State>) => {
119
+ // fetch contacts
120
+ },
121
+ });
93
122
  ```
94
123
 
95
124
  That's it! In this updated version, the **useContacts** hook will no longer return [**state**, **stateSetter**] but instead will return [**state**, **actions**]. This change will provide a more intuitive and convenient way to access and interact with the state and its associated actions.
@@ -97,14 +126,28 @@ That's it! In this updated version, the **useContacts** hook will no longer retu
97
126
  Let's see how that will look now into our **FilterBar.tsx**
98
127
 
99
128
  ```tsx
100
- const [{ filter }, { setFilter }] = useContacts(({ filter }) => ({ filter }));
129
+ const [{ filter }, { setFilter }] = useFilter();
101
130
 
102
131
  return <TextInput onChangeText={setFilter} />;
103
132
  ```
104
133
 
105
- It can't get any simpler, right? Plus, these hooks are strongly typed, so if you're working with TypeScript, you'll love it.
134
+ Yeah, that's it! All the **derived states** and **emitters** (we will talk about this later) will inherit the new actions interface.
135
+
136
+ You can even **derive** from another **derived state**! Let's explore a few silly examples:
137
+
138
+ ```ts
139
+ const useFilter = createDerivate(useContacts, ({ filter }) => ({ filter }));
140
+
141
+ const useFilterString = createDerivate(useFilter, { filter } => filter);
142
+
143
+ const useContacts = createDerivate(useContacts, ({ items }) => items);
106
144
 
107
- Let's continue exploring which other features we can discover with global state hooks!!
145
+ const useContactsLength = createDerivate(useContacts, (items) => items.length);
146
+
147
+ const useIsContactsEmpty = createDerivate(useContactsLength, (length) => !length);
148
+ ```
149
+
150
+ It can't get any simpler, right? Everything is connected, everything is reactive. Plus, these hooks are strongly typed, so if you're working with **TypeScript**, you'll absolutely love it.
108
151
 
109
152
  # Decoupled state access
110
153
 
@@ -143,27 +186,221 @@ Additionally, to subscribe to state changes, you can pass a callback function as
143
186
  * This not only allows you to retrieve the current value of the state...
144
187
  * but also enables you to subscribe to any changes in the state or a portion of it
145
188
  */
146
- const removeSubscriptionGroup = contactsGetter<Subscribe>(
147
- ({ subscribe, subscribeSelector }) => {
148
- subscribe((state) => {
149
- console.log("state changed: ", state);
150
- });
189
+ const removeSubscriptionGroup = contactsGetter<Subscribe>((subscribe) => {
190
+ subscribe((state) => {
191
+ console.log("state changed: ", state);
192
+ });
193
+
194
+ subscribe(
195
+ (state) => state.isLoading,
196
+ (isLoading) => {
197
+ console.log("is loading changed", isLoading);
198
+ }
199
+ );
200
+ });
201
+ ```
151
202
 
152
- subscribeSelector(
153
- (state) => state.isLoading,
154
- (isLoading) => {
155
- console.log("is loading changed", isLoading);
156
- }
157
- );
203
+ That's great, isn't it? everything stays synchronized with the original state!!
204
+
205
+ # Emitters
206
+
207
+ So, we have seen that we can subscribe a callback to state changes, create **derivative states** from our global hooks, **and derive hooks from those derivative states**. Guess what? We can also create derivative **emitters** and subscribe callbacks to specific portions of the state. Let's review it:
208
+
209
+ ```ts
210
+ const subscribeToFilter = createDerivateEmitter(
211
+ contactsGetter,
212
+ ({ filter }) => ({
213
+ filter,
214
+ })
215
+ );
216
+ ```
217
+
218
+ Cool, it's basically the same, but instead of using the **hook** as a parameter, we just have to use the **getter** as a parameter, and that will make the magic.
219
+
220
+ Now we are able to add a callback that will be executed every time the state of the **filter** changes.
221
+
222
+ ```ts
223
+ const removeFilterSubscription = subscribeToFilter<Subscribe>(({ filter }) => {
224
+ console.log(`The filter value changed: ${filter}`);
225
+ });
226
+ ```
227
+
228
+ By default, the callback will be executed once subscribed, using the current value of the state. If you want to avoid this initial call, you can pass an extra parameter to the **subscribe** function.
229
+
230
+ ```ts
231
+ const removeFilterSubscription = subscribeToFilter<Subscribe>(
232
+ ({ filter }) => {
233
+ console.log(`The filter value changed: ${filter}`);
234
+ },
235
+ {
236
+ skipFirst: true,
158
237
  }
159
238
  );
160
239
  ```
161
240
 
162
- That's great, isn't it? And everything stays synchronized with the original state!!
241
+ Also, of course, if you have an exceptional case where you want to derivate directly from the current **emitter**, you can add a **selector**. This allows you to fine-tune the emitted values based on your requirements
242
+
243
+ ```ts
244
+ const removeFilterSubscription = subscribeToFilter<Subscribe>(
245
+ ({ filter }) => filter,
246
+ /**
247
+ * Cause of the selector the filter now is an string
248
+ */
249
+ (filter) => {
250
+ console.log(`The filter value changed: ${filter}`);
251
+ },
252
+ {
253
+ skipFirst: true,
254
+ /**
255
+ * You can also override the default shallow comparison...
256
+ * or disable it completely by setting the isEqual callback to null.
257
+ */
258
+ isEqual: (a, b) => a === b,
259
+ // isEqual: null // this will avoid doing a shallow comparison
260
+ }
261
+ );
262
+ ```
263
+
264
+ And guess what again? You can also derive emitters from derived emitters without any trouble at all! It works basically the same. Let's see an example:
265
+
266
+ ```ts
267
+ const subscribeToItems = createDerivateEmitter(
268
+ contactsGetter,
269
+ ({ items }) => items
270
+ );
271
+
272
+ const subscribeToItemsLength = createDerivateEmitter(
273
+ subscribeToItems,
274
+ (items) => items.length
275
+ );
276
+ ```
277
+
278
+ The examples may seem a little silly, but they allow you to see the incredible things you can accomplish with these **derivative states** and **emitters**. They open up a world of possibilities!
279
+
280
+ # Combining getters
281
+
282
+ What if you have two states and you want to combine them? You may have already guessed it right? ... you can create combined **emitters** and **hooks** from the hook **getters**.
283
+
284
+ By utilizing the approach of combining **emitters** and **hooks**, you can effectively merge multiple states and make them shareable. This allows for better organization and simplifies the management of the combined states. You don't need to refactor everything; you just need to combine the **global state hooks** you already have. Let's see a simple example:
285
+
286
+ Fist we are gonna create a couple of **global state**, is important to create them with the **createGlobalStateWithDecoupledFuncs** since we need the decoupled **getter**. (In case you are using an instance of **GlobalStore** or **GlobalStoreAbstract** you can just pick up the getters from the **getHookDecoupled** method)
287
+
288
+ ```ts
289
+ const [useHook1, getter1, setter1] = createGlobalStateWithDecoupledFuncs({
290
+ propA: 1,
291
+ propB: 2,
292
+ });
293
+
294
+ const [, getter2] = createGlobalStateWithDecoupledFuncs({
295
+ propC: 3,
296
+ propD: 4,
297
+ });
298
+ ```
299
+
300
+ Okay, cool, the first state as **propA, propB** while the second one has **propC, propD**, let's combine them:
301
+
302
+ ```ts
303
+ const [useCombinedHook, getter, dispose] = combineAsyncGetters(
304
+ {
305
+ selector: ([state1, state2]) => ({
306
+ ...state1,
307
+ ...state2,
308
+ }),
309
+ },
310
+ getter1,
311
+ getter2
312
+ );
313
+ ```
314
+
315
+ Well, that's it! Now you have access to a **getter** that will return the combined value of the two states. From this new **getter**, you can retrieve the value or subscribe to its changes. Let'see:
316
+
317
+ ```ts
318
+ const value = getter(); // { propA, propB, propC, propD }
319
+
320
+ // subscribe to the new emitter
321
+ const unsubscribeGroup = getter<Subscribe>((subscribe) => {
322
+ subscribe((state) => {
323
+ console.log(subscribe); // full state
324
+ });
325
+
326
+ // Please note that if you add a selector,
327
+ // the callback will only trigger if the result of the selector changes.
328
+ subscribe(
329
+ ({ propA, propD }) => ({ propA, propD }),
330
+ (derivate) => {
331
+ console.log(derivate); // { propA, propD }
332
+ }
333
+ );
334
+ });
335
+ ```
336
+
337
+ Regarding the newly created hook, **useCombinedHook**, you can seamlessly utilize it across all your components, just like your other **global state hooks**. This enables a consistent and familiar approach for accessing and managing the combined state within your application.
338
+
339
+ ```ts
340
+ const [combinedState] = useCombinedHook();
341
+ ```
342
+
343
+ The main difference with **combined hooks** compared to individual **global state hooks** is the absence of **metadata** and **actions**. Instead, combined hooks provide a condensed representation of the underlying global states using simple React functionality. This streamlined approach ensures lightweight usage, making it easy to access and manage the combined state within your components.
344
+
345
+ ### Let's explore some additional examples.
346
+
347
+ Similar to your other **global state hooks**, **combined hooks** allow you to use **selectors** directly from consumer components. This capability eliminates the need to create an excessive number of reusable hooks if they are not truly necessary. By utilizing selectors, you can efficiently extract specific data from the **combined state** and utilize it within your components. This approach offers a more concise and focused way of accessing the required state values without the need for creating additional hooks unnecessarily.
348
+
349
+ ```ts
350
+ const [fragment] = useCombinedHook(({ propA, propD }) => ({ propA, propD }));
351
+ ```
352
+
353
+ Lastly, you have the flexibility to continue combining getters if desired. This means you can extend the functionality of combined hooks by adding more getters to merge additional states. By combining getters in this way, you can create a comprehensive and unified representation of the combined states within your application. This approach allows for modular and scalable state management, enabling you to efficiently handle complex state compositions.
354
+
355
+ Let's see an example:
356
+
357
+ ```ts
358
+ const [useCombinedHook, combinedGetter1, dispose1] = combineAsyncGetters(
359
+ {
360
+ selector: ([state1, state2]) => ({
361
+ ...state1,
362
+ ...state2,
363
+ }),
364
+ },
365
+ getter1,
366
+ getter2
367
+ );
368
+
369
+ const [useHook3, getter3, setter3] = createGlobalStateWithDecoupledFuncs({
370
+ propE: 1,
371
+ propF: 2,
372
+ });
373
+
374
+ const [useIsLoading, isLoadingGetter, isLoadingSetter] =
375
+ createGlobalStateWithDecoupledFuncs(false);
376
+ ```
377
+
378
+ Once we created another peace of state, we can combine it with our other **global hooks** and **emitters**
379
+
380
+ ```ts
381
+ const [useCombinedHook2, combinedGetter2, dispose2] = combineAsyncGetters(
382
+ {
383
+ selector: ([state1, state2, isLoading]) => ({
384
+ ...state1,
385
+ ...state2,
386
+ isLoading,
387
+ }),
388
+ },
389
+ combinedGetter1,
390
+ getter3,
391
+ isLoadingGetter
392
+ );
393
+ ```
394
+
395
+ You have the freedom to combine as many global hooks as you wish. This means you can merge multiple states into a single cohesive unit by combining their respective hooks. This approach offers flexibility and scalability, allowing you to handle complex state compositions in a modular and efficient manner.
396
+
397
+ ### **Quick note**:
398
+
399
+ Please be aware that the third parameter is a **dispose callback**, which can be particularly useful in **high-order** functions when you want to release any resources associated with the hook. By invoking the dispose callback, the hook will no longer report any changes, ensuring that resources are properly cleaned up. This allows for efficient resource management and can be beneficial in scenarios where you need to handle resource cleanup or termination in a controlled manner.
163
400
 
164
- ...
401
+ ## Setter
165
402
 
166
- Similarly, the **contactsSetter** method enables you to modify the state stored in **useContacts**. You can use this method to update the state with a new value or perform any necessary state mutations.
403
+ Similarly, the **contactsSetter** method allows you to modify the state stored in **useContacts**. You can use this method to update the state with a new value or perform any necessary state mutations without the restrictions imposed by **hooks**.
167
404
 
168
405
  These additional methods provide a more flexible and granular way to interact with the state managed by **useContacts**. You can retrieve and modify the state as needed, without establishing a subscription relationship or reactivity with the state changes.
169
406
 
package/lib/bundle.js CHANGED
@@ -1,2 +1,2 @@
1
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-native-global-state-hooks"]=e(require("react")):t["react-native-global-state-hooks"]=e(t.react)}(this,(t=>{return e={729:(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.createCustomGlobalState=e.createCustomGlobalStateWithDecoupledFuncs=e.createGlobalState=e.createGlobalStateWithDecoupledFuncs=void 0;var i=r(774);e.createGlobalStateWithDecoupledFuncs=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.actions,o=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]])}return r}(e,["actions"]),a=new i.GlobalStore(t,o,r),u=n(a.getHookDecoupled(),2),c=u[0],l=u[1];return[a.getHook(),c,l]},e.createGlobalState=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return n((0,e.createGlobalStateWithDecoupledFuncs)(t,r),1)[0]},e.createCustomGlobalStateWithDecoupledFuncs=function(t){var r=t.onInitialize,n=t.onChange;return function(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{config:null},i=o.config,a=o.actions,u=o.metadata,c=o.onInit,l=o.onStateChanged,s=o.onSubscribed,f=o.computePreventStateChange;return(0,e.createGlobalStateWithDecoupledFuncs)(t,{actions:a,metadata:u,onInit:function(t){r(t,i),null==c||c(t)},onStateChanged:function(t){n(t,i),null==l||l(t)},onSubscribed:s,computePreventStateChange:f})}},e.createCustomGlobalState=function(t){var r=t.onInitialize,o=t.onChange,i=(0,e.createCustomGlobalStateWithDecoupledFuncs)({onInitialize:r,onChange:o});return function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{config:{}},r=e.config,o=e.actions,a=e.metadata,u=e.onInit,c=e.onStateChanged,l=e.onSubscribed,s=e.computePreventStateChange;return n(i(t,{config:r,actions:o,metadata:a,onInit:u,onStateChanged:c,onSubscribed:l,computePreventStateChange:s}),1)[0]}}},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)||function(t,e){if(t){if("string"==typeof t)return i(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)?i(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 i(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 a(){a=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:{},u=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 y?e:y,a=Object.create(i.prototype),u=new C(n||[]);return o(a,"_invoke",{value:j(t,r,u)}),a}function p(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=f;var v={};function y(){}function h(){}function d(){}var b={};s(b,u,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(E([])));m&&m!==e&&r.call(m,u)&&(b=m);var S=d.prototype=y.prototype=Object.create(b);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=p(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=x(a,r);if(u){if(u===v)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=p(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===v)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function x(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,x(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),v;var o=p(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,v;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,v):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,v)}function P(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 k(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function C(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function E(t){if(t){var e=t[u];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:A}}function A(){return{value:void 0,done:!0}}return h.prototype=d,o(S,"constructor",{value:d,configurable:!0}),o(d,"constructor",{value:h,configurable:!0}),h.displayName=s(d,l,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,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,u,(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=E,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(k),!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,v):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),v},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),k(r),v}},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;k(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:E(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),v}},t}function u(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,c(n.key),n)}}function c(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 l=r(608),s=r(156),f=function(){function t(e){var r=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.actionsConfig=i,this.subscribers=new Map,this.config={metadata:null},this.onInit=null,this.onStateChanged=null,this.onSubscribed=null,this.computePreventStateChange=null,this.initialize=function(){return t=r,e=void 0,n=void 0,o=a().mark((function t(){var e,r,n;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e=this.onInit,r=this.config.onInit,e||r){t.next=4;break}return t.abrupt("return");case 4:n=this.getConfigCallbackParam({}),null==e||e(n),null==r||r(n);case 7: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.setState=function(t){var e=t.invokerSetState,n=t.state,i=t.forceUpdate;r.stateWrapper={state:n};var a=function(t,e){var r=e.selector,o=e.currentState,a=e.config,u=(null==a?void 0:a.isEqual)||null===(null==a?void 0:a.isEqual)?a.isEqual:r?l.shallowCompare:null,c=r?r(n):n;!i&&(null==u?void 0:u(o,c))||t({state:c})};if(e){var u=r.subscribers.get(e);a(e,u)}Array.from(r.subscribers.entries()).forEach((function(t){var r=o(t,2),n=r[0],i=r[1];n!==e&&a(n,i)}))},this.setMetadata=function(t){var e,n,o="function"==typeof t?t(null!==(e=r.config.metadata)&&void 0!==e?e:null):t;r.config=Object.assign(Object.assign({},null!==(n=r.config)&&void 0!==n?n:{}),{metadata:o})},this.getMetadata=function(){var t;return null!==(t=r.config.metadata)&&void 0!==t?t:null},this.createChangesSubscriber=function(t){var e=t.callback,n=t.selector,o=t.config,i=n?n(r.stateWrapper.state):r.stateWrapper.state,a={state:i};return(null==o?void 0:o.skipFirst)||e(i),{stateWrapper:a,subscription:function(t){var r=t.state;a.state=r,e(r)}}},this.getState=function(t){if(!t)return r.stateWrapper.state;var e=r.stateWrapper.state,n=new Map;if(t({state:e,subscribe:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=r.createChangesSubscriber({selector:null,callback:t,config:e}),i=o.subscription,a=o.stateWrapper;r.updateSubscription({selector:null,config:e,stateWrapper:a,invokerSetState:i}),n.set(i,{config:e})},subscribeSelector:function(t,e){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=r.createChangesSubscriber({selector:t,callback:e,config:o}),a=i.subscription,u=i.stateWrapper;r.updateSubscription({selector:t,config:Object.assign({isEqual:l.shallowCompare},o),stateWrapper:u,invokerSetState:a}),n.set(a,{config:o,selector:t})}}),!n.size)throw new Error("No new subscribers were added, please make sure to add at least one subscriber with the subscribe/subscribeSelector methods");return function(){Array.from(n.keys()).forEach((function(t){r.subscribers.delete(t)}))}},this.getConfigCallbackParam=function(t){var e=t.invokerSetState;return{setMetadata:r.setMetadata,getMetadata:r.getMetadata,getState:r.getState,setState:r.getSetStateWrapper({invokerSetState:e}),actions:r.getStoreActionsMap()}},this.updateSubscription=function(t){var e=t.selector,n=t.config,o=void 0===n?{}:n,i=t.stateWrapper.state,a=t.invokerSetState,u=r.subscribers.get(a);if(u)u.currentState=i;else{var c=r.onSubscribed,l=r.config.onSubscribed;if(c||l){var s=r.getConfigCallbackParam({invokerSetState:a});null==c||c(s),null==l||l(s)}r.subscribers.set(a,{selector:e,config:o,currentState:i})}},this.getHook=function(){return function(t){var e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=o((0,s.useState)((function(){return t?{state:t(r.stateWrapper.state)}:r.stateWrapper})),2),a=i[0],u=i[1];r.updateSubscription({invokerSetState:u,stateWrapper:a,selector:t,config:n}),(0,s.useEffect)((function(){return function(){r.subscribers.delete(u)}}),[]);var c=(0,s.useMemo)((function(){return r.getStateOrchestrator(u)}),[]);return[a.state,c,null!==(e=r.config.metadata)&&void 0!==e?e:null]}},this.getHookDecoupled=function(){var t=r.getStateOrchestrator(),e=r.getMetadata;return[r.getState,t,e]},this.getSetStateWrapper=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).invokerSetState;return function(e){var n=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).forceUpdate;r.computeSetState({invokerSetState:t,setter:e,forceUpdate:n})}},this.hasStateCallbacks=function(){var t=r.computePreventStateChange,e=r.onStateChanged,n=r.config,o=n.computePreventStateChange,i=n.onStateChanged;return!!(t||o||e||i)},this.computeSetState=function(t){var e=t.setter,n=t.invokerSetState,o=t.forceUpdate,i="function"==typeof e,a=r.stateWrapper.state,u=i?e(a):e;if(o||!Object.is(r.stateWrapper.state,u)){var c=r.hasStateCallbacks(),l=c&&r.getStoreActionsMap({}),s=c&&r.getSetStateWrapper({invokerSetState:n}),f={setMetadata:r.setMetadata,getMetadata:r.getMetadata,setState:s||null,getState:r.getState,actions:l,previousState:a,state:u},p=r.computePreventStateChange,v=r.config.computePreventStateChange;if((p||v)&&((null==p?void 0:p(f))||(null==v?void 0:v(f))))return;r.setState({forceUpdate:o,invokerSetState:n,state:u});var y=r.onStateChanged,h=r.config.onStateChanged;(y||h)&&(null==y||y(f),null==h||h(f))}},this.getStoreActionsMap=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).invokerSetState;if(!r.actionsConfig)return null;var e=r.actionsConfig,n=r.setMetadata,o=e,i=Object.keys(o),a=r.getSetStateWrapper({invokerSetState:t}),u=r.getState,l=r.getMetadata,s=i.reduce((function(t,e){return Object.assign(Object.assign({},t),(r={},f=function(){for(var t=o[e],r=arguments.length,i=new Array(r),c=0;c<r;c++)i[c]=arguments[c];var f=t.apply(s,i);return"function"!=typeof f&&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 }) => {\n\n setState((state) => ({ ...state, ...param }))\n\n }\n\n}\n"))}(e),f.call(s,{setState:a,getState:u,setMetadata:n,getMetadata:l,actions:s})},(i=c(i=e))in r?Object.defineProperty(r,i,{value:f,enumerable:!0,configurable:!0,writable:!0}):r[i]=f,r));var r,i,f}),{});return s},this.stateWrapper={state:e},this.config=Object.assign({metadata:null},null!=n?n:{}),this.constructor!==t||this.initialize()}var e,r;return e=t,(r=[{key:"state",get:function(){return this.stateWrapper.state}},{key:"getStateOrchestrator",value:function(t){return this.actionsConfig?this.getStoreActionsMap({invokerSetState:t}):this.getSetStateWrapper({invokerSetState:t})}}])&&u(e.prototype,r),Object.defineProperty(e,"prototype",{writable:!1}),t}();e.GlobalStore=f},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.shallowCompare=void 0;var c=r(684);e.shallowCompare=function(t,e){if(t===e)return!0;var r=u(t),i=u(e);if(r!==i)return!1;if((0,c.isPrimitive)(t)&&(0,c.isPrimitive)(e)||(0,c.isDate)(t)&&(0,c.isDate)(e)||"function"===r&&"function"===i)return t===e;if(Array.isArray(t)){var a=t,l=e;if(a.length!==l.length)return!1;for(var s=0;s<a.length;s++)if(a[s]!==l[s])return!1}if(t instanceof Map){var f=t,p=e;if(f.size!==p.size)return!1;var v,y=o(f);try{for(y.s();!(v=y.n()).done;){var h=n(v.value,2),d=h[0];if(h[1]!==p.get(d))return!1}}catch(t){y.e(t)}finally{y.f()}}if(t instanceof Set){var b=t,g=e;if(b.size!==g.size)return!1;var m,S=o(b);try{for(S.s();!(m=S.n()).done;){var w=m.value;if(!g.has(w))return!1}}catch(t){S.e(t)}finally{S.f()}}var O=Object.keys(t),j=Object.keys(e);if(O.length!==j.length)return!1;for(var x=0,P=O;x<P.length;x++){var k=P[x];if(t[k]!==e[k])return!1}return!0}},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(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,c),(e=u.call(this,t,r,n)).onInit=function(t){e.onInitialize(t)},e.onStateChanged=function(t){e.onChange(t)},e}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(729),e)},684:function(t){t.exports=(()=>{"use strict";var t={991:(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(729),e)},729:(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,e){if("object"!==r(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,"string");if("object"!==r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===r(e)?e:String(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=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)?i(t,e):void 0}}function i(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.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){return function(t){var r,i;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 a=(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(a)}if("set"===(null==t?void 0:t.$t)){var u=null!==(i=t.$v)&&void 0!==i?i:[].map((function(t){return(0,e.formatFromStore)(t)}));return new Set(u)}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)")):Object.keys(t).reduce((function(r,o){var i=t[o];return Object.assign(Object.assign({},r),n({},o,(0,e.formatFromStore)(i)))}),{})}((arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).jsonParse?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=new Set(null!=u?u:[]),s=new Set(null!=c?c:[]),f=l.size||s.size,p=null!=a?a:function(t){var e=t.key,n=t.value;if(!f)return!0;var o=s.has(e),i=l.has(r(n));return!o&&!i},v=function t(r){if((0,e.isPrimitive)(r))return r;if(Array.isArray(r))return r.map((function(e){return t(e)}));if(r instanceof Map)return{$t:"map",$v:Array.from(r.entries()).map((function(e){return t(e)}))};if(r instanceof Set)return{$t:"set",$v:Array.from(r.values()).map((function(e){return t(e)}))};if((0,e.isDate)(r))return{$t:"date",$v:r.toISOString()};if((0,e.isRegex)(r))return{$t:"regex",$v:r.toString()};if((0,e.isFunction)(r)){var o;try{o={$t:"function",$v:r.toString()}}catch(t){o={$t:"error",$v:"Error: Could not serialize function"}}return o}return r instanceof Error?{$t:"error",$v:r.message}:Object.keys(r).reduce((function(e,o){var i=r[o],a=t(i);return p({obj:r,key:o,value:a})?Object.assign(Object.assign({},e),n({},o,t(i))):e}),{})}((0,e.clone)(t));return i?JSON.stringify(v):v}}},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}(991)})()},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}));
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-native-global-state-hooks"]=e(require("react")):t["react-native-global-state-hooks"]=e(t.react)}(this,(t=>{return e={853:(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}var i=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]])}return r};Object.defineProperty(e,"__esModule",{value:!0}),e.createDerivateEmitter=e.createDerivate=e.createCustomGlobalStateWithDecoupledFuncs=e.createGlobalState=e.createGlobalStateWithDecoupledFuncs=void 0;var a=r(774);e.createGlobalStateWithDecoupledFuncs=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.actions,o=i(e,["actions"]),u=new a.GlobalStore(t,o,r),c=n(u.getHookDecoupled(),2),l=c[0],f=c[1];return[u.getHook(),l,f]},e.createGlobalState=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return n((0,e.createGlobalStateWithDecoupledFuncs)(t,r),1)[0]},e.createCustomGlobalStateWithDecoupledFuncs=function(t){var r=t.onInitialize,n=t.onChange;return function(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{config:null},a=o.config,u=o.onInit,c=o.onStateChanged,l=i(o,["config","onInit","onStateChanged"]);return(0,e.createGlobalStateWithDecoupledFuncs)(t,Object.assign({onInit:function(t){r(t,a),null==u||u(t)},onStateChanged:function(t){n(t,a),null==c||c(t)}},l))}},e.createDerivate=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return function(n){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return t((function(t){var r=e(t);return n?n(r):r}),n&&o?o:r)}},e.createDerivateEmitter=function(t,r){var n=t._father_emitter;if(n){var o=function(t){var e=n.selector(t);return r(e)},i=(0,e.createDerivateEmitter)(n.getter,o);return i._father_emitter={getter:n.getter,selector:o},i}var a=function(e,n){var o="function"==typeof n,i=o?e:null,a=o?n:e,u=o?arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}:n;return t((function(t){t((function(t){var e,n=r(t);return null!==(e=null==i?void 0:i(n))&&void 0!==e?e:n}),a,u)}))};return a._father_emitter={getter:t,selector:r},a}},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)||function(t,e){if(t){if("string"==typeof t)return i(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)?i(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 i(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 a(){a=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:{},u=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",l=i.toStringTag||"@@toStringTag";function f(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{f({},"")}catch(t){f=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var i=e&&e.prototype instanceof y?e:y,a=Object.create(i.prototype),u=new P(n||[]);return o(a,"_invoke",{value:j(t,r,u)}),a}function p(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var v={};function y(){}function h(){}function d(){}var b={};f(b,u,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(k([])));m&&m!==e&&r.call(m,u)&&(b=m);var S=d.prototype=y.prototype=Object.create(b);function w(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function i(o,a,u,c){var l=p(t[o],t,a);if("throw"!==l.type){var f=l.arg,s=f.value;return s&&"object"==n(s)&&r.call(s,"__await")?e.resolve(s.__await).then((function(t){i("next",t,u,c)}),(function(t){i("throw",t,u,c)})):e.resolve(s).then((function(t){f.value=t,u(f)}),(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=x(a,r);if(u){if(u===v)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=p(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===v)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function x(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,x(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),v;var o=p(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,v;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,v):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,v)}function A(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 E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(A,this),this.reset(!0)}function k(t){if(t){var e=t[u];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 h.prototype=d,o(S,"constructor",{value:d,configurable:!0}),o(d,"constructor",{value:h,configurable:!0}),h.displayName=f(d,l,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,f(t,l,"GeneratorFunction")),t.prototype=Object.create(S),t},t.awrap=function(t){return{__await:t}},w(O.prototype),f(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(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(S),f(S,l,"Generator"),f(S,u,(function(){return this})),f(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,P.prototype={constructor:P,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(E),!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,v):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),v},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),E(r),v}},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;E(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),v}},t}function u(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,c(n.key),n)}}function c(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=e.throwNoSubscribersWereAdded=void 0;var l=r(608),f=r(156);e.throwNoSubscribersWereAdded=function(){throw new Error("No new subscribers were added, please make sure to add at least one subscriber with the subscribe method")};var s=function(){function t(r){var n=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.actionsConfig=u,this.subscribers=new Map,this.config={metadata:null},this.onInit=null,this.onStateChanged=null,this.onSubscribed=null,this.computePreventStateChange=null,this.initialize=function(){return t=n,e=void 0,r=void 0,o=a().mark((function t(){var e,r,n;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e=this.onInit,r=this.config.onInit,e||r){t.next=4;break}return t.abrupt("return");case 4:n=this.getConfigCallbackParam({}),null==e||e(n),null==r||r(n);case 7:case"end":return t.stop()}}),t,this)})),new(r||(r=Promise))((function(n,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?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,u)}c((o=o.apply(t,e||[])).next())}));var t,e,r,o},this.setState=function(t){var e=t.invokerSetState,r=t.state,i=t.forceUpdate;n.stateWrapper={state:r};var a=function(t,e){var n=e.selector,o=e.currentState,a=e.config,u=(null==a?void 0:a.isEqual)||null===(null==a?void 0:a.isEqual)?null==a?void 0:a.isEqual:n?l.shallowCompare:null,c=n?n(r):r;!i&&(null==u?void 0:u(o,c))||t({state:c})};if(e){var u=n.subscribers.get(e);a(e,u)}Array.from(n.subscribers.entries()).forEach((function(t){var r=o(t,2),n=r[0],i=r[1];n!==e&&a(n,i)}))},this.setMetadata=function(t){var e,r,o="function"==typeof t?t(null!==(e=n.config.metadata)&&void 0!==e?e:null):t;n.config=Object.assign(Object.assign({},null!==(r=n.config)&&void 0!==r?r:{}),{metadata:o})},this.getMetadata=function(){var t;return null!==(t=n.config.metadata)&&void 0!==t?t:null},this.createChangesSubscriber=function(t){var e=t.callback,r=t.selector,o=t.config,i=r?r(n.stateWrapper.state):n.stateWrapper.state,a={state:i};return(null==o?void 0:o.skipFirst)||e(i),{stateWrapper:a,subscription:function(t){var r=t.state;a.state=r,e(r)}}},this.getState=function(t){if(!t)return n.stateWrapper.state;var r=new Map;return t((function(t,e,o){var i="function"==typeof e,a=i?t:null,u=i?e:t,c=i?o:e,l=n.createChangesSubscriber({selector:a,callback:u,config:c}),f=l.subscription,s=l.stateWrapper;n.updateSubscription({selector:a,config:c,stateWrapper:s,invokerSetState:f}),r.set(f,{config:c})})),r.size||(0,e.throwNoSubscribersWereAdded)(),function(){Array.from(r.keys()).forEach((function(t){n.subscribers.delete(t)}))}},this.getConfigCallbackParam=function(t){var e=t.invokerSetState;return{setMetadata:n.setMetadata,getMetadata:n.getMetadata,getState:n.getState,setState:n.getSetStateWrapper({invokerSetState:e}),actions:n.getStoreActionsMap()}},this.updateSubscription=function(t){var e=t.selector,r=t.config,o=void 0===r?{}:r,i=t.stateWrapper.state,a=t.invokerSetState,u=n.subscribers.get(a);if(u)u.currentState=i;else{var c=n.onSubscribed,l=n.config.onSubscribed;if(c||l){var f=n.getConfigCallbackParam({invokerSetState:a});null==c||c(f),null==l||l(f)}n.subscribers.set(a,{selector:e,config:o,currentState:i})}},this.getHook=function(){return function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=o((0,f.useState)((function(){return t?{state:t(n.stateWrapper.state)}:n.stateWrapper})),2),a=i[0],u=i[1];n.updateSubscription({invokerSetState:u,stateWrapper:a,selector:t,config:r}),(0,f.useEffect)((function(){return function(){n.subscribers.delete(u)}}),[]);var c=(0,f.useMemo)((function(){return n.getStateOrchestrator(u)}),[]);return[a.state,c,null!==(e=n.config.metadata)&&void 0!==e?e:null]}},this.getHookDecoupled=function(){var t=n.getStateOrchestrator(),e=n.getMetadata;return[n.getState,t,e]},this.getSetStateWrapper=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).invokerSetState;return function(e){var r=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).forceUpdate;n.computeSetState({invokerSetState:t,setter:e,forceUpdate:r})}},this.hasStateCallbacks=function(){var t=n.computePreventStateChange,e=n.onStateChanged,r=n.config,o=r.computePreventStateChange,i=r.onStateChanged;return!!(t||o||e||i)},this.computeSetState=function(t){var e=t.setter,r=t.invokerSetState,o=t.forceUpdate,i="function"==typeof e,a=n.stateWrapper.state,u=i?e(a):e;if(o||!Object.is(n.stateWrapper.state,u)){var c=n.hasStateCallbacks(),l=c&&n.getStoreActionsMap({}),f=c&&n.getSetStateWrapper({invokerSetState:r}),s={setMetadata:n.setMetadata,getMetadata:n.getMetadata,setState:f||null,getState:n.getState,actions:l,previousState:a,state:u},p=n.computePreventStateChange,v=n.config.computePreventStateChange;if((p||v)&&((null==p?void 0:p(s))||(null==v?void 0:v(s))))return;n.setState({forceUpdate:o,invokerSetState:r,state:u});var y=n.onStateChanged,h=n.config.onStateChanged;(y||h)&&(null==y||y(s),null==h||h(s))}},this.getStoreActionsMap=function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).invokerSetState;if(!n.actionsConfig)return null;var e=n.actionsConfig,r=n.setMetadata,o=e,i=Object.keys(o),a=n.getSetStateWrapper({invokerSetState:t}),u=n.getState,l=n.getMetadata,f=i.reduce((function(t,e){var n,i,s;return Object.assign(t,(n={},s=function(){for(var t=o[e],n=arguments.length,i=new Array(n),c=0;c<n;c++)i[c]=arguments[c];var s=t.apply(f,i);return"function"!=typeof s&&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),s.call(f,{setState:a,getState:u,setMetadata:r,getMetadata:l,actions:f})},(i=c(i=e))in n?Object.defineProperty(n,i,{value:s,enumerable:!0,configurable:!0,writable:!0}):n[i]=s,n)),t}),{});return f},this.stateWrapper={state:r},this.config=Object.assign({metadata:null},null!=i?i:{}),this.constructor!==t||this.initialize()}var r,n;return r=t,(n=[{key:"state",get:function(){return this.stateWrapper.state}},{key:"getStateOrchestrator",value:function(t){return this.actionsConfig?this.getStoreActionsMap({invokerSetState:t}):this.getSetStateWrapper({invokerSetState:t})}}])&&u(r.prototype,n),Object.defineProperty(r,"prototype",{writable:!1}),t}();e.GlobalStore=s},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.debounce=e.shallowCompare=void 0;var c=r(684);e.shallowCompare=function(t,e){if(t===e)return!0;var r=u(t),i=u(e);if(r!==i)return!1;if((0,c.isPrimitive)(t)&&(0,c.isPrimitive)(e)||(0,c.isDate)(t)&&(0,c.isDate)(e)||"function"===r&&"function"===i)return t===e;if(Array.isArray(t)){var a=t,l=e;if(a.length!==l.length)return!1;for(var f=0;f<a.length;f++)if(a[f]!==l[f])return!1}if(t instanceof Map){var s=t,p=e;if(s.size!==p.size)return!1;var v,y=o(s);try{for(y.s();!(v=y.n()).done;){var h=n(v.value,2),d=h[0];if(h[1]!==p.get(d))return!1}}catch(t){y.e(t)}finally{y.f()}}if(t instanceof Set){var b=t,g=e;if(b.size!==g.size)return!1;var m,S=o(b);try{for(S.s();!(m=S.n()).done;){var w=m.value;if(!g.has(w))return!1}}catch(t){S.e(t)}finally{S.f()}}var O=Object.keys(t),j=Object.keys(e);if(O.length!==j.length)return!1;for(var x=0,A=O;x<A.length;x++){var E=A[x];if(t[E]!==e[E])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];return e&&clearTimeout(e),e=setTimeout((function(){t.apply(void 0,o)}),r),t.apply(void 0,o)}}},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(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,c),(e=u.call(this,t,r,n)).onInit=function(t){e.onInitialize(t)},e.onStateChanged=function(t){e.onChange(t)},e}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)},684:function(t){t.exports=(()=>{"use strict";var t={991:(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(729),e)},729:(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,e){if("object"!==r(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,"string");if("object"!==r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"===r(e)?e:String(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=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)?i(t,e):void 0}}function i(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.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){return function(t){var r,i;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 a=(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(a)}if("set"===(null==t?void 0:t.$t)){var u=null!==(i=t.$v)&&void 0!==i?i:[].map((function(t){return(0,e.formatFromStore)(t)}));return new Set(u)}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)")):Object.keys(t).reduce((function(r,o){var i=t[o];return Object.assign(Object.assign({},r),n({},o,(0,e.formatFromStore)(i)))}),{})}((arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).jsonParse?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=new Set(null!=u?u:[]),f=new Set(null!=c?c:[]),s=l.size||f.size,p=null!=a?a:function(t){var e=t.key,n=t.value;if(!s)return!0;var o=f.has(e),i=l.has(r(n));return!o&&!i},v=function t(r){if((0,e.isPrimitive)(r))return r;if(Array.isArray(r))return r.map((function(e){return t(e)}));if(r instanceof Map)return{$t:"map",$v:Array.from(r.entries()).map((function(e){return t(e)}))};if(r instanceof Set)return{$t:"set",$v:Array.from(r.values()).map((function(e){return t(e)}))};if((0,e.isDate)(r))return{$t:"date",$v:r.toISOString()};if((0,e.isRegex)(r))return{$t:"regex",$v:r.toString()};if((0,e.isFunction)(r)){var o;try{o={$t:"function",$v:r.toString()}}catch(t){o={$t:"error",$v:"Error: Could not serialize function"}}return o}return r instanceof Error?{$t:"error",$v:r.message}:Object.keys(r).reduce((function(e,o){var i=r[o],a=t(i);return p({obj:r,key:o,value:a})?Object.assign(Object.assign({},e),n({},o,t(i))):e}),{})}((0,e.clone)(t));return i?JSON.stringify(v):v}}},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}(991)})()},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}));
@@ -0,0 +1,27 @@
1
+ import { StateGetter, UnsubscribeCallback, SelectorCallback, UseHookConfig, SubscribeToEmitter, StateHook } 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 combineAsyncGettersEmitter: <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;
13
+ };
14
+ }, ...args: TArguments) => [subscribe: SubscribeToEmitter<TDerivate>, getState: StateGetter<TDerivate>, 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 combineAsyncGetters: <TDerivate, TArguments extends StateGetter<unknown>[], TResults = { [K in keyof TArguments]: TArguments[K] extends () => infer TResult ? Exclude<TResult, UnsubscribeCallback> : never; }>(parameters: {
23
+ selector: SelectorCallback<TResults, TDerivate>;
24
+ config?: UseHookConfig<TDerivate> & {
25
+ delay?: number;
26
+ };
27
+ }, ...args: TArguments) => [useHook: StateHook<TDerivate, null, null>, getState: StateGetter<TDerivate>, dispose: UnsubscribeCallback];
@@ -1,15 +1,5 @@
1
- import { ActionCollectionConfig, StateSetter, GlobalStoreConfig, ActionCollectionResult, StateConfigCallbackParam, MetadataSetter, UseHookConfig, StateGetter, SubscribeCallbackConfig } from "./GlobalStore.types";
2
- type SubscriberParameters<TState> = {
3
- selector?: (state: TState) => unknown;
4
- config?: UseHookConfig<any> | SubscribeCallbackConfig<any>;
5
- currentState?: unknown;
6
- };
7
- type SubscriptionCallback = (params: {
8
- state: unknown;
9
- }) => void;
10
- type SetStateCallback = (parameters: {
11
- state: unknown;
12
- }) => void;
1
+ import { ActionCollectionConfig, StateSetter, GlobalStoreConfig, ActionCollectionResult, StateConfigCallbackParam, MetadataSetter, UseHookConfig, StateGetter, SubscribeCallbackConfig, SubscribeCallback, SelectorCallback, SetStateCallback, SubscriberParameters, SubscriptionCallback } from "./GlobalStore.types";
2
+ export declare const throwNoSubscribersWereAdded: () => never;
13
3
  /**
14
4
  * The GlobalStore class is the main class of the library and it is used to create a GlobalStore instances
15
5
  * @template {TState} TState - The type of the state object
@@ -140,13 +130,13 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
140
130
  * */
141
131
  protected setMetadata: MetadataSetter<TMetadata>;
142
132
  protected getMetadata: () => TMetadata;
143
- protected createChangesSubscriber: <TDerivate, State = TDerivate extends never ? TState : TDerivate>({ callback, selector, config, }: {
144
- selector?: (state: TState) => TDerivate;
145
- callback: (state: State) => void;
146
- config: SubscribeCallbackConfig<State>;
133
+ protected createChangesSubscriber: ({ callback, selector, config, }: {
134
+ selector?: SelectorCallback<unknown, unknown>;
135
+ callback: SubscribeCallback<unknown>;
136
+ config: SubscribeCallbackConfig<unknown>;
147
137
  }) => {
148
138
  stateWrapper: {
149
- state: State;
139
+ state: unknown;
150
140
  };
151
141
  subscription: SubscriptionCallback;
152
142
  };
@@ -182,12 +172,12 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
182
172
  * Returns a custom hook that allows to handle a global state
183
173
  * @returns {[TState, TStateSetter, TMetadata]} - The state, the state setter or the actions map, the metadata
184
174
  * */
185
- getHook: () => <State = TState>(selector?: (state: TState) => State, config?: UseHookConfig<State>) => [state: State extends null ? TState : State, setter: TStateSetter extends StateSetter<TState> ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TStateSetter>, metadata: TMetadata];
175
+ getHook: () => <State = TState>(selector?: (state: TState) => State, config?: UseHookConfig<State>) => [state: State extends null ? TState : State, setter: keyof TStateSetter extends never ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TStateSetter>, metadata: TMetadata];
186
176
  /**
187
177
  * Returns an array with the a function to get the state, the state setter or the actions map, and a function to get the metadata
188
178
  * @returns {[() => TState, TStateSetter, () => TMetadata]} - The state getter, the state setter or the actions map, the metadata getter
189
179
  * */
190
- getHookDecoupled: () => [() => TState, TStateSetter extends StateSetter<TState> ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TStateSetter>, () => TMetadata];
180
+ getHookDecoupled: () => [getter: StateGetter<TState>, setter: keyof TStateSetter extends never ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TStateSetter>, metadata: () => TMetadata];
191
181
  /**
192
182
  * returns a wrapper for the setState function that will update the state and all the subscribers
193
183
  * @param {{ invokerSetState?: SetStateCallback }} parameters - The setState function of the component that invoked the state change (optional) (default: null) this is used to updated first the component that invoked the state change
@@ -228,4 +218,3 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
228
218
  invokerSetState?: SetStateCallback;
229
219
  }) => ActionCollectionResult<TState, TMetadata, TStateSetter>;
230
220
  }
231
- export {};
@@ -0,0 +1,36 @@
1
+ import { ActionCollectionConfig, StateSetter, ActionCollectionResult, UseHookConfig, AvoidNever, UnsubscribeCallback, StateHook, StateGetter, createStateConfig, CustomGlobalHookBuilderParams, CustomGlobalHookParams, SelectorCallback, SubscribeToEmitter } from "GlobalStore.types";
2
+ /**
3
+ * Creates a global hook that can be used to access the state and actions across the application
4
+ * @param {TState} state - The initial state
5
+ * @param {{ config?: GlobalStoreConfig<TState, TMetadata, TStateSetter>; actionsConfig?: TStateSetter | null }} parameters - The configuration object (optional) (default: null)
6
+ * @param {GlobalStoreConfig<TState, TMetadata, TStateSetter>} parameters.config - The configuration object
7
+ * @param {TStateSetter | null} parameters.actionsConfig - The setter configuration object (optional) (default: null)
8
+ * @returns {} [HOOK, DECOUPLED_GETTER, DECOUPLED_SETTER] this is an array with the hook, the decoupled getState function and the decoupled setter of the state
9
+ */
10
+ export declare const createGlobalStateWithDecoupledFuncs: <TState, TMetadata = null, TActions extends ActionCollectionConfig<TState, TMetadata> = null>(state: TState, { actions, ...config }?: createStateConfig<TState, TMetadata, TActions>) => [hook: StateHook<TState, keyof TActions extends never ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TActions>, TMetadata>, getter: StateGetter<TState>, setter: keyof TActions extends never ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TActions>];
11
+ /**
12
+ * Creates a global hook that can be used to access the state and actions across the application
13
+ * @param {TState} state - The initial state of the store
14
+ * @param {{ config?: GlobalStoreConfig<TState, TMetadata, TStateSetter>; actionsConfig?: TStateSetter | null }} parameters - The configuration object of the store and the configuration object of the state setter (optional) (default: null)
15
+ * @param {GlobalStoreConfig<TState, TMetadata, TStateSetter>} parameters.config - The configuration object of the store
16
+ * @param {TStateSetter | null} parameters.actionsConfig - The configuration object of the state setter (optional) (default: null)
17
+ * @returns {} - () => [TState, Setter, TMetadata] the hook that can be used to access the state and the setter of the state
18
+ */
19
+ export declare const createGlobalState: <TState, TMetadata = null, TActions extends ActionCollectionConfig<TState, TMetadata> = null>(state: TState, config?: createStateConfig<TState, TMetadata, TActions>) => StateHook<TState, keyof TActions extends never ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TActions>, TMetadata>;
20
+ /**
21
+ * @description
22
+ * Use this function to create a custom global store.
23
+ * You can use this function to create a store with async storage.
24
+ */
25
+ export declare const createCustomGlobalStateWithDecoupledFuncs: <TInheritMetadata = null, TCustomConfig = null>({ onInitialize, onChange, }: CustomGlobalHookBuilderParams<TInheritMetadata, TCustomConfig>) => <TState, TMetadata = null, TActions extends ActionCollectionConfig<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>> = null>(state: TState, { config: customConfig, onInit, onStateChanged, ...parameters }?: CustomGlobalHookParams<TCustomConfig, TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => [hook: StateHook<TState, keyof TActions extends never ? StateSetter<TState> : ActionCollectionResult<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>>, getter: StateGetter<TState>, setter: keyof TActions extends never ? StateSetter<TState> : ActionCollectionResult<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>];
26
+ /**
27
+ * @description
28
+ * Use this function to create a custom global hook which contains a fragment of the state of another hook or a fragment
29
+ */
30
+ export declare const createDerivate: <TState, TSetter, TMetadata, TDerivate>(useHook: StateHook<TState, TSetter, TMetadata>, selector_: SelectorCallback<TState, TDerivate>, config_?: UseHookConfig<TDerivate>) => <State = TDerivate>(selector?: SelectorCallback<TDerivate, State>, config?: UseHookConfig<State>) => [state: State, setter: TSetter, metadata: TMetadata];
31
+ /**
32
+ * @description
33
+ * This function allows you to create a derivate emitter
34
+ * With this approach, you can subscribe to changes in a specific fragment or subset of the state.
35
+ */
36
+ export declare const createDerivateEmitter: <TDerivate, TGetter extends StateGetter<unknown>, TState = Exclude<ReturnType<TGetter>, UnsubscribeCallback>>(getter: TGetter, selector: SelectorCallback<TState, TDerivate>) => SubscribeToEmitter<TDerivate>;
@@ -21,6 +21,12 @@ setter: TState | ((state: TState) => TState),
21
21
  */
22
22
  forceUpdate?: boolean;
23
23
  }) => void;
24
+ /**
25
+ * @description
26
+ * The hook to use the global state
27
+ * @returns {[State, StateSetter<TState>, TMetadata]} result - the state, the setter and the metadata
28
+ */
29
+ export type StateHook<TState, TSetter, TMetadata> = <State = TState>(selector?: (state: TState) => State, config?: UseHookConfig<State>) => [state: State, setter: TSetter, metadata: TMetadata];
24
30
  /**
25
31
  * @description
26
32
  * Type that prevent ts issues with merging never with other types
@@ -213,73 +219,9 @@ export type SubscribeCallbackConfig<TState> = UseHookConfig<TState> & {
213
219
  */
214
220
  export type SubscribeCallback<TState> = (state: TState) => void;
215
221
  /**
216
- * Callback function to subscribe to a portion of the store changes
217
- * @template {TState} TState - The state type
218
- * @template {TDerivate} TDerivate - The derived state type
219
- * @param {SubscribeSelectorCallback<TState, TDerivate>} selector - the selector function to derive the state
220
- * @param {SubscribeCallback<TDerivate>} callback - the callback to execute when the derived state is changed
221
- * @param {SubscribeCallbackConfig<TDerivate>} config - the configuration object
222
- * @returns {void} result - void
223
- */
224
- export type SubscribeSelectorCallback<TState, TDerivate> = (
225
- /**
226
- * The selector function to derive the state
227
- * @param {TState} state - the current state of the store
228
- * @returns {TDerivate} result - the derived state
229
- * */
230
- selector: (state: TState) => TDerivate,
231
- /**
232
- * The callback to execute when the derived state is changed
233
- */
234
- callback: SubscribeCallback<TDerivate>,
235
- /**
236
- * The configuration object
237
- * In the configuration object you can specify a custom compare function to check if the state is changed
238
- */
239
- config?: SubscribeCallbackConfig<TDerivate>) => void;
240
- /**
241
- * Use this function to subscribe to the store changes
242
- */
243
- export type SubscribeMethod<TState> = (
244
- /**
245
- * This callback will be executed every time the state is changed
222
+ * Callback function to subscribe to the store changes from a getter
246
223
  */
247
- callback: SubscribeCallback<TState>,
248
- /**
249
- * The configuration object
250
- * In the configuration object you can specify a custom compare function to check if the state is changed
251
- */
252
- config?: SubscribeCallbackConfig<TState>) => void;
253
- export type SubscribeSelectorMethod<TState> = <TDerivate>(
254
- /**
255
- * The selector function to derive the state
256
- * @param {TState} state - the current state of the store
257
- * @returns {TDerivate} result - the derived state
258
- * */
259
- selector: (state: TState) => TDerivate,
260
- /**
261
- * This callback will be executed every time the state is changed
262
- */
263
- callback: SubscribeCallback<TDerivate>,
264
- /**
265
- * The configuration object
266
- * In the configuration object you can specify a custom compare function to check if the state is changed
267
- */
268
- config?: SubscribeCallbackConfig<TDerivate>) => void;
269
- export type SubscriberCallback<TState> = ({ subscribe, }: {
270
- /**
271
- * Current state of the store
272
- */
273
- state: TState;
274
- /**
275
- * Allow you to subscribe to the store changes
276
- */
277
- subscribe: SubscribeMethod<TState>;
278
- /**
279
- * Allow to select a derived state from the store
280
- */
281
- subscribeSelector: SubscribeSelectorMethod<TState>;
282
- }) => void;
224
+ export type SubscriberCallback<TState> = (subscribe: SubscribeToEmitter<TState>) => void;
283
225
  /**
284
226
  * Callback function to get the current state of the store or to subscribe to the store changes
285
227
  * @template TState - the type of the state
@@ -298,3 +240,67 @@ callback?: Subscription extends Subscribe ? SubscriberCallback<TState> : null) =
298
240
  * Constant value type to indicate that the getter is a subscription
299
241
  */
300
242
  export type Subscribe = true;
243
+ export type createStateConfig<TState, TMetadata, TActions extends ActionCollectionConfig<TState, TMetadata> | null = null> = {
244
+ /**
245
+ * @description
246
+ * The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
247
+ */
248
+ actions?: TActions;
249
+ } & GlobalStoreConfig<TState, TMetadata, TActions>;
250
+ export type CustomGlobalHookBuilderParams<TInheritMetadata = null, TCustomConfig = {}> = {
251
+ /**
252
+ * @description
253
+ * This function is called when the state is initialized.
254
+ */
255
+ onInitialize: ({ setState, setMetadata, getMetadata, getState, actions, }: StateConfigCallbackParam<any, TInheritMetadata>, config: TCustomConfig) => void;
256
+ /**
257
+ * @description
258
+ * This function is called when the state is changed.
259
+ */
260
+ onChange: ({ setState, setMetadata, getMetadata, getState, actions, }: StateChangesParam<any, TInheritMetadata>, config: TCustomConfig) => void;
261
+ };
262
+ export type CustomGlobalHookParams<TCustomConfig, TState, TMetadata, TActions extends ActionCollectionConfig<TState, TMetadata> | null> = {
263
+ /**
264
+ * @description
265
+ * Type of the configuration object that the custom hook will require or accept
266
+ */
267
+ config?: TCustomConfig;
268
+ /**
269
+ * @description
270
+ * The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
271
+ */
272
+ actions?: TActions;
273
+ } & GlobalStoreConfig<TState, TMetadata, TActions>;
274
+ export type SelectorCallback<TState, TDerivate> = (state: TState) => TDerivate;
275
+ /**
276
+ * @description
277
+ * Function to subscribe to the store changes
278
+ * @returns {UnsubscribeCallback} result - Function to unsubscribe from the store
279
+ */
280
+ export type SubscribeToEmitter<TState> = <TParam1 extends SubscribeCallback<TState> | SelectorCallback<TState, unknown>, TResult = ReturnType<TParam1>, TConfig = TResult extends void | null | undefined | never ? SubscribeCallbackConfig<TState> : SubscribeCallbackConfig<TResult>, TParam2 extends SubscribeCallbackConfig<TState> | SubscribeCallback<TResult> = TResult extends void | null | undefined | never ? TConfig : SubscribeCallback<TResult>, TParam3 = TResult extends void | null | undefined | never ? never : TConfig>(
281
+ /**
282
+ * @description
283
+ * The callback function to subscribe to the store changes or a selector function to derive the state
284
+ */
285
+ param1: TParam1,
286
+ /**
287
+ * @description
288
+ * The configuration object or the callback function to subscribe to the store changes
289
+ */
290
+ param2?: TParam2,
291
+ /**
292
+ * @description
293
+ * The configuration object
294
+ */
295
+ param3?: TParam3) => UnsubscribeCallback;
296
+ export type SubscriberParameters<TState> = {
297
+ selector?: (state: TState) => unknown;
298
+ config?: UseHookConfig<any> | SubscribeCallbackConfig<any>;
299
+ currentState?: unknown;
300
+ };
301
+ export type SubscriptionCallback = (params: {
302
+ state: unknown;
303
+ }) => void;
304
+ export type SetStateCallback = (parameters: {
305
+ state: unknown;
306
+ }) => void;
@@ -6,3 +6,7 @@
6
6
  * @returns {boolean} true if the values are equal, false otherwise
7
7
  */
8
8
  export declare const shallowCompare: <T>(value1: T, value2: T) => boolean;
9
+ /**
10
+ * Debounce a function.
11
+ */
12
+ export declare const debounce: <T extends (...args: any[]) => any>(callback: T, delay?: number) => (...args: Parameters<T>) => ReturnType<T>;
@@ -2,4 +2,4 @@ export * from "json-storage-formatter";
2
2
  export * from "./GlobalStore.types";
3
3
  export * from "./GlobalStore";
4
4
  export * from "./GlobalStoreAbstract";
5
- export * from "./GlobalStore.functions";
5
+ export * from "./GlobalStore.functionHooks";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-global-state-hooks",
3
- "version": "4.0.7",
3
+ "version": "5.0.0",
4
4
  "description": "This is a package to easily handling global-state across your react-native-components No-redux",
5
5
  "main": "lib/bundle.js",
6
6
  "types": "lib/index.d.ts",
@@ -55,6 +55,7 @@
55
55
  "@typescript-eslint/parser": "^4.9.1",
56
56
  "babel-loader": "^9.1.2",
57
57
  "cancelable-promise-jq": "^1.0.4",
58
+ "clean-webpack-plugin": "^4.0.0",
58
59
  "eslint": "^7.15.0",
59
60
  "eslint-config-airbnb": "^18.2.1",
60
61
  "eslint-plugin-import": "^2.22.1",
@@ -1,197 +0,0 @@
1
- import { ActionCollectionConfig, StateConfigCallbackParam, StateChangesParam, StateSetter, ActionCollectionResult, UseHookConfig, AvoidNever, GlobalStoreConfig, UnsubscribeCallback } from "GlobalStore.types";
2
- /**
3
- * Creates a global hook that can be used to access the state and actions across the application
4
- * @param {TState} state - The initial state
5
- * @param {{ config?: GlobalStoreConfig<TState, TMetadata, TStateSetter>; actionsConfig?: TStateSetter | null }} parameters - The configuration object (optional) (default: null)
6
- * @param {GlobalStoreConfig<TState, TMetadata, TStateSetter>} parameters.config - The configuration object
7
- * @param {TStateSetter | null} parameters.actionsConfig - The setter configuration object (optional) (default: null)
8
- * @returns {} [HOOK, DECOUPLED_GETTER, DECOUPLED_SETTER] this is an array with the hook, the decoupled getState function and the decoupled setter of the state
9
- */
10
- export declare const createGlobalStateWithDecoupledFuncs: <TState, TMetadata = null, TActions extends ActionCollectionConfig<TState, TMetadata> = null>(state: TState, { actions, ...config }?: {
11
- /**
12
- * @description
13
- * The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
14
- */
15
- actions?: TActions;
16
- /**
17
- * @param {StateConfigCallbackParam<TState, TMetadata> => void} metadata - the initial value of the metadata
18
- * */
19
- metadata?: TMetadata;
20
- /**
21
- * @param {StateConfigCallbackParam<TState, TMetadata> => void} onInit - callback function called when the store is initialized
22
- * @returns {void} result - void
23
- * */
24
- onInit?: (parameters: StateConfigCallbackParam<TState, TMetadata, TActions>) => void;
25
- /**
26
- * @param {StateChangesParam<TState, TMetadata> => void} onStateChanged - callback function called every time the state is changed
27
- * @returns {void} result - void
28
- */
29
- onStateChanged?: (parameters: StateChangesParam<TState, TMetadata, TActions>) => void;
30
- /**
31
- * @param {StateConfigCallbackParam<TState, TMetadata> => void} onSubscribed - callback function called every time a component is subscribed to the store
32
- * @returns {void} result - void
33
- */
34
- onSubscribed?: (parameters: StateConfigCallbackParam<TState, TMetadata, TActions>) => void;
35
- /**
36
- * @param {StateChangesParam<TState, TMetadata> => boolean} computePreventStateChange - callback function called every time the state is about to change and it allows you to prevent the state change
37
- * @returns {boolean} result - true if you want to prevent the state change, false otherwise
38
- */
39
- computePreventStateChange?: (parameters: StateChangesParam<TState, TMetadata, TActions>) => boolean;
40
- }) => [useState: <State = TState>(selector?: (state: TState) => State, config?: UseHookConfig<State>) => [State extends null ? TState : State, TActions extends StateSetter<TState> ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TActions>, TMetadata], getter: <Subscription extends boolean = false>(callback?: Subscription extends true ? ({ state, subscribe, subscribeSelector, }: {
41
- state: TState;
42
- subscribe: (callback: (state: TState) => void, config?: {
43
- /**
44
- * The callback to execute when the state is changed to check if the same really changed
45
- * If the function is not provided the derived state will perform a shallow comparison
46
- */
47
- isEqual?: (current: TState, next: TState) => boolean;
48
- /**
49
- * By default the callback is executed immediately after the subscription
50
- */
51
- skipFirst?: boolean;
52
- }) => void;
53
- subscribeSelector: <TDerivate>(selector: (state: TState) => TDerivate, callback: (state: TDerivate) => void, config?: {
54
- /**
55
- * The callback to execute when the state is changed to check if the same really changed
56
- * If the function is not provided the derived state will perform a shallow comparison
57
- */
58
- isEqual?: (current: TDerivate, next: TDerivate) => boolean;
59
- /**
60
- * By default the callback is executed immediately after the subscription
61
- */
62
- skipFirst?: boolean;
63
- }) => void;
64
- }) => void : null) => Subscription extends false ? TState : UnsubscribeCallback, setter: TActions extends null ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TActions>];
65
- /**
66
- * Creates a global hook that can be used to access the state and actions across the application
67
- * @param {TState} state - The initial state of the store
68
- * @param {{ config?: GlobalStoreConfig<TState, TMetadata, TStateSetter>; actionsConfig?: TStateSetter | null }} parameters - The configuration object of the store and the configuration object of the state setter (optional) (default: null)
69
- * @param {GlobalStoreConfig<TState, TMetadata, TStateSetter>} parameters.config - The configuration object of the store
70
- * @param {TStateSetter | null} parameters.actionsConfig - The configuration object of the state setter (optional) (default: null)
71
- * @returns {} - () => [TState, Setter, TMetadata] the hook that can be used to access the state and the setter of the state
72
- */
73
- export declare const createGlobalState: <TState, TMetadata = null, TActions extends ActionCollectionConfig<TState, TMetadata> = null>(state: TState, config?: {
74
- /**
75
- * @description
76
- * The type of the actionsConfig object (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
77
- */
78
- actions?: TActions;
79
- /**
80
- * @param {StateConfigCallbackParam<TState, TMetadata> => void} metadata - the initial value of the metadata
81
- * */
82
- metadata?: TMetadata;
83
- /**
84
- * @param {StateConfigCallbackParam<TState, TMetadata> => void} onInit - callback function called when the store is initialized
85
- * @returns {void} result - void
86
- * */
87
- onInit?: (parameters: StateConfigCallbackParam<TState, TMetadata, TActions>) => void;
88
- /**
89
- * @param {StateChangesParam<TState, TMetadata> => void} onStateChanged - callback function called every time the state is changed
90
- * @returns {void} result - void
91
- */
92
- onStateChanged?: (parameters: StateChangesParam<TState, TMetadata, TActions>) => void;
93
- /**
94
- * @param {StateConfigCallbackParam<TState, TMetadata> => void} onSubscribed - callback function called every time a component is subscribed to the store
95
- * @returns {void} result - void
96
- */
97
- onSubscribed?: (parameters: StateConfigCallbackParam<TState, TMetadata, TActions>) => void;
98
- /**
99
- * @param {StateChangesParam<TState, TMetadata> => boolean} computePreventStateChange - callback function called every time the state is about to change and it allows you to prevent the state change
100
- * @returns {boolean} result - true if you want to prevent the state change, false otherwise
101
- */
102
- computePreventStateChange?: (parameters: StateChangesParam<TState, TMetadata, TActions>) => boolean;
103
- }) => <State = TState>(selector?: (state: TState) => State, config?: UseHookConfig<State>) => [state: State extends null ? TState : State, setter: TActions extends null ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TActions>, metadata: TMetadata];
104
- export type CustomGlobalHookParams<TInheritMetadata = null, TCustomConfig = {}> = {
105
- /**
106
- * @description
107
- * This function is called when the state is initialized.
108
- */
109
- onInitialize: ({ setState, setMetadata, getMetadata, getState, actions, }: StateConfigCallbackParam<any, TInheritMetadata>, config: TCustomConfig) => void;
110
- /**
111
- * @description
112
- * This function is called when the state is changed.
113
- */
114
- onChange: ({ setState, setMetadata, getMetadata, getState, actions, }: StateChangesParam<any, TInheritMetadata>, config: TCustomConfig) => void;
115
- };
116
- /**
117
- * @description
118
- * Use this function to create a custom global store.
119
- * You can use this function to create a store with async storage.
120
- */
121
- export declare const createCustomGlobalStateWithDecoupledFuncs: <TInheritMetadata = null, TCustomConfig = null>({ onInitialize, onChange, }: CustomGlobalHookParams<TInheritMetadata, TCustomConfig>) => <TState, TMetadata = null, TActions extends ActionCollectionConfig<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>> = null>(state: TState, { config: customConfig, actions, metadata, onInit, onStateChanged, onSubscribed, computePreventStateChange, }?: {
122
- config?: TCustomConfig;
123
- actions?: TActions;
124
- metadata?: TMetadata;
125
- onInit?: (parameters: StateConfigCallbackParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => void;
126
- onStateChanged?: (parameters: StateChangesParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => void;
127
- onSubscribed?: (parameters: StateConfigCallbackParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => void;
128
- computePreventStateChange?: (parameters: StateChangesParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => boolean;
129
- }) => [useState: <State = TState>(selector?: (state: TState) => State, config?: UseHookConfig<State>) => [State extends null ? TState : State, TActions extends null ? StateSetter<TState> : ActionCollectionResult<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>], getter: <Subscription extends boolean = false>(callback?: Subscription extends true ? ({ state, subscribe, subscribeSelector, }: {
130
- state: TState;
131
- subscribe: (callback: (state: TState) => void, config?: {
132
- /**
133
- * The callback to execute when the state is changed to check if the same really changed
134
- * If the function is not provided the derived state will perform a shallow comparison
135
- */
136
- isEqual?: (current: TState, next: TState) => boolean;
137
- /**
138
- * By default the callback is executed immediately after the subscription
139
- */
140
- skipFirst?: boolean;
141
- }) => void;
142
- subscribeSelector: <TDerivate>(selector: (state: TState) => TDerivate, callback: (state: TDerivate) => void, config?: {
143
- /**
144
- * The callback to execute when the state is changed to check if the same really changed
145
- * If the function is not provided the derived state will perform a shallow comparison
146
- */
147
- isEqual?: (current: TDerivate, next: TDerivate) => boolean;
148
- /**
149
- * By default the callback is executed immediately after the subscription
150
- */
151
- skipFirst?: boolean;
152
- }) => void;
153
- }) => void : null) => Subscription extends false ? TState : UnsubscribeCallback, setter: TActions extends null ? StateSetter<TState> : ActionCollectionResult<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>];
154
- /**
155
- * @description
156
- * Use this function to create a custom global store.
157
- * You can use this function to create a store with async storage.
158
- * This function will return a hook that you can use to access the store.
159
- * @param state The initial state of the store.
160
- * @param config The configuration of the store.
161
- * @returns {[TState, TStateSetter, TMetadata]} The state, the state setter and the metadata of the store.
162
- */
163
- export declare const createCustomGlobalState: <TInheritMetadata = null, TCustomConfig = {}>({ onInitialize, onChange, }: CustomGlobalHookParams<TInheritMetadata, TCustomConfig>) => <TState, TMetadata = null, TActions extends ActionCollectionConfig<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>> = null>(state: TState, { config: customConfig, actions, metadata, onInit, onStateChanged, onSubscribed, computePreventStateChange, }?: {
164
- /**
165
- * Configuration of the custom global store
166
- */
167
- config?: TCustomConfig;
168
- /**
169
- * @description
170
- * (optional) (default: null) if a configuration is passed, the hook will return an object with the actions then all the store manipulation will be done through the actions
171
- */
172
- actions?: TActions;
173
- /**
174
- * @param {StateConfigCallbackParam<TState, TMetadata> => void} metadata - the initial value of the metadata
175
- * */
176
- metadata?: TMetadata;
177
- /**
178
- * @param {StateConfigCallbackParam<TState, TMetadata> => void} onInit - callback function called when the store is initialized
179
- * @returns {void} result - void
180
- * */
181
- onInit?: (parameters: StateConfigCallbackParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => void;
182
- /**
183
- * @param {StateChangesParam<TState, TMetadata> => void} onStateChanged - callback function called every time the state is changed
184
- * @returns {void} result - void
185
- */
186
- onStateChanged?: (parameters: StateChangesParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => void;
187
- /**
188
- * @param {StateConfigCallbackParam<TState, TMetadata> => void} onSubscribed - callback function called every time a component is subscribed to the store
189
- * @returns {void} result - void
190
- */
191
- onSubscribed?: (parameters: StateConfigCallbackParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => void;
192
- /**
193
- * @param {StateChangesParam<TState, TMetadata> => boolean} computePreventStateChange - callback function called every time the state is about to change and it allows you to prevent the state change
194
- * @returns {boolean} result - true if you want to prevent the state change, false otherwise
195
- */
196
- computePreventStateChange?: (parameters: StateChangesParam<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>) => boolean;
197
- }) => <State = TState>(selector?: (state: TState) => State, config?: UseHookConfig<State>) => [state: State extends null ? TState : State, setter: TActions extends null ? StateSetter<TState> : ActionCollectionResult<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>, metadata: (TInheritMetadata extends null ? {} : TInheritMetadata) & (TMetadata extends null ? {} : TMetadata)];