@webkrafters/react-observable-context 2.1.5 → 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 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 top level properties.
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
- The context's store update operation adheres to **2** user supplied prehooks when present. Otherwise, the update operation proceeds normally to completion. They are named **resetState** and **setState** after the store update methods which utilize them.
49
+ Prehooks provide a central place for sanitizing, modifying, transforming, validating etc. all related incoming state updates.
48
50
 
49
- * **resetState**: (state: {current: State, original: State}) => boolean
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
- * **setState**: (newChanges: PartialState\<State\>) => boolean
55
+ * **resetState**: (state: {current: State, original: State}) => boolean // ***`state.original`*** holds the `nextUpdate` values.
52
56
 
53
- ***<u>Use case:</u>*** prehooks provide a central place for sanitizing, modifying, transforming, validating etc. all related incoming state updates. The prehook returns a **boolean** value (`true` to continue AND `false` to abort the update operation). The prehook may mutate (i.e. sanitize, transform, transpose) its argument values to accurately reflect the intended update value.
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></b>
90
+ <i><u>index.js</u></i>
85
91
 
86
92
  import React from 'react';
87
93
  import ReactDOM from 'react-dom';
package/dist/index.js CHANGED
@@ -129,7 +129,9 @@ var _setState = function () {
129
129
  if ((0, _lodash5["default"])(state[stateKey]) && isPlainObjectNewState) {
130
130
  return setPlainObject(state, newState, changed, replaced, stateKey);
131
131
  }
132
- replaced[stateKey] = state[stateKey];
132
+ if (stateKey in state) {
133
+ replaced[stateKey] = state[stateKey];
134
+ }
133
135
  state[stateKey] = isArrayNewState || isPlainObjectNewState ? (0, _lodash["default"])(newState[stateKey]) : newState[stateKey];
134
136
  changed[stateKey] = newState[stateKey];
135
137
  };
package/package.json CHANGED
@@ -79,5 +79,5 @@
79
79
  "test:watch": "eslint --fix && jest --updateSnapshot --watchAll"
80
80
  },
81
81
  "types": "dist/index.d.ts",
82
- "version": "2.1.5"
82
+ "version": "2.1.7"
83
83
  }