react-shared-states 1.0.13 → 1.0.15
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 +5 -5
- package/dist/SharedValuesManager.d.ts +9 -0
- package/dist/hooks/use-shared-function.d.ts +6 -0
- package/dist/hooks/use-shared-state.d.ts +2 -0
- package/dist/hooks/use-shared-subscription.d.ts +6 -0
- package/dist/main.esm.js +351 -321
- package/dist/main.min.js +5 -5
- package/package.json +1 -1
- package/tests/index.test.tsx +70 -0
package/README.md
CHANGED
|
@@ -519,11 +519,11 @@ const subStateScoped = sharedSubscriptionsApi.get('live-chat', 'myScope');
|
|
|
519
519
|
|
|
520
520
|
## API summary:
|
|
521
521
|
|
|
522
|
-
| API | Methods
|
|
523
|
-
|
|
524
|
-
| `sharedStatesApi` | `get(key, scopeName?)`, `set(key, val, scopeName?)`, `has(key, scopeName?)`, `clear(key, scopeName?)`, `clearAll(withoutListeners?, withStatic?)`, `clearScope(scopeName?)`, `getAll()` |
|
|
525
|
-
| `sharedFunctionsApi` | `get(key, scopeName?)`, `set(key, val, scopeName?)`, `has(key, scopeName?)`, `clear(key, scopeName?)`, `clearAll(withoutListeners?, withStatic?)`, `clearScope(scopeName?)`, `getAll()` |
|
|
526
|
-
| `sharedSubscriptionsApi` | `get(key, scopeName?)`, `set(key, val, scopeName?)`, `has(key, scopeName?)`, `clear(key, scopeName?)`, `clearAll(withoutListeners?, withStatic?)`, `clearScope(scopeName?)`, `getAll()` |
|
|
522
|
+
| API | Methods |
|
|
523
|
+
|--------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
524
|
+
| `sharedStatesApi` | `get(key, scopeName?)`, `set(key, val, scopeName?)`, `update(key, updater, scopeName?)`, `has(key, scopeName?)`, `clear(key, scopeName?)`, `clearAll(withoutListeners?, withStatic?)`, `clearScope(scopeName?)`, `getAll()` |
|
|
525
|
+
| `sharedFunctionsApi` | `get(key, scopeName?)`, `set(key, val, scopeName?)`, `update(key, updater, scopeName?)`, `has(key, scopeName?)`, `clear(key, scopeName?)`, `clearAll(withoutListeners?, withStatic?)`, `clearScope(scopeName?)`, `getAll()` |
|
|
526
|
+
| `sharedSubscriptionsApi` | `get(key, scopeName?)`, `set(key, val, scopeName?)`, `update(key, updater, scopeName?)`, `has(key, scopeName?)`, `clear(key, scopeName?)`, `clearAll(withoutListeners?, withStatic?)`, `clearScope(scopeName?)`, `getAll()` |
|
|
527
527
|
|
|
528
528
|
`scopeName` defaults to `"_global"`. Internally, keys are stored as `${scope}//${key}`. The `.getAll()` method returns a nested object: `{ [scope]: { [key]: value } }`.
|
|
529
529
|
|
|
@@ -39,6 +39,14 @@ export declare class SharedValuesApi<T extends SharedValue, V, R = T> {
|
|
|
39
39
|
*/
|
|
40
40
|
set<S extends string = string>(key: S, value: V, scopeName: Prefix): void;
|
|
41
41
|
set<S extends string = string>(sharedCreated: SharedCreated, value: V): void;
|
|
42
|
+
/**
|
|
43
|
+
* update a value in the shared data
|
|
44
|
+
* @param key
|
|
45
|
+
* @param updater
|
|
46
|
+
* @param scopeName
|
|
47
|
+
*/
|
|
48
|
+
update<S extends string = string>(key: S, updater: (prev: R) => V, scopeName: Prefix): void;
|
|
49
|
+
update<S extends string = string>(sharedCreated: SharedCreated, updater: (prev: R) => V): void;
|
|
42
50
|
/**
|
|
43
51
|
* clear all values from the shared data
|
|
44
52
|
*/
|
|
@@ -70,4 +78,5 @@ export declare class SharedValuesApi<T extends SharedValue, V, R = T> {
|
|
|
70
78
|
* get all values from the shared data
|
|
71
79
|
*/
|
|
72
80
|
getAll(): Record<string, Record<string, any>>;
|
|
81
|
+
subscribe<S extends string = string>(sharedCreated: SharedCreated, listener: AFunction): void;
|
|
73
82
|
}
|
|
@@ -35,6 +35,12 @@ export declare class SharedFunctionsApi extends SharedValuesApi<SharedFunction<u
|
|
|
35
35
|
set<T, Args extends unknown[]>(sharedFunctionCreated: SharedFunctionCreated<T, Args>, value: {
|
|
36
36
|
fnState: SharedFunctionValue<T>;
|
|
37
37
|
}): void;
|
|
38
|
+
update<T, Args extends unknown[], S extends string = string>(key: S, updater: (prev: SharedFunctionValue<T>) => {
|
|
39
|
+
fnState: SharedFunctionValue<T>;
|
|
40
|
+
}, scopeName?: Prefix): void;
|
|
41
|
+
update<T, Args extends unknown[]>(sharedFunctionCreated: SharedFunctionCreated<T, Args>, updater: (prev: SharedFunctionValue<T>) => {
|
|
42
|
+
fnState: SharedFunctionValue<T>;
|
|
43
|
+
}): void;
|
|
38
44
|
}
|
|
39
45
|
export declare const sharedFunctionsApi: SharedFunctionsApi;
|
|
40
46
|
interface SharedFunctionCreated<T, Args extends unknown[]> extends SharedCreated {
|
|
@@ -20,6 +20,8 @@ export declare class SharedStatesApi extends SharedValuesApi<SharedState<unknown
|
|
|
20
20
|
get<T>(sharedStateCreated: SharedStateCreated<T>): T;
|
|
21
21
|
set<T, S extends string = string>(key: S, value: T, scopeName?: Prefix): void;
|
|
22
22
|
set<T>(sharedStateCreated: SharedStateCreated<T>, value: T): void;
|
|
23
|
+
update<T, S extends string = string>(key: S, updater: (prev: T) => T, scopeName?: Prefix): void;
|
|
24
|
+
update<T>(sharedStateCreated: SharedStateCreated<T>, updater: (prev: T) => T): void;
|
|
23
25
|
}
|
|
24
26
|
export declare const sharedStatesApi: SharedStatesApi;
|
|
25
27
|
export interface SharedStateCreated<T> extends SharedCreated {
|
|
@@ -47,6 +47,12 @@ export declare class SharedSubscriptionsApi extends SharedValuesApi<SharedSubscr
|
|
|
47
47
|
set<T>(sharedSubscriptionCreated: SharedSubscriptionCreated<T>, value: {
|
|
48
48
|
fnState: SharedSubscriptionValue<T>;
|
|
49
49
|
}): void;
|
|
50
|
+
update<T, S extends string = string>(key: S, updater: (prev: SharedSubscriptionValue<T>) => {
|
|
51
|
+
fnState: SharedSubscriptionValue<T>;
|
|
52
|
+
}, scopeName?: Prefix): void;
|
|
53
|
+
update<T>(sharedSubscriptionCreated: SharedSubscriptionCreated<T>, updater: (prev: SharedSubscriptionValue<T>) => {
|
|
54
|
+
fnState: SharedSubscriptionValue<T>;
|
|
55
|
+
}): void;
|
|
50
56
|
}
|
|
51
57
|
export declare const sharedSubscriptionsApi: SharedSubscriptionsApi;
|
|
52
58
|
interface SharedSubscriptionCreated<T> extends SharedCreated {
|