@webkrafters/react-observable-context 4.0.0-alpha.2 → 4.0.0-alpha.3
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/dist/main/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export class UsageError extends Error {
|
|
2
1
|
[selectorKey: string]: string | keyof T_1;
|
|
3
2
|
Provider: ObservableProvider<S>;
|
|
4
3
|
children?: ReactNode;
|
|
5
4
|
prehooks?: Prehooks<T>;
|
|
6
5
|
storage?: IStorage<T>;
|
|
7
6
|
value: PartialState<T>;
|
|
7
|
+
export class UsageError extends Error {
|
|
8
8
|
[selectorKey: string]: string | keyof T;
|
|
9
9
|
Provider: ObservableProvider<S>;
|
|
10
10
|
children?: ReactNode;
|
|
11
11
|
prehooks?: Prehooks<T>;
|
|
12
12
|
storage?: IStorage<T>;
|
|
13
13
|
value: PartialState<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default Accessor;
|
|
2
1
|
static "__#5@#NUM_INSTANCES": number;
|
|
3
2
|
/**
|
|
4
3
|
* @param {T} source State object reference from which the accessedPropertyPaths are to be selected.
|
|
5
4
|
* @param {Array<string>} accessedPropertyPaths
|
|
6
5
|
*/
|
|
7
6
|
constructor(source: T, accessedPropertyPaths: Array<string>);
|
|
8
7
|
/** @type {boolean} */
|
|
9
8
|
refreshDue: boolean;
|
|
10
9
|
get numClients(): number;
|
|
11
10
|
get id(): number;
|
|
12
11
|
get paths(): string[];
|
|
13
12
|
get value(): {
|
|
14
13
|
[propertyPath: string]: Readonly<any>;
|
|
15
14
|
};
|
|
16
15
|
/** @param {string} clientId */
|
|
17
16
|
addClient(clientId: string): void;
|
|
18
17
|
hasClient(clientId: string): boolean;
|
|
19
18
|
removeClient(clientId: string): boolean;
|
|
20
19
|
/**
|
|
21
20
|
* @param {{[propertyPath: string]: Atom<*>}} atoms Curated slices of state currently requested
|
|
22
21
|
* @returns {{[propertyPath: string]: Readonly<*>}}
|
|
23
22
|
*/
|
|
24
23
|
refreshValue(atoms: {
|
|
25
24
|
[propertyPath: string]: import("../atom").default<any>;
|
|
26
25
|
}): {
|
|
27
26
|
[propertyPath: string]: Readonly<any>;
|
|
28
27
|
};
|
|
29
28
|
#private;
|
|
29
|
+
export default Accessor;
|
|
30
30
|
static "__#5@#NUM_INSTANCES": number;
|
|
31
31
|
/**
|
|
32
32
|
* @param {T} source State object reference from which the accessedPropertyPaths are to be selected.
|
|
33
33
|
* @param {Array<string>} accessedPropertyPaths
|
|
34
34
|
*/
|
|
35
35
|
constructor(source: T, accessedPropertyPaths: Array<string>);
|
|
36
36
|
/** @type {Array<string>} */
|
|
37
37
|
outdatedPaths: Array<string>;
|
|
38
38
|
get numClients(): number;
|
|
39
39
|
get id(): number;
|
|
40
40
|
get paths(): string[];
|
|
41
41
|
get value(): {
|
|
42
42
|
[propertyPath: string]: Readonly<any>;
|
|
43
43
|
};
|
|
44
44
|
/** @param {string} clientId */
|
|
45
45
|
addClient(clientId: string): void;
|
|
46
46
|
hasClient(clientId: string): boolean;
|
|
47
47
|
removeClient(clientId: string): boolean;
|
|
48
48
|
/**
|
|
49
49
|
* @param {{[propertyPath: string]: Atom<*>}} atoms Curated slices of state currently requested
|
|
50
50
|
* @returns {{[propertyPath: string]: Readonly<*>}}
|
|
51
51
|
*/
|
|
52
52
|
refreshValue(atoms: {
|
|
53
53
|
[propertyPath: string]: import("../atom").default<any>;
|
|
54
54
|
}): {
|
|
55
55
|
[propertyPath: string]: Readonly<any>;
|
|
56
56
|
};
|
|
57
57
|
#private;
|
|
@@ -12,8 +12,10 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
12
12
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
13
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
14
14
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
15
|
+
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
15
16
|
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
16
17
|
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
18
|
+
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
17
19
|
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
18
20
|
function _classStaticPrivateFieldSpecSet(receiver, classConstructor, descriptor, value) { _classCheckPrivateStaticAccess(receiver, classConstructor); _classCheckPrivateStaticFieldDescriptor(descriptor, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
|
|
19
21
|
function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { _classCheckPrivateStaticAccess(receiver, classConstructor); _classCheckPrivateStaticFieldDescriptor(descriptor, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
@@ -23,12 +25,14 @@ function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) {
|
|
|
23
25
|
function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
|
|
24
26
|
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
25
27
|
function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
|
|
28
|
+
var MODERATE_NUM_PATHS_THRESHOLD = 8;
|
|
29
|
+
/** @template {State} T */
|
|
26
30
|
var _clients = new WeakMap();
|
|
27
31
|
var _id = new WeakMap();
|
|
28
32
|
var _paths = new WeakMap();
|
|
29
33
|
var _source = new WeakMap();
|
|
30
34
|
var _value = new WeakMap();
|
|
31
|
-
|
|
35
|
+
var _setValueAt = new WeakSet();
|
|
32
36
|
var Accessor = function () {
|
|
33
37
|
/** @type {Set<string>} */
|
|
34
38
|
/** @type {number} */
|
|
@@ -39,6 +43,7 @@ var Accessor = function () {
|
|
|
39
43
|
function Accessor(source, accessedPropertyPaths) {
|
|
40
44
|
var _Accessor$NUM_INSTANC, _Accessor$NUM_INSTANC2;
|
|
41
45
|
_classCallCheck(this, Accessor);
|
|
46
|
+
_classPrivateMethodInitSpec(this, _setValueAt);
|
|
42
47
|
_classPrivateFieldInitSpec(this, _clients, {
|
|
43
48
|
writable: true,
|
|
44
49
|
value: void 0
|
|
@@ -62,8 +67,8 @@ var Accessor = function () {
|
|
|
62
67
|
_classPrivateFieldSet(this, _clients, new Set());
|
|
63
68
|
_classPrivateFieldSet(this, _id, _classStaticPrivateFieldSpecSet(Accessor, Accessor, _NUM_INSTANCES, (_Accessor$NUM_INSTANC2 = _classStaticPrivateFieldSpecGet(Accessor, Accessor, _NUM_INSTANCES), ++_Accessor$NUM_INSTANC2)));
|
|
64
69
|
_classPrivateFieldSet(this, _paths, Array.from(new Set(accessedPropertyPaths)));
|
|
65
|
-
/** @type {
|
|
66
|
-
this.
|
|
70
|
+
/** @type {Array<string>} */
|
|
71
|
+
this.outdatedPaths = _classPrivateFieldGet(this, _paths).slice();
|
|
67
72
|
_classPrivateFieldSet(this, _source, source);
|
|
68
73
|
_classPrivateFieldSet(this, _value, {});
|
|
69
74
|
}
|
|
@@ -87,10 +92,11 @@ var Accessor = function () {
|
|
|
87
92
|
get: function get() {
|
|
88
93
|
return _classPrivateFieldGet(this, _value);
|
|
89
94
|
}
|
|
90
|
-
/**
|
|
95
|
+
/**
|
|
91
96
|
* @param {string} propertyPath
|
|
92
97
|
* @param {Atom<V>} atom
|
|
93
98
|
* @template V
|
|
94
99
|
*/
|
|
95
100
|
}, {
|
|
96
101
|
key: "addClient",
|
|
97
|
-
value:
|
|
102
|
+
value: /** @param {string} clientId */
|
|
103
|
+
function addClient(clientId) {
|
|
98
104
|
_classPrivateFieldGet(this, _clients).add(clientId);
|
|
99
105
|
}
|
|
100
106
|
/** @type {(clientId: string) => boolean} */
|
|
@@ -109,32 +115,72 @@ var Accessor = function () {
|
|
|
109
115
|
}, {
|
|
110
116
|
key: "refreshValue",
|
|
111
117
|
value: function refreshValue(atoms) {
|
|
112
|
-
if (!this.
|
|
118
|
+
if (!this.outdatedPaths.length) {
|
|
113
119
|
return _classPrivateFieldGet(this, _value);
|
|
114
120
|
}
|
|
115
|
-
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
var refreshLen;
|
|
122
|
+
var refreshPaths = {};
|
|
123
|
+
buildRefreshObj: {
|
|
124
|
+
var pathSet = new Set(this.outdatedPaths);
|
|
125
|
+
this.outdatedPaths.length = 0;
|
|
126
|
+
refreshLen = pathSet.size;
|
|
127
|
+
var _iterator = _createForOfIteratorHelper(pathSet),
|
|
128
|
+
_step;
|
|
129
|
+
try {
|
|
130
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
131
|
+
var p = _step.value;
|
|
132
|
+
refreshPaths[p] = true;
|
|
133
|
+
}
|
|
134
|
+
} catch (err) {
|
|
135
|
+
_iterator.e(err);
|
|
136
|
+
} finally {
|
|
137
|
+
_iterator.f();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (refreshLen >= _classPrivateFieldGet(this, _paths).length) {
|
|
141
|
+
var _iterator2 = _createForOfIteratorHelper(_classPrivateFieldGet(this, _paths)),
|
|
142
|
+
_step2;
|
|
143
|
+
try {
|
|
144
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
145
|
+
var _p = _step2.value;
|
|
146
|
+
_p in refreshPaths && _classPrivateMethodGet(this, _setValueAt, _setValueAt2).call(this, _p, atoms[_p]);
|
|
123
147
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
148
|
+
} catch (err) {
|
|
149
|
+
_iterator2.e(err);
|
|
150
|
+
} finally {
|
|
151
|
+
_iterator2.f();
|
|
152
|
+
}
|
|
153
|
+
} else if (_classPrivateFieldGet(this, _paths).length > MODERATE_NUM_PATHS_THRESHOLD) {
|
|
154
|
+
var pathsObj = {};
|
|
155
|
+
var _iterator3 = _createForOfIteratorHelper(_classPrivateFieldGet(this, _paths).length),
|
|
156
|
+
_step3;
|
|
157
|
+
try {
|
|
158
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
159
|
+
var _p3 = _step3.value;
|
|
160
|
+
pathsObj[_p3] = true;
|
|
161
|
+
}
|
|
162
|
+
} catch (err) {
|
|
163
|
+
_iterator3.e(err);
|
|
164
|
+
} finally {
|
|
165
|
+
_iterator3.f();
|
|
166
|
+
}
|
|
167
|
+
for (var _p2 in refreshPaths) {
|
|
168
|
+
_p2 in pathsObj && _classPrivateMethodGet(this, _setValueAt, _setValueAt2).call(this, _p2, atoms[_p2]);
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
for (var _p4 in refreshPaths) {
|
|
172
|
+
_classPrivateFieldGet(this, _paths).includes(_p4) && _classPrivateMethodGet(this, _setValueAt, _setValueAt2).call(this, _p4, atoms[_p4]);
|
|
127
173
|
}
|
|
128
|
-
} catch (err) {
|
|
129
|
-
_iterator.e(err);
|
|
130
|
-
} finally {
|
|
131
|
-
_iterator.f();
|
|
132
174
|
}
|
|
133
175
|
return _classPrivateFieldGet(this, _value);
|
|
134
176
|
}
|
|
135
177
|
}]);
|
|
136
178
|
return Accessor;
|
|
137
179
|
}();
|
|
180
|
+
function _setValueAt2(propertyPath, atom) {
|
|
181
|
+
!atom.isConnected(_classPrivateFieldGet(this, _id)) && atom.connect(_classPrivateFieldGet(this, _id));
|
|
182
|
+
_classPrivateFieldGet(this, _value)[propertyPath] = atom.value;
|
|
183
|
+
}
|
|
138
184
|
var _NUM_INSTANCES = {
|
|
139
185
|
writable: true,
|
|
140
186
|
value: 0
|
|
@@ -111,7 +111,7 @@ var AccessorCache = function () {
|
|
|
111
111
|
value: function watchSource(originChanges) {
|
|
112
112
|
var accessors = _classPrivateFieldGet(this, _accessors);
|
|
113
113
|
var atoms = _classPrivateFieldGet(this, _atoms);
|
|
114
|
-
var updatedPaths =
|
|
114
|
+
var updatedPaths = [];
|
|
115
115
|
for (var path in atoms) {
|
|
116
116
|
if (path !== _constants.FULL_STATE_SELECTOR && !(0, _lodash2["default"])(originChanges, path)) {
|
|
117
117
|
continue;
|
|
@@ -121,17 +121,14 @@ var AccessorCache = function () {
|
|
|
121
121
|
continue;
|
|
122
122
|
}
|
|
123
123
|
atoms[path].setValue(newAtomVal);
|
|
124
|
-
updatedPaths
|
|
124
|
+
updatedPaths.push(path);
|
|
125
125
|
}
|
|
126
|
-
if (
|
|
126
|
+
if (!updatedPaths.length) {
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
129
129
|
for (var k in accessors) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return p in updatedPaths;
|
|
133
|
-
});
|
|
134
|
-
}
|
|
130
|
+
var _accessors$k$outdated;
|
|
131
|
+
(_accessors$k$outdated = accessors[k].outdatedPaths).push.apply(_accessors$k$outdated, updatedPaths);
|
|
135
132
|
}
|
|
136
133
|
}
|
|
137
134
|
}]);
|
package/package.json
CHANGED