react-shared-states 1.0.8 → 1.0.12
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 +155 -91
- package/dist/{SharedData.d.ts → SharedValuesManager.d.ts} +28 -17
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/use-shared-function.d.ts +37 -12
- package/dist/hooks/use-shared-state.d.ts +22 -3
- package/dist/hooks/use-shared-subscription.d.ts +44 -16
- package/dist/main.esm.js +480 -395
- package/dist/main.min.js +5 -5
- package/dist/types.d.ts +2 -1
- package/package.json +9 -2
- package/tests/index.test.tsx +309 -5
- package/pnpm-workspace.yaml +0 -2
|
@@ -1,24 +1,52 @@
|
|
|
1
|
-
import { PotentialPromise, Prefix, SharedCreated } from '../types';
|
|
2
|
-
import {
|
|
3
|
-
type Unsubscribe = () => void;
|
|
1
|
+
import { PotentialPromise, Prefix, SharedCreated, SharedValue } from '../types';
|
|
2
|
+
import { SharedValuesApi, SharedValuesManager } from '../SharedValuesManager';
|
|
3
|
+
export type Unsubscribe = () => void;
|
|
4
4
|
export declare namespace SubscriberEvents {
|
|
5
5
|
type OnError = (error: unknown) => void;
|
|
6
6
|
type OnCompletion = () => void;
|
|
7
7
|
type Set<T> = (value: T) => void;
|
|
8
8
|
}
|
|
9
|
-
type Subscriber<T> = (set: SubscriberEvents.Set<T>, onError: SubscriberEvents.OnError, onCompletion: SubscriberEvents.OnCompletion) => PotentialPromise<Unsubscribe | void | undefined>;
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
subscribed: boolean;
|
|
16
|
-
};
|
|
17
|
-
unsubscribe?: Unsubscribe | void;
|
|
9
|
+
export type Subscriber<T> = (set: SubscriberEvents.Set<T>, onError: SubscriberEvents.OnError, onCompletion: SubscriberEvents.OnCompletion) => PotentialPromise<Unsubscribe | void | undefined>;
|
|
10
|
+
type SharedSubscriptionValue<T> = {
|
|
11
|
+
data?: T;
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
error?: unknown;
|
|
14
|
+
subscribed?: boolean;
|
|
18
15
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
interface SharedSubscription<T> extends SharedValue {
|
|
17
|
+
fnState: SharedSubscriptionValue<T>;
|
|
18
|
+
unsubscribe?: Unsubscribe | void;
|
|
19
|
+
}
|
|
20
|
+
declare class SharedSubscriptionsManager extends SharedValuesManager<SharedSubscription<unknown>, {
|
|
21
|
+
fnState: SharedSubscriptionValue<unknown>;
|
|
22
|
+
}> {
|
|
23
|
+
defaultValue(): {
|
|
24
|
+
fnState: {
|
|
25
|
+
data: undefined;
|
|
26
|
+
isLoading: boolean;
|
|
27
|
+
error: undefined;
|
|
28
|
+
subscribed: boolean;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
initValue(key: string, prefix: Prefix, isStatic?: boolean): void;
|
|
32
|
+
setValue<T>(key: string, prefix: Prefix, data: {
|
|
33
|
+
fnState: SharedSubscriptionValue<T>;
|
|
34
|
+
}): void;
|
|
35
|
+
useEffect(key: string, prefix: Prefix): void;
|
|
36
|
+
unsubscribe(key: string, prefix: Prefix): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
export declare class SharedSubscriptionsApi extends SharedValuesApi<SharedSubscription<unknown>, {
|
|
39
|
+
fnState: SharedSubscriptionValue<unknown>;
|
|
40
|
+
}, SharedSubscriptionValue<unknown>> {
|
|
41
|
+
constructor(sharedSubscriptionsManager: SharedSubscriptionsManager);
|
|
42
|
+
get<T, S extends string = string>(key: S, scopeName?: Prefix): SharedSubscriptionValue<T>;
|
|
43
|
+
get<T>(sharedSubscriptionCreated: SharedSubscriptionCreated<T>): SharedSubscriptionValue<T>;
|
|
44
|
+
set<T, S extends string = string>(key: S, value: {
|
|
45
|
+
fnState: SharedSubscriptionValue<T>;
|
|
46
|
+
}, scopeName?: Prefix): void;
|
|
47
|
+
set<T>(sharedSubscriptionCreated: SharedSubscriptionCreated<T>, value: {
|
|
48
|
+
fnState: SharedSubscriptionValue<T>;
|
|
49
|
+
}): void;
|
|
22
50
|
}
|
|
23
51
|
export declare const sharedSubscriptionsApi: SharedSubscriptionsApi;
|
|
24
52
|
interface SharedSubscriptionCreated<T> extends SharedCreated {
|
|
@@ -26,7 +54,7 @@ interface SharedSubscriptionCreated<T> extends SharedCreated {
|
|
|
26
54
|
}
|
|
27
55
|
export declare const createSharedSubscription: <T, Args extends unknown[]>(subscriber: Subscriber<T>, scopeName?: Prefix) => SharedSubscriptionCreated<T>;
|
|
28
56
|
export type SharedSubscriptionStateReturn<T> = {
|
|
29
|
-
readonly state: NonNullable<
|
|
57
|
+
readonly state: NonNullable<SharedSubscriptionValue<T>>;
|
|
30
58
|
readonly trigger: () => void;
|
|
31
59
|
readonly forceTrigger: () => void;
|
|
32
60
|
readonly unsubscribe: () => void;
|