@webkrafters/react-observable-context 2.0.0 → 2.0.1
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 +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ The React-Observable-Context package exports **3** modules namely: the **createC
|
|
|
16
16
|
|
|
17
17
|
* **createContext** is a zero-parameter funtion returning a store-bearing context. Pass the context to the React::useContext() parameter to obtain the context's `store`.
|
|
18
18
|
|
|
19
|
-
* **useContext** is analogous to React::useContext hook but returns the context store and takes a second parameter named ***watchedKeys***. The `watchedKeys` parameter is a list of state object property
|
|
19
|
+
* **useContext** is analogous to React::useContext hook but returns the context store and takes a second parameter named ***watchedKeys***. The `watchedKeys` parameter is a list of state object property paths to watch. A change in any of the referenced properties automatically triggers a render of the component calling this hook.
|
|
20
20
|
|
|
21
21
|
* **Provider** can immediately be used as-is anywhere the React-Observable-Context is required. It accepts **3** props and the customary Provider `children` prop. Supply the context to its `context` prop; the initial state to the customary Provider `value` prop; and the optional `prehooks` prop <i>(discussed in the prehooks section below)</i>.
|
|
22
22
|
|
|
@@ -30,7 +30,7 @@ The context's `store` exposes **4** methods for interacting with the context's i
|
|
|
30
30
|
|
|
31
31
|
* **resetState**: VoidFunction // resets the state to the Provider initial `value` prop.
|
|
32
32
|
|
|
33
|
-
* **setState**: (changes: PartialState\<State\>) => void
|
|
33
|
+
* **setState**: (changes: PartialState\<State\>) => void // sets only new/changed top level properties.
|
|
34
34
|
|
|
35
35
|
* **subscribe**: (listener: (newValue: PartialState\<State\>, oldValue: PartialState\<State\>) => void) => ***UnsubscribeFunction***
|
|
36
36
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export class UsageError extends Error {
|
|
2
2
|
}
|
|
3
3
|
export function createContext<T_1 extends State>(): React.Context<Store<T_2>>;
|
|
4
|
-
export function useContext<T_1 extends State>(context: React.Context<Store<T_2>>, watchedKeys?: (keyof T_1)[]): Store<T_1>;
|
|
4
|
+
export function useContext<T_1 extends State>(context: React.Context<Store<T_2>>, watchedKeys?: (string | keyof T_1)[]): Store<T_1>;
|
|
5
5
|
/**
|
|
6
6
|
* Note: `context` prop is not updateable. Furtther updates to this prop are ignored.
|
|
7
7
|
*
|
package/dist/index.js
CHANGED
|
@@ -72,13 +72,14 @@ var createContext = function createContext() {
|
|
|
72
72
|
* Actively monitors the store and triggers component re-render if any of the watched keys in the state objects changes
|
|
73
73
|
*
|
|
74
74
|
* @param {ObservableContext<T>} context
|
|
75
|
-
* @param {Array<keyof T>} [watchedKeys = []]
|
|
75
|
+
* @param {Array<string|keyof T>} [watchedKeys = []] A list of state object property paths to watch. A change in any of the referenced properties results in this component render.
|
|
76
76
|
* @returns {Store<T>}
|
|
77
77
|
* @template {State} T
|
|
78
78
|
*/
|
|
79
79
|
exports.createContext = createContext;
|
|
80
80
|
var useContext = function useContext(context) {
|
|
81
81
|
var watchedKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
82
|
+
/** @type {Store<T>} */
|
|
82
83
|
var store = (0, _react.useContext)(context);
|
|
83
84
|
var _useState = (0, _react.useState)(false),
|
|
84
85
|
_useState2 = _slicedToArray(_useState, 2),
|
package/package.json
CHANGED