react-hooks-global-states 2.0.2 → 2.1.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 +267 -229
- package/lib/bundle.js +1 -1
- package/lib/src/GlobalStore.d.ts +12 -2
- package/lib/src/GlobalStore.functionHooks.d.ts +5 -7
- package/lib/src/GlobalStore.types.d.ts +27 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,17 +49,17 @@ import { createGlobalState } from 'react-hooks-global-states';
|
|
|
49
49
|
|
|
50
50
|
export const useContacts = createGlobalState({
|
|
51
51
|
isLoading: true,
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
entities: Contact[],
|
|
53
|
+
selected: Set<number>,
|
|
54
54
|
});
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
Now, let's say we want to
|
|
58
|
-
|
|
59
|
-
**FilterBar.tsx**
|
|
57
|
+
Now, let's say we have a situation where we want to access only the list of contacts. We don't care about the rest of the state.
|
|
60
58
|
|
|
61
59
|
```tsx
|
|
62
|
-
|
|
60
|
+
// That's it. With that simple selector, we now get the list of contacts,
|
|
61
|
+
// and the component will only re-render if the property **entities** changes on the global state
|
|
62
|
+
const [contacts] = useContacts((state) => state.entities]);
|
|
63
63
|
|
|
64
64
|
return (
|
|
65
65
|
<ul>
|
|
@@ -70,9 +70,92 @@ return (
|
|
|
70
70
|
);
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
What about special cases, like when you have a map instead of an array and want to extract a list of contacts? It's common to use selectors that return a new array, but this can cause React to re-render because the new array has a different reference than the previous one.
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
export const useContacts = createGlobalState({
|
|
77
|
+
isLoading: true,
|
|
78
|
+
entities: Map<number, Contact>,
|
|
79
|
+
selected: Set<number>,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// The selector is simply a standard selector used to extract the values from the map.
|
|
83
|
+
|
|
84
|
+
const [contacts] = useContacts((state) => [...state.entities.values()], {
|
|
85
|
+
// The isEqualRoots function allows you to create your own validation logic for determining when to recompute the selector.
|
|
86
|
+
isEqualRoot: (a, b) => a.entities === b.entities,
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Okay, everything works when the changes come from the state, but what happens if I want to recompute the selector based on the internal state of the component?
|
|
74
91
|
|
|
75
|
-
|
|
92
|
+
**component.ts**
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
const [filter, setFilter] = useState('');
|
|
96
|
+
|
|
97
|
+
const [contacts] = useContacts(
|
|
98
|
+
(state) => [...state.entities.values()].filter((item) => item.name.includes(filter)),
|
|
99
|
+
{
|
|
100
|
+
isEqualRoot: (a, b) => a.entities === b.entities,
|
|
101
|
+
/**
|
|
102
|
+
* Easy to understand, right? With the dependencies prop, you can,
|
|
103
|
+
* just like with any other hook, provide a collection of values that will be compared during each render cycle
|
|
104
|
+
* to determine if the selector should be recomputed.*/
|
|
105
|
+
dependencies: [filter],
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
And finally, what if you need to reuse this selector throughout your application and don't want to duplicate code?
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
export const useContacts = createGlobalState({
|
|
114
|
+
isLoading: true,
|
|
115
|
+
entities: Map<number, Contact>,
|
|
116
|
+
selected: Set<number>,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const useContactsArray = useContacts.createSelectorHook((state) => [...state.entities.values()], {
|
|
120
|
+
isEqualRoot: (a, b) => a.entities === b.entities,
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Now inside your component just call the new hook
|
|
125
|
+
|
|
126
|
+
**component.ts**
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
const [filter, setFilter] = useState('');
|
|
130
|
+
|
|
131
|
+
const [contacts] = useContactsArray((entities) => entities.name.includes(filter), {
|
|
132
|
+
dependencies: [filter],
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Or you can create another selectorHook from your **useContactsArray**
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
const useContactsArray = useContacts.createSelectorHook((state) => [...state.entities.values()], {
|
|
140
|
+
isEqualRoot: (a, b) => a.entities === b.entities,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const useContactsLength = useContactsArray.createSelectorHook((entities) => entities.length);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Or you can create a custom hook
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
const useFilteredContacts = (filter: string) => {
|
|
150
|
+
const [contacts] = useContactsArray((entities) => entities.name.includes(filter), {
|
|
151
|
+
dependencies: [filter],
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return contacts;
|
|
155
|
+
};
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
To summarize
|
|
76
159
|
|
|
77
160
|
```tsx
|
|
78
161
|
const [filter, setFilter] = useState('');
|
|
@@ -109,7 +192,7 @@ return (
|
|
|
109
192
|
);
|
|
110
193
|
```
|
|
111
194
|
|
|
112
|
-
If you want to perform a shallow comparison between the previous and new values, you can use the **shallowCompare** function from the library.
|
|
195
|
+
Btw, If you want to perform a shallow comparison between the previous and new values, you can use the **shallowCompare** function from the library.
|
|
113
196
|
|
|
114
197
|
```TSX
|
|
115
198
|
({
|
|
@@ -120,27 +203,23 @@ If you want to perform a shallow comparison between the previous and new values,
|
|
|
120
203
|
})
|
|
121
204
|
```
|
|
122
205
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
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?
|
|
206
|
+
Just remember, you can select or derive different values from the global state endlessly, but the state mutator will remain the same throughout the hooks.
|
|
126
207
|
|
|
127
|
-
|
|
208
|
+
More examples:
|
|
128
209
|
|
|
129
210
|
```ts
|
|
130
|
-
const useFilter =
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
Well, that's it! Now you can simply call **useFilter** inside your component, and everything will continue to work the same.
|
|
211
|
+
const useFilter = useContacts.createSelectorHook(({ filter }) => filter);
|
|
134
212
|
|
|
135
|
-
|
|
213
|
+
const useContactsArray = useContacts.createSelectorHook(({ items }) => items);
|
|
136
214
|
|
|
137
|
-
|
|
138
|
-
const [{ filter }, setState] = useFilter();
|
|
215
|
+
const useContactsLength = useContactsArray.createSelectorHook((items) => items.length);
|
|
139
216
|
|
|
140
|
-
|
|
217
|
+
const useIsContactsEmpty = useContactsLength.createSelectorHook((length) => !length);
|
|
141
218
|
```
|
|
142
219
|
|
|
143
|
-
|
|
220
|
+
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.
|
|
221
|
+
|
|
222
|
+
Each selector hook is reactive only to the fragment/derived of the state returned by the selector. And again you can optimize it by using the **isEqualRoot** and **isEqual** functions, which help avoid recomputing the selector if the root state or the fragment hasn't changed.
|
|
144
223
|
|
|
145
224
|
# State actions
|
|
146
225
|
|
|
@@ -170,7 +249,7 @@ export const useContacts = createGlobalState(initialState, {
|
|
|
170
249
|
}));
|
|
171
250
|
};
|
|
172
251
|
},
|
|
173
|
-
} as const,
|
|
252
|
+
} as const, // as const is necessary for the correct typing
|
|
174
253
|
onInit: async ({ setState }: StoreTools<State>) => {
|
|
175
254
|
// fetch contacts
|
|
176
255
|
},
|
|
@@ -182,35 +261,19 @@ That's it! In this updated version, the **useContacts** hook will no longer retu
|
|
|
182
261
|
Let's see how that will look now into our **FilterBar.tsx**
|
|
183
262
|
|
|
184
263
|
```tsx
|
|
185
|
-
const [
|
|
264
|
+
const [filter, { setFilter }] = useFilter();
|
|
186
265
|
|
|
187
266
|
return <TextInput onChangeText={setFilter} />;
|
|
188
267
|
```
|
|
189
268
|
|
|
190
|
-
Yeah, that's it! All the **derived states** and **emitters** (we will talk about this later) will inherit the new actions interface.
|
|
269
|
+
Yeah, that's it! All the **derived states** and **emitters** (we will talk about **emitters** this later) will inherit the new actions interface.
|
|
191
270
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
```ts
|
|
195
|
-
const useFilter = createDerivate(useContacts, ({ filter }) => ({ filter }));
|
|
196
|
-
|
|
197
|
-
const useFilterString = createDerivate(useFilter, { filter } => filter);
|
|
198
|
-
|
|
199
|
-
const useContacts = createDerivate(useContacts, ({ items }) => items);
|
|
200
|
-
|
|
201
|
-
const useContactsLength = createDerivate(useContacts, (items) => items.length);
|
|
202
|
-
|
|
203
|
-
const useIsContactsEmpty = createDerivate(useContactsLength, (length) => !length);
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
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.
|
|
207
|
-
|
|
208
|
-
# Decoupled state access
|
|
271
|
+
# State Controls
|
|
209
272
|
|
|
210
273
|
If you need to access the global state outside of a component or a hook without subscribing to state changes, or even inside a **ClassComponent**, you can use:
|
|
211
274
|
|
|
212
275
|
```tsx
|
|
213
|
-
|
|
276
|
+
useContacts.stateControls: () => [stateRetriever: StateGetter<State>, stateMutator: Setter<State>|ActionCollectionResult<State>, metadataRetriever: Metadata];
|
|
214
277
|
|
|
215
278
|
// example:
|
|
216
279
|
const [getContacts, setContacts] = useContacts.stateControls();
|
|
@@ -220,30 +283,9 @@ console.log(getContacts()); // prints the list of contacts
|
|
|
220
283
|
|
|
221
284
|
**stateMutator** is particularly useful when you want to create components that have editing access to a specific store but don't necessarily need to reactively respond to state changes.
|
|
222
285
|
|
|
223
|
-
Using the **stateRetriever** and the **stateMutator** allows you to retrieve the state when needed without establishing a reactive relationship with the state changes. This approach provides more flexibility and control over when and how components interact with the global state.
|
|
224
|
-
|
|
225
|
-
```ts
|
|
226
|
-
import { createGlobalState } from 'react-hooks-global-states';
|
|
227
|
-
|
|
228
|
-
export const useContacts = createGlobalState({
|
|
229
|
-
isLoading: true,
|
|
230
|
-
filter: '',
|
|
231
|
-
items: [] as Contact[],
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
export const [contactsRetriever, contactsMutator] = useContacts.stateControls();
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
That's great! With the addition of the **contactsRetriever** and **contactsMutator** methods, you now have the ability to access and modify the state without the need for subscription to the hook.
|
|
238
|
-
|
|
239
|
-
While **useContacts** will allow your components to subscribe to the custom hook, using the **contactsRetriever** method you will be able retrieve the current value of the state. This allows you to access the state whenever necessary, without being reactive to its changes. Let' see how:
|
|
240
|
-
|
|
241
|
-
```ts
|
|
242
|
-
// To synchronously get the value of the state
|
|
243
|
-
const value = contactsRetriever();
|
|
286
|
+
Using the **stateRetriever** and the **stateMutator** allows you to retrieve the state when needed without establishing a reactive relationship with the state changes. This approach provides more flexibility and control over when and how components interact with the global state.
|
|
244
287
|
|
|
245
|
-
|
|
246
|
-
```
|
|
288
|
+
So, While **useContacts** will allow your components to subscribe to the custom hook, using the **contactsRetriever** method you will be able retrieve the current value of the state. This allows you to access the state whenever necessary, without being reactive to its changes and with the **contactsMutator** you now have the ability to modify the state without the need for subscription to the hook.
|
|
247
289
|
|
|
248
290
|
Additionally, to subscribe to state changes, you can pass a callback function as a parameter to the **stateRetriever**. This approach enables you to create a subscription group, allowing you to subscribe to either the entire state or a specific portion of it. When a callback function is provided to the **stateRetriever**, it will return a cleanup function instead of the state. This cleanup function can be used to unsubscribe or clean up the subscription when it is no longer needed.
|
|
249
291
|
|
|
@@ -268,9 +310,158 @@ const removeSubscriptionGroup = contactsRetriever<Subscribe>((subscribe) => {
|
|
|
268
310
|
|
|
269
311
|
That's great, isn't it? everything stays synchronized with the original state!!
|
|
270
312
|
|
|
313
|
+
## stateMutator
|
|
314
|
+
|
|
315
|
+
Let's add more actions to the state and explore how to use one action from inside another.
|
|
316
|
+
|
|
317
|
+
Here's an example of adding multiple actions to the state and utilizing one action within another:
|
|
318
|
+
|
|
319
|
+
```ts
|
|
320
|
+
import { createGlobalState } from 'react-hooks-global-states';
|
|
321
|
+
|
|
322
|
+
export const useCount = createGlobalState(0, {
|
|
323
|
+
actions: {
|
|
324
|
+
log: (currentValue: string) => {
|
|
325
|
+
return ({ getState }: StoreTools<number>): void => {
|
|
326
|
+
console.log(`Current Value: ${getState()}`);
|
|
327
|
+
};
|
|
328
|
+
},
|
|
329
|
+
|
|
330
|
+
increase(value: number = 1) {
|
|
331
|
+
return ({ getState, setState, actions }: StoreTools<number>) => {
|
|
332
|
+
setState((count) => count + value);
|
|
333
|
+
|
|
334
|
+
actions.log(message);
|
|
335
|
+
};
|
|
336
|
+
},
|
|
337
|
+
|
|
338
|
+
decrease(value: number = 1) {
|
|
339
|
+
return ({ getState, setState, actions }: StoreTools<number>) => {
|
|
340
|
+
setState((count) => count - value);
|
|
341
|
+
|
|
342
|
+
actions.log(message);
|
|
343
|
+
};
|
|
344
|
+
},
|
|
345
|
+
} as const,
|
|
346
|
+
});
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
Notice that the **StoreTools** will contain a reference to the generated actions API. From there, you'll be able to access all actions from inside another one... the **StoreTools** is generic and allow your to set an interface for getting the typing on the actions.
|
|
350
|
+
|
|
351
|
+
# Stateful Context with Actions
|
|
352
|
+
|
|
353
|
+
**The ultimate blend of flexibility and control in React state management!** You can now create an isolated global state within a React context, giving each consumer of the context provider a unique state instance. But that’s not all...
|
|
354
|
+
|
|
355
|
+
**Stateful Context with Actions** extends the powerful features of global hooks into the realm of React Context. By integrating global hooks within a context, you bring all the benefits of global state management—such as modularity, selectors, derived states, and actions—into a context-specific environment. This means each consumer of the context not only gets a unique state instance but also inherits all the advanced capabilities of global hooks.
|
|
356
|
+
|
|
357
|
+
## Creating a Stateful Context
|
|
358
|
+
|
|
359
|
+
Forget about the boilerplate of creating a context... with **createStatefulContext** it's straightforward and powerful. You can create a context and provider with one line of code.
|
|
360
|
+
|
|
361
|
+
```tsx
|
|
362
|
+
export const [useCounterContext, CounterProvider] = createStatefulContext(2);
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
Then just wrap the components you need with the provider:
|
|
366
|
+
|
|
367
|
+
```tsx
|
|
368
|
+
<CounterProvider>
|
|
369
|
+
<MyComponent />
|
|
370
|
+
</CounterProvider>
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
And finally, access the context value with the generated custom hook:
|
|
374
|
+
|
|
375
|
+
```tsx
|
|
376
|
+
const MyComponent = () => {
|
|
377
|
+
const [useCounter] = useCounterContext();
|
|
378
|
+
|
|
379
|
+
// If the component needs to react to state changes, simply use the hook
|
|
380
|
+
const [count, setCount] = useCounter();
|
|
381
|
+
|
|
382
|
+
return <>{count}</>;
|
|
383
|
+
};
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
What’s the advantage of this, you might ask? Well, now you have all the capabilities of the global hooks within the isolated scope of the context. For example, you can choose whether or not to listen to changes in the state:
|
|
387
|
+
|
|
388
|
+
```tsx
|
|
389
|
+
const MyComponent = () => {
|
|
390
|
+
const [, , setCount] = useCounterContext();
|
|
391
|
+
|
|
392
|
+
// This component can access only the stateMutator of the state,
|
|
393
|
+
// and won't re-render if the counter changes
|
|
394
|
+
return <button onClick={() => setCount((count) => count + 1)}>Increase</button>;
|
|
395
|
+
};
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
Now you have selectors—if the state changes, the component will only re-render if the selected portion of the state changes.
|
|
399
|
+
|
|
400
|
+
```tsx
|
|
401
|
+
const MyComponent = () => {
|
|
402
|
+
const [useCounter] = useCounterContext();
|
|
403
|
+
|
|
404
|
+
// Notice that we can select and derive values from the state
|
|
405
|
+
const [isEven, setCount] = useCounter((count) => count % 2 === 0);
|
|
406
|
+
|
|
407
|
+
useEffect(() => {
|
|
408
|
+
// Since the counter initially was 2 and now is 4, it’s still an even number.
|
|
409
|
+
// Because of this, the component will not re-render.
|
|
410
|
+
setCount(4);
|
|
411
|
+
}, []);
|
|
412
|
+
|
|
413
|
+
return <>{isEven ? 'is even' : 'is odd'}</>;
|
|
414
|
+
};
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
**createStatefulContext** also allows you to add custom actions to control the manipulation of the state.
|
|
418
|
+
|
|
419
|
+
```tsx
|
|
420
|
+
import { createStatefulContext, StoreTools } from 'react-global-state-hooks';
|
|
421
|
+
|
|
422
|
+
type CounterState = {
|
|
423
|
+
count: number;
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
const initialState: CounterState = {
|
|
427
|
+
count: 0,
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
export const [useCounterContext, CounterProvider] = createStatefulContext(initialState, {
|
|
431
|
+
actions: {
|
|
432
|
+
increase: (value: number = 1) => {
|
|
433
|
+
return ({ setState }: StoreTools<CounterState>) => {
|
|
434
|
+
setState((state) => ({
|
|
435
|
+
...state,
|
|
436
|
+
count: state.count + value,
|
|
437
|
+
}));
|
|
438
|
+
};
|
|
439
|
+
},
|
|
440
|
+
decrease: (value: number = 1) => {
|
|
441
|
+
return ({ setState }: StoreTools<CounterState>) => {
|
|
442
|
+
setState((state) => ({
|
|
443
|
+
...state,
|
|
444
|
+
count: state.count - value,
|
|
445
|
+
}));
|
|
446
|
+
};
|
|
447
|
+
},
|
|
448
|
+
} as const,
|
|
449
|
+
});
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
And just like with regular global hooks, now instead of a setState function, the hook will return the collection of actions:
|
|
453
|
+
|
|
454
|
+
```tsx
|
|
455
|
+
const MyComponent = () => {
|
|
456
|
+
const [, , actions] = useCounterContext();
|
|
457
|
+
|
|
458
|
+
return <button onClick={() => actions.increase(1)}>Increase</button>;
|
|
459
|
+
};
|
|
460
|
+
```
|
|
461
|
+
|
|
271
462
|
# Emitters
|
|
272
463
|
|
|
273
|
-
So, we have seen that we can subscribe a callback to state changes, create **
|
|
464
|
+
So, we have seen that we can subscribe a callback to state changes, create **selector hooks** from our global states. Guess what? We can also create derived **emitters** and subscribe callbacks to specific portions of the state. Let's review it:
|
|
274
465
|
|
|
275
466
|
```ts
|
|
276
467
|
const subscribeToFilter = createDerivateEmitter(contactsRetriever, ({ filter }) => ({
|
|
@@ -301,7 +492,7 @@ const removeFilterSubscription = subscribeToFilter<Subscribe>(
|
|
|
301
492
|
);
|
|
302
493
|
```
|
|
303
494
|
|
|
304
|
-
Also, of course, if you have an exceptional case where you want to
|
|
495
|
+
Also, of course, if you have an exceptional case where you want to derived/selected directly from the current **emitter**, you can add a **selector**. This allows you to fine-tune the emitted values based on your requirements
|
|
305
496
|
|
|
306
497
|
```ts
|
|
307
498
|
const removeFilterSubscription = subscribeToFilter<Subscribe>(
|
|
@@ -332,7 +523,7 @@ const subscribeToItems = createDerivateEmitter(contactsRetriever, ({ items }) =>
|
|
|
332
523
|
const subscribeToItemsLength = createDerivateEmitter(subscribeToItems, (items) => items.length);
|
|
333
524
|
```
|
|
334
525
|
|
|
335
|
-
The examples may seem a little silly, but they allow you to see the incredible things you can accomplish with these **
|
|
526
|
+
The examples may seem a little silly, but they allow you to see the incredible things you can accomplish with these **derived states** and **emitters**. They open up a world of possibilities!
|
|
336
527
|
|
|
337
528
|
# Combining stateRetriever
|
|
338
529
|
|
|
@@ -340,7 +531,7 @@ What if you have two states and you want to combine them? You may have already g
|
|
|
340
531
|
|
|
341
532
|
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:
|
|
342
533
|
|
|
343
|
-
First we are gonna create a couple of **global states**, and extract the **stateRetriever**.
|
|
534
|
+
First we are gonna create a couple of **global states**, and extract the **stateRetriever**.
|
|
344
535
|
|
|
345
536
|
```ts
|
|
346
537
|
const useHook1 = createGlobalState({
|
|
@@ -361,7 +552,7 @@ const [, stateRetriever2] = useHook2.stateControls();
|
|
|
361
552
|
Okay, cool, the first state as **propA, propB** while the second one has **propC, propD**, let's combine them:
|
|
362
553
|
|
|
363
554
|
```ts
|
|
364
|
-
const [useCombinedHook,
|
|
555
|
+
const [useCombinedHook, combinedStateRetriever] = combineAsyncGetters(
|
|
365
556
|
{
|
|
366
557
|
selector: ([state1, state2]) => ({
|
|
367
558
|
...state1,
|
|
@@ -373,7 +564,7 @@ const [useCombinedHook, stateRetriever, dispose] = combineAsyncGetters(
|
|
|
373
564
|
);
|
|
374
565
|
```
|
|
375
566
|
|
|
376
|
-
Well, that's it! Now you have access to a **
|
|
567
|
+
Well, that's it! Now you have access to a **combinedStateRetriever** that will return the combined value of the two states. From this new **combinedStateRetriever**, you can retrieve the value or subscribe to its changes. Let'see:
|
|
377
568
|
|
|
378
569
|
```ts
|
|
379
570
|
const value = stateRetriever(); // { propA, propB, propC, propD }
|
|
@@ -388,8 +579,8 @@ const unsubscribeGroup = stateRetriever<Subscribe>((subscribe) => {
|
|
|
388
579
|
// the callback will only trigger if the result of the selector changes.
|
|
389
580
|
subscribe(
|
|
390
581
|
({ propA, propD }) => ({ propA, propD }),
|
|
391
|
-
(
|
|
392
|
-
console.log(
|
|
582
|
+
(derived) => {
|
|
583
|
+
console.log(derived); // { propA, propD }
|
|
393
584
|
}
|
|
394
585
|
);
|
|
395
586
|
});
|
|
@@ -416,7 +607,7 @@ Lastly, you have the flexibility to continue combining stateRetrievers if desire
|
|
|
416
607
|
Let's see an example:
|
|
417
608
|
|
|
418
609
|
```ts
|
|
419
|
-
const [useCombinedHook, combinedStateRetriever1
|
|
610
|
+
const [useCombinedHook, combinedStateRetriever1] = combineAsyncGetters(
|
|
420
611
|
{
|
|
421
612
|
selector: ([state1, state2]) => ({
|
|
422
613
|
...state1,
|
|
@@ -442,7 +633,7 @@ const [isLoadingStateRetriever, isLoadingMutator] = useIsLoading.stateControls()
|
|
|
442
633
|
Once we created another peace of state, we can combine it with our other **global hooks** and **emitters**
|
|
443
634
|
|
|
444
635
|
```ts
|
|
445
|
-
const [useCombinedHook2, combinedStateRetriever2
|
|
636
|
+
const [useCombinedHook2, combinedStateRetriever2] = combineAsyncGetters(
|
|
446
637
|
{
|
|
447
638
|
selector: ([state1, state2, isLoading]) => ({
|
|
448
639
|
...state1,
|
|
@@ -462,159 +653,6 @@ You have the freedom to combine as many global hooks as you wish. This means you
|
|
|
462
653
|
|
|
463
654
|
Please be aware that the third parameter is a **dispose callback**, which can be particularly useful in **higher-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.
|
|
464
655
|
|
|
465
|
-
## stateMutator
|
|
466
|
-
|
|
467
|
-
Similarly, the **contactsMutator** 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**.
|
|
468
|
-
|
|
469
|
-
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.
|
|
470
|
-
|
|
471
|
-
Let's add more actions to the state and explore how to use one action from inside another.
|
|
472
|
-
|
|
473
|
-
Here's an example of adding multiple actions to the state and utilizing one action within another:
|
|
474
|
-
|
|
475
|
-
```ts
|
|
476
|
-
import { createGlobalState } from 'react-hooks-global-states';
|
|
477
|
-
|
|
478
|
-
export const useCount = createGlobalState(0, {
|
|
479
|
-
actions: {
|
|
480
|
-
log: (currentValue: string) => {
|
|
481
|
-
return ({ getState }: StoreTools<number>): void => {
|
|
482
|
-
console.log(`Current Value: ${getState()}`);
|
|
483
|
-
};
|
|
484
|
-
},
|
|
485
|
-
|
|
486
|
-
increase(value: number = 1) {
|
|
487
|
-
return ({ getState, setState, actions }: StoreTools<number>) => {
|
|
488
|
-
setState((count) => count + value);
|
|
489
|
-
|
|
490
|
-
actions.log(message);
|
|
491
|
-
};
|
|
492
|
-
},
|
|
493
|
-
|
|
494
|
-
decrease(value: number = 1) {
|
|
495
|
-
return ({ getState, setState, actions }: StoreTools<number>) => {
|
|
496
|
-
setState((count) => count - value);
|
|
497
|
-
|
|
498
|
-
actions.log(message);
|
|
499
|
-
};
|
|
500
|
-
},
|
|
501
|
-
} as const,
|
|
502
|
-
});
|
|
503
|
-
```
|
|
504
|
-
|
|
505
|
-
Notice that the **StoreTools** will contain a reference to the generated actions API. From there, you'll be able to access all actions from inside another one... the **StoreTools** is generic and allow your to set an interface for getting the typing on the actions.
|
|
506
|
-
|
|
507
|
-
# Stateful Context with Actions
|
|
508
|
-
|
|
509
|
-
**The ultimate blend of flexibility and control in React state management!** You can now create an isolated global state within a React context, giving each consumer of the context provider a unique state instance. But that’s not all...
|
|
510
|
-
|
|
511
|
-
**Stateful Context with Actions** extends the powerful features of global hooks into the realm of React Context. By integrating global hooks within a context, you bring all the benefits of global state management—such as modularity, selectors, derived states, and actions—into a context-specific environment. This means each consumer of the context not only gets a unique state instance but also inherits all the advanced capabilities of global hooks.
|
|
512
|
-
|
|
513
|
-
## Creating a Stateful Context
|
|
514
|
-
|
|
515
|
-
Forget about the boilerplate of creating a context... with **createStatefulContext** it's straightforward and powerful. You can create a context and provider with one line of code.
|
|
516
|
-
|
|
517
|
-
```tsx
|
|
518
|
-
export const [useCounterContext, CounterProvider] = createStatefulContext(2);
|
|
519
|
-
```
|
|
520
|
-
|
|
521
|
-
Then just wrap the components you need with the provider:
|
|
522
|
-
|
|
523
|
-
```tsx
|
|
524
|
-
<CounterProvider>
|
|
525
|
-
<MyComponent />
|
|
526
|
-
</CounterProvider>
|
|
527
|
-
```
|
|
528
|
-
|
|
529
|
-
And finally, access the context value with the generated custom hook:
|
|
530
|
-
|
|
531
|
-
```tsx
|
|
532
|
-
const MyComponent = () => {
|
|
533
|
-
const [useCounter] = useCounterContext();
|
|
534
|
-
|
|
535
|
-
// If the component needs to react to state changes, simply use the hook
|
|
536
|
-
const [count, setCount] = useCounter();
|
|
537
|
-
|
|
538
|
-
return <>{count}</>;
|
|
539
|
-
};
|
|
540
|
-
```
|
|
541
|
-
|
|
542
|
-
What’s the advantage of this, you might ask? Well, now you have all the capabilities of the global hooks within the isolated scope of the context. For example, you can choose whether or not to listen to changes in the state:
|
|
543
|
-
|
|
544
|
-
```tsx
|
|
545
|
-
const MyComponent = () => {
|
|
546
|
-
const [, , setCount] = useCounterContext();
|
|
547
|
-
|
|
548
|
-
// This component can access only the stateMutator of the state,
|
|
549
|
-
// and won't re-render if the counter changes
|
|
550
|
-
return <button onClick={() => setCount((count) => count + 1)}>Increase</button>;
|
|
551
|
-
};
|
|
552
|
-
```
|
|
553
|
-
|
|
554
|
-
Now you have selectors—if the state changes, the component will only re-render if the selected portion of the state changes.
|
|
555
|
-
|
|
556
|
-
```tsx
|
|
557
|
-
const MyComponent = () => {
|
|
558
|
-
const [useCounter] = useCounterContext();
|
|
559
|
-
|
|
560
|
-
// Notice that we can select and derive values from the state
|
|
561
|
-
const [isEven, setCount] = useCounter((count) => count % 2 === 0);
|
|
562
|
-
|
|
563
|
-
useEffect(() => {
|
|
564
|
-
// Since the counter initially was 2 and now is 4, it’s still an even number.
|
|
565
|
-
// Because of this, the component will not re-render.
|
|
566
|
-
setCount(4);
|
|
567
|
-
}, []);
|
|
568
|
-
|
|
569
|
-
return <>{isEven ? 'is even' : 'is odd'}</>;
|
|
570
|
-
};
|
|
571
|
-
```
|
|
572
|
-
|
|
573
|
-
**createStatefulContext** also allows you to add custom actions to control the manipulation of the state.
|
|
574
|
-
|
|
575
|
-
```tsx
|
|
576
|
-
import { createStatefulContext, StoreTools } from 'react-global-state-hooks';
|
|
577
|
-
|
|
578
|
-
type CounterState = {
|
|
579
|
-
count: number;
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
const initialState: CounterState = {
|
|
583
|
-
count: 0,
|
|
584
|
-
};
|
|
585
|
-
|
|
586
|
-
export const [useCounterContext, CounterProvider] = createStatefulContext(initialState, {
|
|
587
|
-
actions: {
|
|
588
|
-
increase: (value: number = 1) => {
|
|
589
|
-
return ({ setState }: StoreTools<CounterState>) => {
|
|
590
|
-
setState((state) => ({
|
|
591
|
-
...state,
|
|
592
|
-
count: state.count + value,
|
|
593
|
-
}));
|
|
594
|
-
};
|
|
595
|
-
},
|
|
596
|
-
decrease: (value: number = 1) => {
|
|
597
|
-
return ({ setState }: StoreTools<CounterState>) => {
|
|
598
|
-
setState((state) => ({
|
|
599
|
-
...state,
|
|
600
|
-
count: state.count - value,
|
|
601
|
-
}));
|
|
602
|
-
};
|
|
603
|
-
},
|
|
604
|
-
} as const,
|
|
605
|
-
});
|
|
606
|
-
```
|
|
607
|
-
|
|
608
|
-
And just like with regular global hooks, now instead of a setState function, the hook will return the collection of actions:
|
|
609
|
-
|
|
610
|
-
```tsx
|
|
611
|
-
const MyComponent = () => {
|
|
612
|
-
const [, , actions] = useCounterContext();
|
|
613
|
-
|
|
614
|
-
return <button onClick={() => actions.increase(1)}>Increase</button>;
|
|
615
|
-
};
|
|
616
|
-
```
|
|
617
|
-
|
|
618
656
|
# Extending Global Hooks
|
|
619
657
|
|
|
620
658
|
Creating a global hook that connects to an asyncStorage is made incredibly easy with the **createCustomGlobalState** function.
|
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-hooks-global-states"]=e(require("react")):t["react-hooks-global-states"]=e(t.react)}(this,(t=>{return e={852:(t,e,r)=>{"use strict";function n(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,l=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(u.push(n.value),u.length!==e);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(t,e)||function(t,e){if(t){if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}Object.defineProperty(e,"__esModule",{value:!0}),e.combineRetrieverAsynchronously=e.combineAsyncGetters=e.combineRetrieverEmitterAsynchronously=e.combineAsyncGettersEmitter=void 0;var i=r(608),a=r(156),u=r(774);e.combineAsyncGettersEmitter=function(t){for(var e,r,n,o=arguments.length,a=new Array(o>1?o-1:0),c=1;c<o;c++)a[c-1]=arguments[c];var l=a,s=new Map(l.map((function(t,e){return[e,t()]}))),f=t.selector(Array.from(s.values())),v=void 0!==(null===(e=null==t?void 0:t.config)||void 0===e?void 0:e.isEqual)?null===(r=null==t?void 0:t.config)||void 0===r?void 0:r.isEqual:i.shallowCompare,p=new Set,d=(0,i.debounce)((function(){var e=t.selector(Array.from(s.values()));(null==v?void 0:v(f,e))||(f=e,p.forEach((function(t){return t()})))}),null===(n=null==t?void 0:t.config)||void 0===n?void 0:n.delay),y=l.map((function(t,e){return t((function(t){t((function(t){s.set(e,t),d()}))}))})),h=function(t,e,r){var n,o,a="function"==typeof e,u=a?t:null,c=a?e:t,l=a?r:e,s=Object.assign({delay:0,isEqual:i.shallowCompare},null!=l?l:{}),v=null!==(n=null==u?void 0:u(f))&&void 0!==n?n:f;s.skipFirst||c(v);var d=(0,i.debounce)((function(){var t,e,r=null!==(t=null==u?void 0:u(f))&&void 0!==t?t:f;(null===(e=s.isEqual)||void 0===e?void 0:e.call(s,v,r))||(v=r,c(r))}),null!==(o=s.delay)&&void 0!==o?o:0);return p.add(d),function(){p.delete(d)}};return[h,function(t){if(!t)return f;var e=[];return t((function(){e.push(h.apply(void 0,arguments))})),e.length||(0,u.throwNoSubscribersWereAdded)(),function(){e.forEach((function(t){t(),p.delete(t)}))}},function(){y.forEach((function(t){return t()}))}]},e.combineRetrieverEmitterAsynchronously=e.combineAsyncGettersEmitter,e.combineAsyncGetters=function(t){for(var r=arguments.length,o=new Array(r>1?r-1:0),u=1;u<r;u++)o[u-1]=arguments[u];var c=n(e.combineAsyncGettersEmitter.apply(void 0,[t].concat(o)),3),l=c[0],s=c[1],f=c[2];return[function(t,e){var r=n((0,a.useState)((function(){var e=s();return t?t(e):e})),2),o=r[0],u=r[1];return(0,a.useEffect)((function(){var r,n=Object.assign({delay:0,isEqual:i.shallowCompare},null!=e?e:{}),o=void 0!==n.isEqual?n.isEqual:i.shallowCompare,a=l((function(e){return t?t(e):e}),(0,i.debounce)((function(e){var r=t?t(e):e;(null==o?void 0:o(e,r))||u(r)}),null!==(r=n.delay)&&void 0!==r?r:0));return function(){a()}}),[]),[o,null,null]},s,f]},e.combineRetrieverAsynchronously=e.combineAsyncGetters},113:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createStatefulContext=void 0;var n,o=r(853),i=r(684),a=(n=r(156))&&n.__esModule?n:{default:n};e.createStatefulContext=function(t,e){var r=a.default.createContext(null);return[function(){return a.default.useContext(r)},function(n){var u=n.children,c=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}(n,["children"]),l=(0,o.createGlobalStateWithDecoupledFuncs)(function(){if(c.initialValue){if("function"==typeof c.initialValue)return c.initialValue((0,i.clone)(t));var e=Array.isArray(c.initialValue),r=c.initialValue instanceof Map,n=c.initialValue instanceof Set;return(0,i.isPrimitive)(c.initialValue)||(0,i.isDate)(c.initialValue)||e||r||n?c.initialValue:Object.assign(Object.assign({},t),c.initialValue)}return(0,i.clone)(t)}(),e);return a.default.createElement(r.Provider,{value:l},u)}]}},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],s=c[1];return[u.getHook(),l,s]},e.createGlobalState=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=n((0,e.createGlobalStateWithDecoupledFuncs)(t,r),3),i=o[0],a=o[1],u=o[2];return i.stateControls=function(){return[a,u]},i},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){(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 i(){i=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},u=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",l=a.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 d?e:d,a=Object.create(i.prototype),u=new P(n||[]);return o(a,"_invoke",{value:j(t,r,u)}),a}function v(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=f;var p={};function d(){}function y(){}function h(){}var b={};s(b,u,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(C([])));m&&m!==e&&r.call(m,u)&&(b=m);var S=h.prototype=d.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=v(t[o],t,a);if("throw"!==l.type){var s=l.arg,f=s.value;return f&&"object"==n(f)&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){i("next",t,u,c)}),(function(t){i("throw",t,u,c)})):e.resolve(f).then((function(t){s.value=t,u(s)}),(function(t){return i("throw",t,u,c)}))}c(l.arg)}var a;o(this,"_invoke",{value:function(t,r){function n(){return new e((function(e,n){i(t,r,e,n)}))}return a=a?a.then(n,n):n()}})}function j(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=A(a,r);if(u){if(u===p)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=v(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function A(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,A(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var o=v(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,p;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,p):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function E(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 x(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function C(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 y.prototype=h,o(S,"constructor",{value:h,configurable:!0}),o(h,"constructor",{value:y,configurable:!0}),y.displayName=s(h,l,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,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=C,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(x),!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,p):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),p},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),x(r),p}},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;x(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:C(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function a(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,u(n.key),n)}}function u(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 c=r(608),l=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=Symbol("unique"),f=function(){function t(r){var n=this,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},f=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=f,this.subscribers=new Map,this.actions=null,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=i().mark((function t(){var e,r,n;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.actionsConfig&&(this.actions=this.getStoreActionsMap()),e=this.onInit,r=this.config.onInit,e||r){t.next=5;break}return t.abrupt("return");case 5:n=this.getConfigCallbackParam(),null==e||e(n),null==r||r(n);case 8: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.state,r=t.forceUpdate,o=n.stateWrapper.state;n.stateWrapper={state:e};for(var i=function(t){var n,i,a=t.selector,u=t.callback,c=t.currentState,l=t.config;if(r||!(null!==(n=null==l?void 0:l.isEqualRoot)&&void 0!==n?n:function(t,e){return Object.is(t,e)})(o,e)){var s=a?a(e):e;!r&&(null!==(i=null==l?void 0:l.isEqual)&&void 0!==i?i:function(t,e){return Object.is(t,e)})(c,s)||u({state:s})}},a=Array.from(n.subscribers.values()),u=0;u<a.length;u++)i(a[u])},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,subscriptionCallback:function(t){var r=t.state;a.state=r,e(r)}}},this.getState=function(t){if(!t)return n.stateWrapper.state;var r=[];return t((function(t,e,o){var i="function"==typeof e,a=i?t:null,u=i?e:t,l=i?o:e,s=n.createChangesSubscriber({selector:a,callback:u,config:l}),f=s.subscriptionCallback,v=s.stateWrapper,p=(0,c.uniqueId)();n.addNewSubscriber(p,{selector:a,config:l,stateWrapper:v,callback:f}),r.push(p)})),r.length||(0,e.throwNoSubscribersWereAdded)(),function(){r.forEach((function(t){n.subscribers.delete(t)}))}},this.getConfigCallbackParam=function(){var t=n.setMetadata,e=n.getMetadata,r=n.getState,o=n.actions;return{setMetadata:t,getMetadata:e,getState:r,setState:n.setStateWrapper,actions:o}},this.addNewSubscriber=function(t,e){n.subscribers.set(t,{subscriptionId:t,currentState:e.stateWrapper.state,selector:e.selector,config:e.config,callback:e.callback,currentDependencies:s})},this.updateSubscriptionIfExists=function(t,e){var r;if(n.subscribers.has(t)){var o=n.subscribers.get(t);o.currentState=e.stateWrapper.state,o.currentDependencies=null===(r=o.config)||void 0===r?void 0:r.dependencies,o.selector=e.selector,o.config=e.config,o.callback=e.callback}},this.executeOnSubscribed=function(){var t=n.onSubscribed,e=n.config.onSubscribed;if(t||e){var r=n.getConfigCallbackParam();null==t||t(r),null==e||e(r)}},this.getHook=function(){return function(t){var e,r,i,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},u=(0,l.useRef)(null),f=function(){return t?{state:t(n.stateWrapper.state)}:n.stateWrapper},v=(r=(0,l.useState)(f),i=2,function(t){if(Array.isArray(t))return t}(r)||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}}(r,i)||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}}(r,i)||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.")}()),p=v[0],d=v[1];return(0,l.useEffect)((function(){return null===u.current&&(u.current=(0,c.uniqueId)()),function(){n.subscribers.delete(u.current)}}),[]),n.updateSubscriptionIfExists(u.current,{stateWrapper:p,selector:t,config:a,callback:d}),(0,l.useEffect)((function(){var e=u.current;null!==e&&!n.subscribers.has(e)&&(n.addNewSubscriber(e,{stateWrapper:p,selector:t,config:a,callback:d}),n.executeOnSubscribed())}),[p]),[function(){var e=u.current;if(!t||!n.subscribers.has(e))return p.state;var r=n.subscribers.get(e),o=r.currentDependencies,i=r.config,l=(void 0===i?{}:i).dependencies;if(o===s)return p.state;if(o===l)return p.state;if((null==o?void 0:o.length)===(null==l?void 0:l.length)&&(0,c.shallowCompare)(o,l))return p.state;var v=f();return n.updateSubscriptionIfExists(e,{stateWrapper:v,selector:t,config:a,callback:d}),p.state=v.state,v.state}(),n.getStateOrchestrator(),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.getStateOrchestrator=function(){return n.actions?n.actions:n.setStateWrapper},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.setStateWrapper=function(t){var e=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).forceUpdate,r="function"==typeof t,o=n.stateWrapper.state,i=r?t(o):t;if(e||!Object.is(n.stateWrapper.state,i)){var a=n.setMetadata,u=n.getMetadata,c=n.getState,l=n.actions,s={setMetadata:a,getMetadata:u,setState:n.setState,getState:c,actions:l,previousState:o,state:i},f=n.computePreventStateChange,v=n.config.computePreventStateChange;if((f||v)&&((null==f?void 0:f(s))||(null==v?void 0:v(s))))return;n.setState({forceUpdate:e,state:i});var p=n.onStateChanged,d=n.config.onStateChanged;(p||d)&&(null==p||p(s),null==d||d(s))}},this.getStoreActionsMap=function(){if(!n.actionsConfig)return null;var t=n.actionsConfig,e=n.setMetadata,r=n.setStateWrapper,o=n.getState,i=n.getMetadata,a=Object.keys(t).reduce((function(n,c){var l,s,f;return Object.assign(n,(l={},f=function(){for(var n=t[c],u=arguments.length,l=new Array(u),s=0;s<u;s++)l[s]=arguments[s];var f=n.apply(a,l);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, actions }) => {\n\n setState((state) => ({ ...state, ...param }))\n\n }\n\n}\n"))}(c),f.call(a,{setState:r,getState:o,setMetadata:e,getMetadata:i,actions:a})},(s=u(s=c))in l?Object.defineProperty(l,s,{value:f,enumerable:!0,configurable:!0,writable:!0}):l[s]=f,l)),n}),{});return a},this.stateWrapper={state:r},this.config=Object.assign({metadata:null},null!=a?a:{}),this.constructor!==t||this.initialize()}var r,n;return r=t,(n=[{key:"state",get:function(){return this.stateWrapper.state}}])&&a(r.prototype,n),Object.defineProperty(r,"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.uniqueId=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.isNil)(t)||(0,c.isNil)(e)||(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,v=e;if(f.size!==v.size)return!1;var p,d=o(f);try{for(d.s();!(p=d.n()).done;){var y=n(p.value,2),h=y[0];if(y[1]!==v.get(h))return!1}}catch(t){d.e(t)}finally{d.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 A=0,E=O;A<E.length;A++){var x=E[A];if(t[x]!==e[x])return!1}return!0},e.debounce=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return function(){for(var n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];e&&clearTimeout(e),e=setTimeout((function(){t.apply(void 0,o)}),r)}},e.uniqueId=function(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},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),o(r(608),e),o(r(852),e),o(r(113),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,v=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},p=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 v({obj:r,key:o,value:a})?Object.assign(Object.assign({},e),n({},o,t(i))):e}),{})}((0,e.clone)(t));return i?JSON.stringify(p):p}}},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-hooks-global-states"]=e(require("react")):t["react-hooks-global-states"]=e(t.react)}(this,(t=>{return e={852:(t,e,r)=>{"use strict";function n(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],c=!0,l=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(u.push(n.value),u.length!==e);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(t,e)||function(t,e){if(t){if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}Object.defineProperty(e,"__esModule",{value:!0}),e.combineRetrieverAsynchronously=e.combineAsyncGetters=e.combineRetrieverEmitterAsynchronously=e.combineAsyncGettersEmitter=void 0;var i=r(608),a=r(156),u=r(774);e.combineAsyncGettersEmitter=function(t){for(var e,r,n,o=arguments.length,a=new Array(o>1?o-1:0),c=1;c<o;c++)a[c-1]=arguments[c];var l=a,s=new Map(l.map((function(t,e){return[e,t()]}))),f=t.selector(Array.from(s.values())),p=void 0!==(null===(e=null==t?void 0:t.config)||void 0===e?void 0:e.isEqual)?null===(r=null==t?void 0:t.config)||void 0===r?void 0:r.isEqual:i.shallowCompare,v=new Set,d=(0,i.debounce)((function(){var e=t.selector(Array.from(s.values()));(null==p?void 0:p(f,e))||(f=e,v.forEach((function(t){return t()})))}),null===(n=null==t?void 0:t.config)||void 0===n?void 0:n.delay),y=l.map((function(t,e){return t((function(t){t((function(t){s.set(e,t),d()}))}))})),b=function(t,e,r){var n,o,a="function"==typeof e,u=a?t:null,c=a?e:t,l=a?r:e,s=Object.assign({delay:0,isEqual:i.shallowCompare},null!=l?l:{}),p=null!==(n=null==u?void 0:u(f))&&void 0!==n?n:f;s.skipFirst||c(p);var d=(0,i.debounce)((function(){var t,e,r=null!==(t=null==u?void 0:u(f))&&void 0!==t?t:f;(null===(e=s.isEqual)||void 0===e?void 0:e.call(s,p,r))||(p=r,c(r))}),null!==(o=s.delay)&&void 0!==o?o:0);return v.add(d),function(){v.delete(d)}};return[b,function(t){if(!t)return f;var e=[];return t((function(){e.push(b.apply(void 0,arguments))})),e.length||(0,u.throwNoSubscribersWereAdded)(),function(){e.forEach((function(t){t(),v.delete(t)}))}},function(){y.forEach((function(t){return t()}))}]},e.combineRetrieverEmitterAsynchronously=e.combineAsyncGettersEmitter,e.combineAsyncGetters=function(t){for(var r=arguments.length,o=new Array(r>1?r-1:0),u=1;u<r;u++)o[u-1]=arguments[u];var c=n(e.combineAsyncGettersEmitter.apply(void 0,[t].concat(o)),3),l=c[0],s=c[1],f=c[2];return[function(t,e){var r=n((0,a.useState)((function(){var e=s();return t?t(e):e})),2),o=r[0],u=r[1];return(0,a.useEffect)((function(){var r,n=Object.assign({delay:0,isEqual:i.shallowCompare},null!=e?e:{}),o=void 0!==n.isEqual?n.isEqual:i.shallowCompare,a=l((function(e){return t?t(e):e}),(0,i.debounce)((function(e){var r=t?t(e):e;(null==o?void 0:o(e,r))||u(r)}),null!==(r=n.delay)&&void 0!==r?r:0));return function(){a()}}),[]),[o,null,null]},s,f]},e.combineRetrieverAsynchronously=e.combineAsyncGetters},113:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createStatefulContext=void 0;var n,o=r(853),i=r(684),a=(n=r(156))&&n.__esModule?n:{default:n};e.createStatefulContext=function(t,e){var r=a.default.createContext(null);return[function(){return a.default.useContext(r)},function(n){var u=n.children,c=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}(n,["children"]),l=(0,o.createGlobalStateWithDecoupledFuncs)(function(){if(c.initialValue){if("function"==typeof c.initialValue)return c.initialValue((0,i.clone)(t));var e=Array.isArray(c.initialValue),r=c.initialValue instanceof Map,n=c.initialValue instanceof Set;return(0,i.isPrimitive)(c.initialValue)||(0,i.isDate)(c.initialValue)||e||r||n?c.initialValue:Object.assign(Object.assign({},t),c.initialValue)}return(0,i.clone)(t)}(),e);return a.default.createElement(r.Provider,{value:l},u)}]}},853:(t,e,r)=>{"use strict";function n(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 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};Object.defineProperty(e,"__esModule",{value:!0}),e.createDerivateEmitter=e.createDerivate=e.createCustomGlobalStateWithDecoupledFuncs=e.createGlobalState=e.createGlobalStateWithDecoupledFuncs=void 0;var i=r(774);e.createGlobalStateWithDecoupledFuncs=function(t){var e,r,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},u=a.actions,c=o(a,["actions"]),l=new i.GlobalStore(t,c,u).getHook(),s=(e=l.stateControls(),r=2,function(t){if(Array.isArray(t))return t}(e)||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}}(e,r)||function(t,e){if(t){if("string"==typeof t)return n(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)?n(t,e):void 0}}(e,r)||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.")}());return[l,s[0],s[1]]},e.createGlobalState=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.actions,n=o(e,["actions"]);return new i.GlobalStore(t,n,r).getHook()},e.createCustomGlobalStateWithDecoupledFuncs=function(t){var r=t.onInitialize,n=t.onChange;return function(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{config:null},a=i.config,u=i.onInit,c=i.onStateChanged,l=o(i,["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 t.createSelectorHook(e,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 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 d?e:d,a=Object.create(i.prototype),u=new k(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 d(){}function y(){}function b(){}var h={};s(h,u,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(P([])));m&&m!==e&&r.call(m,u)&&(h=m);var S=b.prototype=d.prototype=Object.create(h);function w(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function i(o,a,u,c){var l=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=E(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 E(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,E(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),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 x(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function k(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(A,this),this.reset(!0)}function P(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:C}}function C(){return{value:void 0,done:!0}}return y.prototype=b,o(S,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:y,configurable:!0}),y.displayName=s(b,l,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,s(t,l,"GeneratorFunction")),t.prototype=Object.create(S),t},t.awrap=function(t){return{__await:t}},w(O.prototype),s(O.prototype,c,(function(){return this})),t.AsyncIterator=O,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new O(f(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(S),s(S,l,"Generator"),s(S,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=P,k.prototype={constructor:k,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(x),!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),x(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;x(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:P(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.uniqueSymbol=e.throwNoSubscribersWereAdded=void 0;var l=r(608),s=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")},e.uniqueSymbol=Symbol("unique");var f=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.actions=null,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(this.actionsConfig&&(this.actions=this.getStoreActionsMap()),e=this.onInit,r=this.config.onInit,e||r){t.next=5;break}return t.abrupt("return");case 5:n=this.getConfigCallbackParam(),null==e||e(n),null==r||r(n);case 8: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.state,r=t.forceUpdate,o=n.stateWrapper.state;n.stateWrapper={state:e};for(var i=function(t){var n,i,a=t.selector,u=t.callback,c=t.currentState,l=t.config;if(r||!(null!==(n=null==l?void 0:l.isEqualRoot)&&void 0!==n?n:function(t,e){return Object.is(t,e)})(o,e)){var s=a?a(e):e;!r&&(null!==(i=null==l?void 0:l.isEqual)&&void 0!==i?i:function(t,e){return Object.is(t,e)})(c,s)||u({state:s})}},a=Array.from(n.subscribers.values()),u=0;u<a.length;u++)i(a[u])},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,subscriptionCallback:function(t){var r=t.state;a.state=r,e(r)}}},this.getState=function(t){if(!t)return n.stateWrapper.state;var r=[];return t((function(t,e,o){var i="function"==typeof e,a=i?t:null,u=i?e:t,c=i?o:e,s=n.createChangesSubscriber({selector:a,callback:u,config:c}),f=s.subscriptionCallback,p=s.stateWrapper,v=(0,l.uniqueId)();n.addNewSubscriber(v,{selector:a,config:c,stateWrapper:p,callback:f}),r.push(v)})),r.length||(0,e.throwNoSubscribersWereAdded)(),function(){r.forEach((function(t){n.subscribers.delete(t)}))}},this.getConfigCallbackParam=function(){var t=n.setMetadata,e=n.getMetadata,r=n.getState,o=n.actions;return{setMetadata:t,getMetadata:e,getState:r,setState:n.setStateWrapper,actions:o}},this.addNewSubscriber=function(t,r){n.subscribers.set(t,{subscriptionId:t,currentState:r.stateWrapper.state,selector:r.selector,config:r.config,callback:r.callback,currentDependencies:e.uniqueSymbol})},this.updateSubscriptionIfExists=function(t,e){var r;if(n.subscribers.has(t)){var o=n.subscribers.get(t);o.currentState=e.stateWrapper.state,o.currentDependencies=null===(r=o.config)||void 0===r?void 0:r.dependencies,o.selector=e.selector,o.config=e.config,o.callback=e.callback}},this.executeOnSubscribed=function(){var t=n.onSubscribed,e=n.config.onSubscribed;if(t||e){var r=n.getConfigCallbackParam();null==t||t(r),null==e||e(r)}},this.getHook=function(){var t=function(t){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=(0,s.useRef)(null),u=function(){return t?{state:t(n.stateWrapper.state)}:{state:n.stateWrapper.state}},c=o((0,s.useState)(u),2),f=c[0],p=c[1];return(0,s.useEffect)((function(){return null===a.current&&(a.current=(0,l.uniqueId)()),function(){n.subscribers.delete(a.current)}}),[]),n.updateSubscriptionIfExists(a.current,{stateWrapper:f,selector:t,config:i,callback:p}),(0,s.useEffect)((function(){var e=a.current;null!==e&&!n.subscribers.has(e)&&(n.addNewSubscriber(e,{stateWrapper:f,selector:t,config:i,callback:p}),n.executeOnSubscribed())}),[f]),[function(){var r=a.current;if(!t||!n.subscribers.has(r))return f.state;var o=n.subscribers.get(r),c=o.currentDependencies,s=o.config,v=(void 0===s?{}:s).dependencies;if(c===e.uniqueSymbol)return f.state;if(c===v)return f.state;if((null==c?void 0:c.length)===(null==v?void 0:v.length)&&(0,l.shallowCompare)(c,v))return f.state;var d=u();return n.updateSubscriptionIfExists(r,{stateWrapper:d,selector:t,config:i,callback:p}),f.state=d.state,d.state}(),n.getStateOrchestrator(),null!==(r=n.config.metadata)&&void 0!==r?r:null]};return t.stateControls=n.stateControls,t.createSelectorHook=n.createSelectorHook,t},this.createSelectorHook=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=r.isEqualRoot,a=r.isEqual,u=new Map,c=o(n.stateControls(),3),f=c[0],p=c[1],v=c[2],d=f(),y=(null!=t?t:function(t){return t})(f());f((function(e){e((function(e){if(!(null!=i?i:Object.is)(d,e)){d=e;var r=t(e);(null!=a?a:Object.is)(y,r)||(y=r,u.forEach((function(t){t.callback({state:y})})))}}),{skipFirst:!0})}));var b=function(t,r){u.set(t,{subscriptionId:t,currentState:r.stateWrapper.state,selector:r.selector,config:r.config,callback:r.callback,currentDependencies:e.uniqueSymbol})},h=function(t,e){var r;if(u.has(t)){var n=u.get(t);n.currentState=e.stateWrapper.state,n.currentDependencies=null===(r=n.config)||void 0===r?void 0:r.dependencies,n.selector=e.selector,n.config=e.config,n.callback=e.callback}},g=function(t){if(!t)return y;var r=[];return t((function(t,e,n){var o="function"==typeof e,i=o?t:null,a=o?n:e,u=function(t){var e=t.callback,r=t.selector,n=t.config,o=(null!=r?r:function(t){return t})(y),i={state:o};return(null==n?void 0:n.skipFirst)||e(o),{stateWrapper:i,subscriptionCallback:function(t){var r=t.state;i.state=r,e(r)}}}({selector:i,callback:o?e:t,config:a}),c=u.subscriptionCallback,s=u.stateWrapper,f=(0,l.uniqueId)();b(f,{selector:i,config:a,stateWrapper:s,callback:c}),r.push(f)})),r.length||(0,e.throwNoSubscribersWereAdded)(),function(){r.forEach((function(t){u.delete(t)}))}},m=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=r.isEqualRoot,i=r.isEqual,a=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}(r,["isEqualRoot","isEqual"]),c=function(){return t?{state:t(y)}:{state:y}},f=(0,s.useRef)(null),d=o((0,s.useState)(c),2),m=d[0],S=d[1];return(0,s.useEffect)((function(){null===f.current&&(f.current=(0,l.uniqueId)());var e=g((function(e){var r=y;e((function(e){var o=u.get(f.current);if(!(null!=n?n:Object.is)(r,e)){r=e;var a=(null!=t?t:function(t){return t})(y);(null!=i?i:Object.is)(a,o.currentState)||(o.currentState=a,S({state:a}))}}),{skipFirst:!0})}));return function(){e(),u.delete(f.current)}}),[]),h(f.current,{stateWrapper:m,selector:t,config:a,callback:S}),(0,s.useEffect)((function(){var e=f.current;null!==e&&!u.has(e)&&b(e,{stateWrapper:m,selector:t,config:a,callback:S})}),[m]),[function(){var r=f.current;if(!t||!u.has(r))return m.state;var n=u.get(r),o=n.currentDependencies,i=n.config,s=(void 0===i?{}:i).dependencies;if(o===e.uniqueSymbol)return m.state;if(o===s)return m.state;if((null==o?void 0:o.length)===(null==s?void 0:s.length)&&(0,l.shallowCompare)(o,s))return m.state;var p=c();return h(r,{stateWrapper:p,selector:t,config:a,callback:S}),m.state=p.state,p.state}(),p,v]};return m.stateControls=function(){return[g,p,v]},m.createSelectorHook=n.createSelectorHook.bind(m),m},this.stateControls=function(){var t=n.getStateOrchestrator(),e=n.getMetadata;return[n.getState,t,e]},this.getHookDecoupled=function(){return n.stateControls()},this.getStateOrchestrator=function(){return n.actions?n.actions:n.setStateWrapper},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.setStateWrapper=function(t){var e=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).forceUpdate,r="function"==typeof t,o=n.stateWrapper.state,i=r?t(o):t;if(e||!Object.is(n.stateWrapper.state,i)){var a=n.setMetadata,u=n.getMetadata,c=n.getState,l=n.actions,s={setMetadata:a,getMetadata:u,setState:n.setState,getState:c,actions:l,previousState:o,state:i},f=n.computePreventStateChange,p=n.config.computePreventStateChange;if((f||p)&&((null==f?void 0:f(s))||(null==p?void 0:p(s))))return;n.setState({forceUpdate:e,state:i});var v=n.onStateChanged,d=n.config.onStateChanged;(v||d)&&(null==v||v(s),null==d||d(s))}},this.getStoreActionsMap=function(){if(!n.actionsConfig)return null;var t=n.actionsConfig,e=n.setMetadata,r=n.setStateWrapper,o=n.getState,i=n.getMetadata,a=Object.keys(t).reduce((function(n,u){var l,s,f;return Object.assign(n,(l={},f=function(){for(var n=t[u],c=arguments.length,l=new Array(c),s=0;s<c;s++)l[s]=arguments[s];var f=n.apply(a,l);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, actions }) => {\n\n setState((state) => ({ ...state, ...param }))\n\n }\n\n}\n"))}(u),f.call(a,{setState:r,getState:o,setMetadata:e,getMetadata:i,actions:a})},(s=c(s=u))in l?Object.defineProperty(l,s,{value:f,enumerable:!0,configurable:!0,writable:!0}):l[s]=f,l)),n}),{});return a},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}}])&&u(r.prototype,n),Object.defineProperty(r,"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.uniqueId=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.isNil)(t)||(0,c.isNil)(e)||(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,d=o(f);try{for(d.s();!(v=d.n()).done;){var y=n(v.value,2),b=y[0];if(y[1]!==p.get(b))return!1}}catch(t){d.e(t)}finally{d.f()}}if(t instanceof Set){var h=t,g=e;if(h.size!==g.size)return!1;var m,S=o(h);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 E=0,A=O;E<A.length;E++){var x=A[E];if(t[x]!==e[x])return!1}return!0},e.debounce=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return function(){for(var n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];e&&clearTimeout(e),e=setTimeout((function(){t.apply(void 0,o)}),r)}},e.uniqueId=function(){return Date.now().toString(36)+Math.random().toString(36).substr(2,5)}},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),o(r(608),e),o(r(852),e),o(r(113),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}));
|
package/lib/src/GlobalStore.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ActionCollectionConfig, StateSetter, GlobalStoreConfig, ActionCollectionResult, StateConfigCallbackParam, MetadataSetter, UseHookConfig, StateGetter, SubscribeCallbackConfig, SubscribeCallback, SelectorCallback, SubscriberParameters, SubscriptionCallback, MetadataGetter } from './GlobalStore.types';
|
|
1
|
+
import { ActionCollectionConfig, StateSetter, GlobalStoreConfig, ActionCollectionResult, StateConfigCallbackParam, MetadataSetter, UseHookConfig, StateGetter, SubscribeCallbackConfig, SubscribeCallback, SelectorCallback, SubscriberParameters, SubscriptionCallback, MetadataGetter, StateHook } from './GlobalStore.types';
|
|
2
2
|
export declare const throwNoSubscribersWereAdded: () => never;
|
|
3
|
+
export declare const uniqueSymbol: unique symbol;
|
|
3
4
|
/**
|
|
4
5
|
* The GlobalStore class is the main class of the library and it is used to create a GlobalStore instances
|
|
5
6
|
* @template {TState} TState - The type of the state object
|
|
@@ -181,11 +182,20 @@ export declare class GlobalStore<TState, TMetadata = null, TStateMutator extends
|
|
|
181
182
|
* Returns a custom hook that allows to handle a global state
|
|
182
183
|
* @returns {[TState, TStateMutator, TMetadata]} - The state, the state setter or the actions map, the metadata
|
|
183
184
|
* */
|
|
184
|
-
getHook: () => <
|
|
185
|
+
getHook: () => StateHook<TState, TStateMutator, TMetadata>;
|
|
186
|
+
/**
|
|
187
|
+
* @description
|
|
188
|
+
* Use this function to create a custom global hook which contains a fragment of the state of another hook
|
|
189
|
+
*/
|
|
190
|
+
createSelectorHook: <RootState, StateMutator, Metadata, RootSelectorResult, RootDerivate = RootSelectorResult extends never ? RootState : RootSelectorResult>(mainSelector?: (state: RootState) => RootSelectorResult, { isEqualRoot: mainIsEqualRoot, isEqual: mainIsEqualFun, }?: Omit<UseHookConfig<RootDerivate, RootState>, "dependencies">) => StateHook<RootDerivate, StateMutator, Metadata>;
|
|
185
191
|
/**
|
|
186
192
|
* 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
|
|
187
193
|
* @returns {[() => TState, TStateMutator, () => TMetadata]} - The state getter, the state setter or the actions map, the metadata getter
|
|
188
194
|
* */
|
|
195
|
+
stateControls: () => [StateGetter<TState>, keyof TStateMutator extends never ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TStateMutator>, MetadataGetter<TMetadata>];
|
|
196
|
+
/**
|
|
197
|
+
* @deprecated use the stateControls method instead
|
|
198
|
+
*/
|
|
189
199
|
getHookDecoupled: () => [StateGetter<TState>, keyof TStateMutator extends never ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TStateMutator>, MetadataGetter<TMetadata>];
|
|
190
200
|
/**
|
|
191
201
|
* Returns the state setter or the actions map
|
|
@@ -3,25 +3,23 @@ import { ActionCollectionConfig, StateSetter, ActionCollectionResult, UseHookCon
|
|
|
3
3
|
* Creates a global state with the given state and config.
|
|
4
4
|
* @returns {} [HOOK, DECOUPLED_RETRIEVER, DECOUPLED_MUTATOR] this is an array with the hook, the decoupled getState function and the decoupled setter of the state
|
|
5
5
|
*/
|
|
6
|
-
export declare const createGlobalStateWithDecoupledFuncs: <TState, TMetadata = null, TActions extends ActionCollectionConfig<TState, TMetadata> = null>(state: TState, { actions, ...config }?: createStateConfig<TState, TMetadata, TActions>) => [
|
|
6
|
+
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>, stateRetriever: StateGetter<TState>, stateMutator: keyof TActions extends never ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TActions>];
|
|
7
7
|
/**
|
|
8
8
|
* Creates a global hook that can be used to access the state and actions across the application
|
|
9
9
|
* @returns {} - () => [TState, Setter, TMetadata] the hook that can be used to access the state and the setter of the state
|
|
10
10
|
*/
|
|
11
|
-
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
|
|
12
|
-
stateControls: () => [stateRetriever: StateGetter<TState>, stateMutator: keyof TActions extends never ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TActions>];
|
|
13
|
-
};
|
|
11
|
+
export declare const createGlobalState: <TState, TMetadata = null, TActions extends ActionCollectionConfig<TState, TMetadata> = null>(state: TState, { actions, ...config }?: createStateConfig<TState, TMetadata, TActions>) => StateHook<TState, keyof TActions extends never ? StateSetter<TState> : ActionCollectionResult<TState, TMetadata, TActions>, TMetadata>;
|
|
14
12
|
/**
|
|
15
13
|
* @description
|
|
16
14
|
* Use this function to create a custom global store.
|
|
17
15
|
* You can use this function to create a store with async storage.
|
|
18
16
|
*/
|
|
19
|
-
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>) => [
|
|
17
|
+
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>>, stateRetriever: StateGetter<TState>, stateMutator: keyof TActions extends never ? StateSetter<TState> : ActionCollectionResult<TState, AvoidNever<TInheritMetadata> & AvoidNever<TMetadata>, TActions>];
|
|
20
18
|
/**
|
|
21
19
|
* @description
|
|
22
|
-
* Use this function to create a custom global hook which contains a fragment of the state of another hook
|
|
20
|
+
* Use this function to create a custom global hook which contains a fragment of the state of another hook
|
|
23
21
|
*/
|
|
24
|
-
export declare const createDerivate: <
|
|
22
|
+
export declare const createDerivate: <RootState, StateMutator, Metadata, RootSelectorResult, RootDerivate = RootSelectorResult extends never ? RootState : RootSelectorResult>(useHook: StateHook<RootState, StateMutator, Metadata>, mainSelector?: (state: RootState) => RootSelectorResult, args?: Omit<UseHookConfig<RootDerivate, RootState>, "dependencies">) => StateHook<RootDerivate, StateMutator, Metadata>;
|
|
25
23
|
/**
|
|
26
24
|
* @description
|
|
27
25
|
* This function allows you to create a derivate emitter
|
|
@@ -24,9 +24,32 @@ setter: TState | ((state: TState) => TState),
|
|
|
24
24
|
/**
|
|
25
25
|
* @description
|
|
26
26
|
* The hook to use the global state
|
|
27
|
-
* @returns {[State, StateSetter<
|
|
27
|
+
* @returns {[State, StateSetter<State>, TMetadata]} result - the state, the setter and the metadata
|
|
28
28
|
*/
|
|
29
|
-
export type StateHook<
|
|
29
|
+
export type StateHook<State, StateMutator, TMetadata> = (<Derivate = State>(selector?: (state: State) => Derivate, config?: UseHookConfig<Derivate, State>) => Readonly<[state: Derivate, stateMutator: StateMutator, metadata: TMetadata]>) & {
|
|
30
|
+
/**
|
|
31
|
+
* @description Return the state controls of the hook
|
|
32
|
+
* This selectors includes:
|
|
33
|
+
* - stateRetriever: a function to get the current state or subscribe a callback to the state changes
|
|
34
|
+
* - stateMutator: a function to set the state or a collection of actions if you pass an storeActionsConfig configuration
|
|
35
|
+
* - metadataRetriever: a function to get the metadata of the global state
|
|
36
|
+
*/
|
|
37
|
+
stateControls: () => Readonly<[
|
|
38
|
+
stateRetriever: StateGetter<State>,
|
|
39
|
+
stateMutator: StateMutator,
|
|
40
|
+
metadataRetriever: MetadataGetter<TMetadata>
|
|
41
|
+
]>;
|
|
42
|
+
/***
|
|
43
|
+
* @description Creates a new hooks that returns the result of the selector passed as a parameter
|
|
44
|
+
* Your can create selector hooks of other selectors hooks and extract as many derived states as or fragments of the state as you want
|
|
45
|
+
* The selector hook will be evaluated only if the result of the selector changes and the equality function returns false
|
|
46
|
+
* you can customize the equality function by passing the isEqualRoot and isEqual parameters
|
|
47
|
+
*/
|
|
48
|
+
createSelectorHook: <RootState, StateMutator, Metadata, RootSelectorResult, RootDerivate = RootSelectorResult extends never ? RootState : RootSelectorResult>(this: StateHook<RootState, StateMutator, Metadata>, mainSelector?: (state: RootState) => RootSelectorResult, { isEqualRoot, isEqual }?: Omit<UseHookConfig<RootDerivate, RootState>, 'dependencies'>) => StateHook<RootDerivate, StateMutator, Metadata>;
|
|
49
|
+
State: State;
|
|
50
|
+
StateMutator: StateMutator;
|
|
51
|
+
Metadata: TMetadata;
|
|
52
|
+
};
|
|
30
53
|
/**
|
|
31
54
|
* @description
|
|
32
55
|
* Type that prevent ts issues with merging never with other types
|
|
@@ -194,13 +217,13 @@ export type GlobalStoreConfig<TState, TMetadata, TStateMutator extends ActionCol
|
|
|
194
217
|
*/
|
|
195
218
|
computePreventStateChange?: (parameters: StateChangesParam<TState, TMetadata, TStateMutator>) => boolean;
|
|
196
219
|
} | null;
|
|
197
|
-
export type UseHookConfig<TState> = {
|
|
220
|
+
export type UseHookConfig<TState, TRoot = any> = {
|
|
198
221
|
/**
|
|
199
222
|
* The callback to execute when the state is changed to check if the same really changed
|
|
200
223
|
* If the function is not provided the derived state will perform a shallow comparison
|
|
201
224
|
*/
|
|
202
225
|
isEqual?: (current: TState, next: TState) => boolean;
|
|
203
|
-
isEqualRoot?: (current:
|
|
226
|
+
isEqualRoot?: (current: TRoot, next: TRoot) => boolean;
|
|
204
227
|
dependencies?: unknown[];
|
|
205
228
|
};
|
|
206
229
|
/**
|
package/package.json
CHANGED