@webkrafters/react-observable-context 2.1.4 → 2.1.6

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.
Files changed (2) hide show
  1. package/dist/index.js +10 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -113,6 +113,10 @@ var useContext = function useContext(context) {
113
113
  exports.useContext = useContext;
114
114
  var defaultPrehooks = Object.freeze({});
115
115
  var _setState = function () {
116
+ var initDiff = function initDiff(propKey, changed, replaced) {
117
+ changed[propKey] = {};
118
+ replaced[propKey] = {};
119
+ };
116
120
  var setAtomic = function setAtomic(state, newState, changed, replaced, stateKey) {
117
121
  if ((0, _lodash4["default"])(state[stateKey], newState[stateKey])) {
118
122
  return;
@@ -125,23 +129,21 @@ var _setState = function () {
125
129
  if ((0, _lodash5["default"])(state[stateKey]) && isPlainObjectNewState) {
126
130
  return setPlainObject(state, newState, changed, replaced, stateKey);
127
131
  }
128
- replaced[stateKey] = state[stateKey];
132
+ if (stateKey in state) {
133
+ replaced[stateKey] = state[stateKey];
134
+ }
129
135
  state[stateKey] = isArrayNewState || isPlainObjectNewState ? (0, _lodash["default"])(newState[stateKey]) : newState[stateKey];
130
136
  changed[stateKey] = newState[stateKey];
131
137
  };
132
138
  var setArray = function setArray(state, newState, changed, replaced, rootKey) {
133
- changed[rootKey] = {};
134
- replaced[rootKey] = {};
139
+ initDiff(rootKey, changed, replaced);
135
140
  for (var i = 0, len = newState[rootKey].length; i < len; i++) {
136
141
  setAtomic(state[rootKey], newState[rootKey], changed[rootKey], replaced[rootKey], i);
137
142
  }
138
143
  };
139
144
  var setPlainObject = function setPlainObject(state, newState, changed, replaced, rootKey) {
140
- changed[rootKey] = {};
141
- replaced[rootKey] = {};
142
- for (var k in newState[rootKey]) {
143
- setAtomic(state[rootKey], newState[rootKey], changed[rootKey], replaced[rootKey], k);
144
- }
145
+ initDiff(rootKey, changed, replaced);
146
+ set(state[rootKey], newState[rootKey], changed[rootKey], replaced[rootKey]);
145
147
  };
146
148
  var set = function set(state, newState) {
147
149
  var changed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
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.4"
82
+ "version": "2.1.6"
83
83
  }