@webkrafters/react-observable-context 4.1.2 → 4.1.4

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.
@@ -30,21 +30,24 @@ export function createContext<T extends import("../types").State>(): ObservableC
30
30
  * {myX: 'd.e.f[1].x'} or {myX: 'd.e.f.1.x'} => {myX: 7} // same applies to {myY: 'd.e.f[1].y'} = {myY: 8}; {myZ: 'd.e.f[1].z'} = {myZ: 9}
31
31
  * {myData: '@@STATE'} => {myData: state}
32
32
  */
33
- export function useContext<T extends import("../types").State>(context: ObservableContext<T>, selectorMap?: SelectorMap<T>): Store<T>;
33
+ export function useContext<T extends import("../types").State>(context: ObservableContext<T>, selectorMap?: BaseSelectorMap<T>): Store<T>;
34
34
 
35
35
  /**
36
- * @param {ObservableContext<T>} context Refers to the PublicObservableContext<T> type of the ObservableContext<T>
37
- * @param {SelectorMap<T>} [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.
38
- * @returns {(WrappedComponent: C) => MemoExoticComponent<P>}
39
- * @template {State} T
40
- * @template {PartialStore<T> & {[x:string]:*}} [P=PartialStore<T>]
41
- * @template {ComponentType<P>|ExoticComponent<P>} C
42
- * @see {ObservableContext<T>}
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 {SELECTOR_MAP} [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 {SelectorMap<STATE>} [SELECTOR_MAP=SelectorMap<STATE>]
46
+ * @template {ComponentType<ConnectedComponentProps<OWNPROPS, PartialStore<STATE>>|ExoticComponent<ConnectedComponentProps<OWNPROPS, PartialStore<STATE>>} [C = ComponentType<ConnectedComponentProps<OWNPROPS, PartialStore<STATE>>]
47
+ * @see {ObservableContext<STATE>}
43
48
  * @see {useContext} for selectorMap sample
44
49
  */
45
- export function connect<T extends import("../types").State, P extends PartialStore<T> & {
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>;
50
+ export function connect<STATE extends import("../types").State, OWNPROPS extends import("../types").State = {}, SELECTOR_MAP extends BaseSelectorMap<STATE> = BaseSelectorMap<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?: SELECTOR_MAP): (WrappedComponent: C) => ConnectedComponent<OWNPROPS, Store<STATE>>;
48
51
  export type CLEAR_TAG = typeof CLEAR_TAG;
49
52
 
50
53
  /** @example changes = { property: CLEAR_TAG } */
@@ -129,7 +132,8 @@ export type StoreRef<T extends import("../types").State> = {
129
132
  export type State = import("../types").State;
130
133
  export type PartialState<T extends import("../types").State> = import("../types").PartialState<T>;
131
134
  export type Prehooks<T extends import("../types").State> = import("../types").Prehooks<T>;
132
- export type SelectorMap<T extends import("../types").State> = {
135
+ export type SelectorMap<T extends import("../types").State = import("../types").State, MAP extends BaseSelectorMap<T> = BaseSelectorMap<T>> = MAP;
136
+ export type BaseSelectorMap<T extends import("../types").State> = {
133
137
  [dataPropKey: string]: string | keyof T;
134
138
  } & {
135
139
  [dataPropKey: string]: "@@STATE";
@@ -143,6 +147,8 @@ export type PartialStore<T extends import("../types").State> = {
143
147
  export type Store<T extends import("../types").State> = import("../types").Store<T>;
144
148
  export type IStore = import("../types").IStore;
145
149
  export type IStorage<T extends import("../types").State> = import("../types").IStorage<T>;
150
+ export type ConnectedComponent<OWNPROPS extends import("../types").State = {}, STORE extends Store<import("../types").State> = Store<import("../types").State>> = MemoExoticComponent<ConnectedComponentProps<OWNPROPS, STORE>>;
151
+ export type ConnectedComponentProps<OWNPROPS extends import("../types").State = {}, STORE extends Store<import("../types").State> = Store<import("../types").State>> = STORE & OWNPROPS;
146
152
  export type NonReactUsageReport = import("../types").NonReactUsageReport;
147
153
  export type Data = import("../types").Data;
148
154
  export type ReactNode = import("react").ReactNode;
package/package.json CHANGED
@@ -133,5 +133,5 @@
133
133
  "test:watch": "eslint --fix && jest --updateSnapshot --watchAll"
134
134
  },
135
135
  "types": "dist/main/index.d.ts",
136
- "version": "4.1.2"
136
+ "version": "4.1.4"
137
137
  }