@webkrafters/react-observable-context 4.1.1 → 4.1.3
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.
|
@@ -16,7 +16,7 @@ declare function useStore<T extends import("../../../types").State>(prehooks: Pr
|
|
|
16
16
|
[propertyPaths: string]: Readonly<any>;
|
|
17
17
|
};
|
|
18
18
|
resetState: (propertyPaths?: string[]) => void;
|
|
19
|
-
setState: (changes: import("../../../types").
|
|
19
|
+
setState: (changes: import("../../../types").Changes<T>) => void;
|
|
20
20
|
state: T;
|
|
21
21
|
subscribe: (listener: import("../../../types").Listener<T>) => VoidFunction;
|
|
22
22
|
unlinkCache: (clientId: string) => void;
|
package/dist/main/index.d.ts
CHANGED
|
@@ -33,18 +33,20 @@ export function createContext<T extends import("../types").State>(): ObservableC
|
|
|
33
33
|
export function useContext<T extends import("../types").State>(context: ObservableContext<T>, selectorMap?: SelectorMap<T>): Store<T>;
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @
|
|
41
|
-
* @
|
|
42
|
-
* @
|
|
36
|
+
* Provides an HOC function for connecting its WrappedComponent argument to the context store.
|
|
37
|
+
*
|
|
38
|
+
* The HOC function automatically memoizes any un-memoized WrappedComponent argument.
|
|
39
|
+
*
|
|
40
|
+
* @param {ObservableContext<STATE>} context - Refers to the PublicObservableContext<T> type of the ObservableContext<T>
|
|
41
|
+
* @param {SelectorMap<STATE>} [selectorMap] - Key:value pairs where `key` => arbitrary key given to a Store.data property holding a state slice and `value` => property path to a state slice used by this component: see examples below. May add a mapping for a certain arbitrary key='state' and value='@@STATE' to indicate a desire to obtain the entire state object and assign to a `state` property of Store.data. A change in any of the referenced properties results in this component render. When using '@@STATE', note that any change within the state object will result in this component render.
|
|
42
|
+
* @returns {(WrappedComponent: C) => ConnectedComponent<OWNPROPS, Store<STATE>>} - Connector HOC function
|
|
43
|
+
* @template {State} STATE
|
|
44
|
+
* @template {State} [OWNPROPS = {}]
|
|
45
|
+
* @template {ComponentType<ConnectedComponentProps<OWNPROPS, PartialStore<STATE>>|ExoticComponent<ConnectedComponentProps<OWNPROPS, PartialStore<STATE>>} [C = ComponentType<ConnectedComponentProps<OWNPROPS, PartialStore<STATE>>]
|
|
46
|
+
* @see {ObservableContext<STATE>}
|
|
43
47
|
* @see {useContext} for selectorMap sample
|
|
44
48
|
*/
|
|
45
|
-
export function connect<
|
|
46
|
-
[x: string]: any;
|
|
47
|
-
} = PartialStore<T>, C extends ComponentType<P> | import("react").ExoticComponent<ComponentType<P>>>(context: ObservableContext<T>, selectorMap?: SelectorMap<T>): (WrappedComponent: C) => MemoExoticComponent<P>;
|
|
49
|
+
export function connect<STATE extends import("../types").State, OWNPROPS extends import("../types").State = {}, C extends ComponentType<ConnectedComponentProps<OWNPROPS, PartialStore<STATE>> | import("react").ExoticComponent<ComponentType<ConnectedComponentProps<OWNPROPS, PartialStore<STATE>>>>> = ComponentType<ConnectedComponentProps<OWNPROPS, PartialStore<STATE>>>>(context: ObservableContext<STATE>, selectorMap?: SelectorMap<STATE>): (WrappedComponent: C) => ConnectedComponent<OWNPROPS, Store<STATE>>;
|
|
48
50
|
export type CLEAR_TAG = typeof CLEAR_TAG;
|
|
49
51
|
|
|
50
52
|
/** @example changes = { property: CLEAR_TAG } */
|
|
@@ -123,7 +125,7 @@ export type StoreRef<T extends import("../types").State> = {
|
|
|
123
125
|
getState: () => T;
|
|
124
126
|
} & {
|
|
125
127
|
resetState: (propertyPaths?: string[]) => void;
|
|
126
|
-
setState: (changes: import("../types").
|
|
128
|
+
setState: (changes: import("../types").Changes<T>) => void;
|
|
127
129
|
subscribe: (listener: import("../types").Listener<T>) => VoidFunction;
|
|
128
130
|
};
|
|
129
131
|
export type State = import("../types").State;
|
|
@@ -138,11 +140,13 @@ export type StoreInternal<T extends import("../types").State> = import("../types
|
|
|
138
140
|
export type PartialStore<T extends import("../types").State> = {
|
|
139
141
|
data?: import("../types").Data;
|
|
140
142
|
resetState?: (propertyPaths?: string[]) => void;
|
|
141
|
-
setState?: (changes: import("../types").
|
|
143
|
+
setState?: (changes: import("../types").Changes<T>) => void;
|
|
142
144
|
};
|
|
143
145
|
export type Store<T extends import("../types").State> = import("../types").Store<T>;
|
|
144
146
|
export type IStore = import("../types").IStore;
|
|
145
147
|
export type IStorage<T extends import("../types").State> = import("../types").IStorage<T>;
|
|
148
|
+
export type ConnectedComponent<OWNPROPS extends import("../types").State = {}, STORE extends Store<import("../types").State> = Store<import("../types").State>> = MemoExoticComponent<ConnectedComponentProps<OWNPROPS, STORE>>;
|
|
149
|
+
export type ConnectedComponentProps<OWNPROPS extends import("../types").State = {}, STORE extends Store<import("../types").State> = Store<import("../types").State>> = STORE & OWNPROPS;
|
|
146
150
|
export type NonReactUsageReport = import("../types").NonReactUsageReport;
|
|
147
151
|
export type Data = import("../types").Data;
|
|
148
152
|
export type ReactNode = import("react").ReactNode;
|
|
@@ -7,6 +7,6 @@ declare class AccessorCache<T extends import("../../types").State> {
|
|
|
7
7
|
[propertyPaths: string]: Readonly<any>;
|
|
8
8
|
};
|
|
9
9
|
unlinkClient(clientId: string): void;
|
|
10
|
-
watchSource(changes: import("../../types").
|
|
10
|
+
watchSource(changes: import("../../types").Changes<T>): void;
|
|
11
11
|
#private;
|
|
12
12
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type IStore = {
|
|
|
19
19
|
subscribe: NonReactUsageReport;
|
|
20
20
|
};
|
|
21
21
|
export type KeyType = number | string | symbol;
|
|
22
|
-
export type Listener<T extends State> = (changes:
|
|
22
|
+
export type Listener<T extends State> = (changes: Changes<T>) => void;
|
|
23
23
|
export type NonReactUsageReport = () => never;
|
|
24
24
|
export type PartialState<T extends State> = { [K in keyof T]?: T[K]; };
|
|
25
25
|
export type Prehooks<T extends State> = {
|
|
@@ -27,7 +27,7 @@ export type Prehooks<T extends State> = {
|
|
|
27
27
|
current: T;
|
|
28
28
|
original: T;
|
|
29
29
|
}) => boolean;
|
|
30
|
-
setState?: (newChanges:
|
|
30
|
+
setState?: (newChanges: Changes<T>) => boolean;
|
|
31
31
|
};
|
|
32
32
|
export type State = {
|
|
33
33
|
[x: string]: any;
|
|
@@ -36,7 +36,7 @@ export type State = {
|
|
|
36
36
|
};
|
|
37
37
|
export type StoreInternal<T extends State> = {
|
|
38
38
|
resetState: (propertyPaths?: string[]) => void;
|
|
39
|
-
setState: (changes:
|
|
39
|
+
setState: (changes: Changes<T>) => void;
|
|
40
40
|
} & {
|
|
41
41
|
getState: (clientId: string, ...propertyPaths?: string[]) => {
|
|
42
42
|
[propertyPaths: string]: Readonly<any>;
|
|
@@ -47,8 +47,9 @@ export type StoreInternal<T extends State> = {
|
|
|
47
47
|
export type Store<T extends State> = {
|
|
48
48
|
data: Data;
|
|
49
49
|
resetState: (propertyPaths?: string[]) => void;
|
|
50
|
-
setState: (changes:
|
|
50
|
+
setState: (changes: Changes<T>) => void;
|
|
51
51
|
};
|
|
52
|
+
export type Changes<T extends State> = UpdatePayload<PartialState<T>>;
|
|
52
53
|
export type UpdateStats = {
|
|
53
54
|
hasChanges: boolean;
|
|
54
55
|
};
|
package/package.json
CHANGED