@webkrafters/react-observable-context 4.1.0-rc.5 → 4.1.0-rc.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 +4 -4
- package/dist/model/accessor-cache/index.js +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/utils/index.d.ts +4 -3
- package/dist/utils/index.js +81 -90
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ Subscribing component decides which context state properties' changes to trigger
|
|
|
30
30
|
|
|
31
31
|
**Moniker:** Eagle Eye
|
|
32
32
|
|
|
33
|
-
**Usage:** Please see <b><a href="#getting-started">Getting Started</a></b
|
|
33
|
+
**Usage:** Please see <b><a href="#getting-started">Getting Started</a></b>.
|
|
34
34
|
|
|
35
35
|
**Demo:** [Play with the app on codesandbox](https://codesandbox.io/s/github/webKrafters/react-observable-context-app)\
|
|
36
36
|
If sandbox fails to load app, please refresh dependencies on its lower left.
|
|
@@ -39,7 +39,7 @@ If sandbox fails to load app, please refresh dependencies on its lower left.
|
|
|
39
39
|
npm i -S @webkrafters/react-observable-context\
|
|
40
40
|
npm install --save @webkrafters/react-observable-context
|
|
41
41
|
|
|
42
|
-
May also see <b><a href="#changes">What's Changed?</a></b
|
|
42
|
+
May also see <b><a href="#changes">What's Changed?</a></b>.
|
|
43
43
|
|
|
44
44
|
<h1 id="toc">Table of Contents</h1>
|
|
45
45
|
|
|
@@ -289,9 +289,9 @@ A special property path [@@STATE](#fullstate-selectorkey) may be used to access
|
|
|
289
289
|
## Provider
|
|
290
290
|
The Provider component is a property of the `React-Observable-Context` context object. As a `React.context` based provider, it accepts the customary `children` and `value` props. It also accepts **2** optional props: <a href="#prehooks"><code>prehooks</code></a> and <a href="#storage"><code>storage</code></a>.
|
|
291
291
|
|
|
292
|
-
External direct access to the context store may be obtained via the `ref` attribute. Please see a [Provider Usage](#provider-usage) sample
|
|
292
|
+
External direct access to the context store may be obtained via the `ref` attribute. Please see a [Provider Usage](#provider-usage) sample.
|
|
293
293
|
|
|
294
|
-
Routinely, the `value` prop is initialized with the full initial state. It may only be updated with parts of the state which are changing. Please see a [Provider Usage](#provider-usage) sample
|
|
294
|
+
Routinely, the `value` prop is initialized with the full initial state. It may only be updated with parts of the state which are changing. Please see a [Provider Usage](#provider-usage) sample.
|
|
295
295
|
|
|
296
296
|
<h2 id="selector-map">Selector Map</h2>
|
|
297
297
|
A selector map is an object holding key:value pairs.<br />
|
|
@@ -106,7 +106,7 @@ var AccessorCache = function () {
|
|
|
106
106
|
var _classPrivateMethodGe = _classPrivateMethodGet(this, _getOriginAt, _getOriginAt2).call(this, path),
|
|
107
107
|
exists = _classPrivateMethodGe.exists,
|
|
108
108
|
newAtomVal = _classPrivateMethodGe.value;
|
|
109
|
-
if (path !== _constants.FULL_STATE_SELECTOR && exists && typeof newAtomVal === 'undefined' && !(0, _utils.getProperty)(originChanges, path).
|
|
109
|
+
if (path !== _constants.FULL_STATE_SELECTOR && exists && typeof newAtomVal === 'undefined' && !(0, _utils.getProperty)(originChanges, path).trail.length || (0, _lodash2["default"])(newAtomVal, atoms[path].value)) {
|
|
110
110
|
continue;
|
|
111
111
|
}
|
|
112
112
|
atoms[path].setValue(newAtomVal);
|
package/dist/types.d.ts
CHANGED
|
@@ -33,8 +33,10 @@ export type PropertyInfo<T extends any[] | State> = {
|
|
|
33
33
|
_value: any;
|
|
34
34
|
exists: boolean;
|
|
35
35
|
index: number;
|
|
36
|
-
|
|
36
|
+
isSelf: KeyType;
|
|
37
|
+
key: KeyType;
|
|
37
38
|
source: T;
|
|
39
|
+
trail: Array<KeyType>;
|
|
38
40
|
value: any;
|
|
39
41
|
};
|
|
40
42
|
export type State = {
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ export function mapPathsToObject<T extends {
|
|
|
5
5
|
[x: string]: any;
|
|
6
6
|
}>(source: T, propertyPaths: Array<string>): { [K in keyof T]?: any; };
|
|
7
7
|
export function clonedeep<T, R>(value: T): R;
|
|
8
|
-
export function getProperty(source: T, path:
|
|
9
|
-
export type GetProperty<T extends any[] | import("../types").State = any[] | import("../types").State
|
|
8
|
+
export function getProperty(source: T, path: KeyType | Array<KeyType>, defaultValue: any): PropertyInfo<T>;
|
|
9
|
+
export type GetProperty<T extends any[] | import("../types").State = any[] | import("../types").State> = (source: T, path?: KeyType | Array<KeyType>, defaultValue?: any) => PropertyInfo<T>;
|
|
10
10
|
export type PropertyInfo<T extends any[] | import("../types").State> = import("../types").PropertyInfo<T>;
|
|
11
|
-
export type State = import("../types").State;
|
|
11
|
+
export type State = import("../types").State;
|
|
12
|
+
export type KeyType = import("../types").KeyType;
|
package/dist/utils/index.js
CHANGED
|
@@ -8,8 +8,7 @@ exports.isDataContainer = isDataContainer;
|
|
|
8
8
|
exports.makeReadonly = makeReadonly;
|
|
9
9
|
exports.mapPathsToObject = mapPathsToObject;
|
|
10
10
|
var _lodash = _interopRequireDefault(require("lodash.clonedeepwith"));
|
|
11
|
-
var _lodash2 = _interopRequireDefault(require("lodash.
|
|
12
|
-
var _lodash3 = _interopRequireDefault(require("lodash.isplainobject"));
|
|
11
|
+
var _lodash2 = _interopRequireDefault(require("lodash.isplainobject"));
|
|
13
12
|
var _clonedeepEligibilityCheck = _interopRequireDefault(require("./clonedeep-eligibility-check"));
|
|
14
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
14
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
@@ -89,98 +88,90 @@ var clonedeep = function () {
|
|
|
89
88
|
}();
|
|
90
89
|
exports.clonedeep = clonedeep;
|
|
91
90
|
var getProperty = function () {
|
|
92
|
-
var
|
|
93
|
-
var
|
|
94
|
-
var
|
|
95
|
-
var
|
|
96
|
-
|
|
97
|
-
var index = +key;
|
|
91
|
+
var RE_DELIMITER = /[\[\]|\.]+/g;
|
|
92
|
+
var RE_END_BRACKET_LAST_CHAR = /\]$/;
|
|
93
|
+
var RE_TYPE = /.*\s(\w+)\]$/;
|
|
94
|
+
var toString = Object.prototype.toString;
|
|
95
|
+
var hasEntry = function hasEntry(key, object) {
|
|
98
96
|
try {
|
|
99
|
-
|
|
100
|
-
if (Number.isInteger(index)) {
|
|
101
|
-
if (index < 0) {
|
|
102
|
-
index = source.length + index;
|
|
103
|
-
}
|
|
104
|
-
var _value2 = source[index];
|
|
105
|
-
return {
|
|
106
|
-
_value: _value2,
|
|
107
|
-
exists: index in source,
|
|
108
|
-
index: index,
|
|
109
|
-
key: key,
|
|
110
|
-
source: source,
|
|
111
|
-
value: _value2 !== null && _value2 !== void 0 ? _value2 : defaultValue
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
var _value = source[key];
|
|
116
|
-
exists = key in source;
|
|
117
|
-
return {
|
|
118
|
-
_value: _value,
|
|
119
|
-
exists: exists,
|
|
120
|
-
index: index,
|
|
121
|
-
key: key,
|
|
122
|
-
source: source,
|
|
123
|
-
value: _value !== null && _value !== void 0 ? _value : defaultValue
|
|
124
|
-
};
|
|
97
|
+
return key in object;
|
|
125
98
|
} catch (e) {
|
|
126
|
-
return
|
|
127
|
-
_value: defaultValue,
|
|
128
|
-
exists: exists,
|
|
129
|
-
index: index,
|
|
130
|
-
key: key,
|
|
131
|
-
source: source,
|
|
132
|
-
value: defaultValue
|
|
133
|
-
};
|
|
99
|
+
return false;
|
|
134
100
|
}
|
|
135
101
|
};
|
|
136
|
-
var
|
|
137
|
-
var
|
|
138
|
-
|
|
139
|
-
return source;
|
|
140
|
-
}
|
|
141
|
-
var segmentStart = 0;
|
|
142
|
-
for (var p = segmentStart; p < pLen; p++) {
|
|
143
|
-
var key = parentPath[p];
|
|
144
|
-
var kNum = +key;
|
|
145
|
-
if (Number.isInteger(kNum) && kNum < 0) {
|
|
146
|
-
source = (0, _lodash2["default"])(source, parentPath.slice(segmentStart, p));
|
|
147
|
-
segmentStart = p + 1;
|
|
148
|
-
source = fromSource(source, key).value;
|
|
149
|
-
if (segmentStart === pLen || typeof source === 'undefined') {
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (segmentStart === 0) {
|
|
155
|
-
return (0, _lodash2["default"])(source, parentPath);
|
|
156
|
-
}
|
|
157
|
-
if (segmentStart === pLen || typeof source === 'undefined') {
|
|
158
|
-
return source;
|
|
159
|
-
}
|
|
160
|
-
return (0, _lodash2["default"])(source, parentPath.slice(segmentStart, pLen));
|
|
161
|
-
};
|
|
162
|
-
var getInfo = function getInfo(source, path, defaultValue) {
|
|
163
|
-
switch (Object.prototype.toString.call(path).replace(reType, '$1')) {
|
|
102
|
+
var get = function get(source, path, defaultValue) {
|
|
103
|
+
var _path2, _value2;
|
|
104
|
+
switch (toString.call(path).replace(RE_TYPE, '$1')) {
|
|
164
105
|
case 'String':
|
|
165
|
-
path = path.replace(
|
|
106
|
+
path = path.replace(RE_END_BRACKET_LAST_CHAR, '').split(RE_DELIMITER);
|
|
166
107
|
break;
|
|
167
108
|
case 'Array':
|
|
168
109
|
break;
|
|
110
|
+
case 'Undefined':
|
|
111
|
+
path = [];
|
|
112
|
+
break;
|
|
169
113
|
default:
|
|
170
114
|
path = [path];
|
|
171
115
|
}
|
|
172
|
-
var
|
|
173
|
-
|
|
116
|
+
var _value = source;
|
|
117
|
+
var exists = true;
|
|
118
|
+
var index = NaN;
|
|
119
|
+
var trail = [];
|
|
120
|
+
var _iterator2 = _createForOfIteratorHelper(path),
|
|
121
|
+
_step2;
|
|
122
|
+
try {
|
|
123
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
124
|
+
var p = _step2.value;
|
|
125
|
+
index = NaN;
|
|
126
|
+
if (Array.isArray(_value)) {
|
|
127
|
+
var _index = +p;
|
|
128
|
+
if (Number.isInteger(_index)) {
|
|
129
|
+
if (_index < 0) {
|
|
130
|
+
_index = _value.length + _index;
|
|
131
|
+
}
|
|
132
|
+
index = _index;
|
|
133
|
+
if (index in _value) {
|
|
134
|
+
source = _value;
|
|
135
|
+
_value = _value[index];
|
|
136
|
+
trail.push(index);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
source = _value;
|
|
142
|
+
if (!hasEntry(p, _value)) {
|
|
143
|
+
exists = false;
|
|
144
|
+
_value = undefined;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
_value = _value[p];
|
|
148
|
+
trail.push(p);
|
|
149
|
+
}
|
|
150
|
+
} catch (err) {
|
|
151
|
+
_iterator2.e(err);
|
|
152
|
+
} finally {
|
|
153
|
+
_iterator2.f();
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
_value: _value,
|
|
157
|
+
exists: exists,
|
|
158
|
+
index: index,
|
|
159
|
+
isSelf: !path.length,
|
|
160
|
+
key: (_path2 = path) === null || _path2 === void 0 ? void 0 : _path2[path.length - 1],
|
|
161
|
+
source: path.length && path.length - trail.length < 2 ? source : undefined,
|
|
162
|
+
trail: trail,
|
|
163
|
+
value: (_value2 = _value) !== null && _value2 !== void 0 ? _value2 : defaultValue
|
|
164
|
+
};
|
|
174
165
|
};
|
|
175
|
-
return
|
|
166
|
+
return get;
|
|
176
167
|
}();
|
|
177
168
|
exports.getProperty = getProperty;
|
|
178
169
|
function isDataContainer(v) {
|
|
179
|
-
return (0,
|
|
170
|
+
return (0, _lodash2["default"])(v) || Array.isArray(v);
|
|
180
171
|
}
|
|
181
172
|
function makeReadonly(v) {
|
|
182
173
|
var frozen = true;
|
|
183
|
-
if ((0,
|
|
174
|
+
if ((0, _lodash2["default"])(v)) {
|
|
184
175
|
for (var k in v) {
|
|
185
176
|
makeReadonly(v[k]);
|
|
186
177
|
}
|
|
@@ -198,32 +189,32 @@ function makeReadonly(v) {
|
|
|
198
189
|
;
|
|
199
190
|
function mapPathsToObject(source, propertyPaths) {
|
|
200
191
|
var paths = [];
|
|
201
|
-
var
|
|
202
|
-
|
|
192
|
+
var _iterator3 = _createForOfIteratorHelper(propertyPaths),
|
|
193
|
+
_step3;
|
|
203
194
|
try {
|
|
204
|
-
for (
|
|
205
|
-
var path =
|
|
195
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
196
|
+
var path = _step3.value;
|
|
206
197
|
paths.push(path.replace(/\.?\[/g, '.').replace(/^\.|\]/g, ''));
|
|
207
198
|
}
|
|
208
199
|
} catch (err) {
|
|
209
|
-
|
|
200
|
+
_iterator3.e(err);
|
|
210
201
|
} finally {
|
|
211
|
-
|
|
202
|
+
_iterator3.f();
|
|
212
203
|
}
|
|
213
204
|
var dest = {};
|
|
214
205
|
var object = dest;
|
|
215
|
-
var
|
|
216
|
-
|
|
206
|
+
var _iterator4 = _createForOfIteratorHelper(arrangePropertyPaths(paths)),
|
|
207
|
+
_step4;
|
|
217
208
|
try {
|
|
218
|
-
for (
|
|
219
|
-
var
|
|
220
|
-
var _getProperty = getProperty(source,
|
|
209
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
210
|
+
var _path3 = _step4.value;
|
|
211
|
+
var _getProperty = getProperty(source, _path3),
|
|
221
212
|
exists = _getProperty.exists,
|
|
222
213
|
value = _getProperty.value;
|
|
223
214
|
if (!exists) {
|
|
224
215
|
continue;
|
|
225
216
|
}
|
|
226
|
-
for (var tokens =
|
|
217
|
+
for (var tokens = _path3.split('.'), tLen = tokens.length, t = 0; t < tLen; t++) {
|
|
227
218
|
var token = tokens[t];
|
|
228
219
|
if (t + 1 === tLen) {
|
|
229
220
|
object[token] = value;
|
|
@@ -237,9 +228,9 @@ function mapPathsToObject(source, propertyPaths) {
|
|
|
237
228
|
}
|
|
238
229
|
}
|
|
239
230
|
} catch (err) {
|
|
240
|
-
|
|
231
|
+
_iterator4.e(err);
|
|
241
232
|
} finally {
|
|
242
|
-
|
|
233
|
+
_iterator4.f();
|
|
243
234
|
}
|
|
244
235
|
return dest;
|
|
245
236
|
}
|
package/package.json
CHANGED
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
],
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"lodash.clonedeepwith": "^4.5.0",
|
|
11
|
-
"lodash.get": "^4.4.2",
|
|
12
11
|
"lodash.isboolean": "^3.0.3",
|
|
13
12
|
"lodash.isempty": "^4.4.0",
|
|
14
13
|
"lodash.isequal": "^4.5.0",
|
|
@@ -133,5 +132,5 @@
|
|
|
133
132
|
"test:watch": "eslint --fix && jest --updateSnapshot --watchAll"
|
|
134
133
|
},
|
|
135
134
|
"types": "dist/main/index.d.ts",
|
|
136
|
-
"version": "4.1.0-rc.
|
|
135
|
+
"version": "4.1.0-rc.7"
|
|
137
136
|
}
|