@webkrafters/react-observable-context 2.1.6 → 2.1.7
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 +12 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,19 +38,25 @@ The context's `store` exposes **4** methods for interacting with the context's i
|
|
|
38
38
|
|
|
39
39
|
* **resetState**: VoidFunction // resets the state to the Provider initial `value` prop.
|
|
40
40
|
|
|
41
|
-
* **setState**: (changes: PartialState\<State\>) => void // sets only new/changed
|
|
41
|
+
* **setState**: (changes: PartialState\<State\>) => void // sets only new/changed state slices.\
|
|
42
|
+
***Do this:*** `setState({stateKey0: changes0[, ...]});`\
|
|
43
|
+
***Not this:*** `setState({stateKey0: {...state.stateKey0, ...changes0}[, ...]});`
|
|
42
44
|
|
|
43
45
|
* **subscribe**: (listener: (newValue: PartialState\<State\>, oldValue: PartialState\<State\>) => void) => ***UnsubscribeFunction***
|
|
44
46
|
|
|
45
47
|
### Prehooks
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
Prehooks provide a central place for sanitizing, modifying, transforming, validating etc. all related incoming state updates.
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
The context store **2** update operations each adhere to its own user specified prehook when present. Otherwise, the update operation proceeds normally to completion. Thus, there are **2** prehooks named **resetState** and **setState** - after the store update methods they support.
|
|
52
|
+
|
|
53
|
+
Each prehook returns a **boolean** value (`true` to continue AND `false` to abort the update operation). The prehook may modify (i.e. sanitize, transform, transpose) the argument to accurately reflect the intended update value. This is done by mutating part of the argument which holds the next `nextUpdate` values.
|
|
50
54
|
|
|
51
|
-
* **
|
|
55
|
+
* **resetState**: (state: {current: State, original: State}) => boolean // ***`state.original`*** holds the `nextUpdate` values.
|
|
52
56
|
|
|
53
|
-
|
|
57
|
+
* **setState**: (newChanges: PartialState\<State\>) => boolean // ***`newChanges`*** holds the `nextUpdate` values.
|
|
58
|
+
|
|
59
|
+
***<u>Use case:</u>*** prehooks provide a central place for sanitizing, modifying, transforming, validating etc. all related incoming state updates.
|
|
54
60
|
|
|
55
61
|
## Usage
|
|
56
62
|
|
|
@@ -81,7 +87,7 @@ The context's store update operation adheres to **2** user supplied prehooks whe
|
|
|
81
87
|
|
|
82
88
|
export default ObservableContext;
|
|
83
89
|
|
|
84
|
-
<i><u>index.js</i
|
|
90
|
+
<i><u>index.js</u></i>
|
|
85
91
|
|
|
86
92
|
import React from 'react';
|
|
87
93
|
import ReactDOM from 'react-dom';
|
package/package.json
CHANGED