@webkrafters/react-observable-context 4.0.0-alpha.2 → 4.0.0-alpha.4
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/constants.d.ts +1 -1
- package/dist/constants.js +0 -2
- package/dist/main/hooks/use-prehooks-ref/index.d.ts +1 -1
- package/dist/main/hooks/use-prehooks-ref/index.js +0 -1
- package/dist/main/hooks/use-render-key-provider/index.d.ts +1 -1
- package/dist/main/hooks/use-render-key-provider/index.js +6 -18
- package/dist/main/hooks/use-state-manager/index.d.ts +1 -1
- package/dist/main/hooks/use-state-manager/index.js +0 -6
- package/dist/main/hooks/use-store/index.d.ts +1 -1
- package/dist/main/hooks/use-store/index.js +8 -12
- package/dist/main/index.d.ts +41 -1
- package/dist/main/index.js +41 -30
- package/dist/main/set-state/index.d.ts +1 -1
- package/dist/main/set-state/index.js +0 -7
- package/dist/model/accessor/index.d.ts +1 -1
- package/dist/model/accessor/index.js +64 -30
- package/dist/model/accessor-cache/index.d.ts +1 -1
- package/dist/model/accessor-cache/index.js +5 -17
- package/dist/model/atom/index.d.ts +1 -1
- package/dist/model/atom/index.js +0 -8
- package/dist/model/storage/index.d.ts +1 -1
- package/dist/model/storage/index.js +17 -17
- package/dist/types.d.ts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +139 -7
- package/package.json +4 -3
|
@@ -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
|
constructor(source: T, accessedPropertyPaths: Array<string>);
|
|
32
32
|
outdatedPaths: Array<string>;
|
|
33
33
|
get numClients(): number;
|
|
34
34
|
get id(): number;
|
|
35
35
|
get paths(): string[];
|
|
36
36
|
get value(): {
|
|
37
37
|
[propertyPath: string]: Readonly<any>;
|
|
38
38
|
};
|
|
39
39
|
addClient(clientId: string): void;
|
|
40
40
|
hasClient(clientId: string): boolean;
|
|
41
41
|
removeClient(clientId: string): boolean;
|
|
42
42
|
refreshValue(atoms: {
|
|
43
43
|
[propertyPath: string]: import("../atom").default<any>;
|
|
44
44
|
}): {
|
|
45
45
|
[propertyPath: string]: Readonly<any>;
|
|
46
46
|
};
|
|
47
47
|
#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,22 +25,18 @@ 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;
|
|
26
29
|
var _clients = new WeakMap();
|
|
27
30
|
var _id = new WeakMap();
|
|
28
31
|
var _paths = new WeakMap();
|
|
29
32
|
var _source = new WeakMap();
|
|
30
33
|
var _value = new WeakMap();
|
|
31
|
-
|
|
34
|
+
var _setValueAt = new WeakSet();
|
|
32
35
|
var Accessor = function () {
|
|
33
|
-
/** @type {Set<string>} */
|
|
34
|
-
/** @type {number} */
|
|
35
|
-
/** @type {Array<string>} */
|
|
36
|
-
/** @type {T} */
|
|
37
|
-
/** @type {{[propertyPath: string]: Readonly<*>}} */
|
|
38
|
-
/**
|
|
39
36
|
* @param {T} source State object reference from which the accessedPropertyPaths are to be selected.
|
|
40
37
|
* @param {Array<string>} accessedPropertyPaths
|
|
41
38
|
*/
|
|
42
39
|
function Accessor(source, accessedPropertyPaths) {
|
|
43
40
|
var _Accessor$NUM_INSTANC, _Accessor$NUM_INSTANC2;
|
|
44
41
|
_classCallCheck(this, Accessor);
|
|
42
|
+
_classPrivateMethodInitSpec(this, _setValueAt);
|
|
45
43
|
_classPrivateFieldInitSpec(this, _clients, {
|
|
46
44
|
writable: true,
|
|
47
45
|
value: void 0
|
|
@@ -62,8 +60,7 @@ var Accessor = function () {
|
|
|
62
60
|
_classPrivateFieldSet(this, _clients, new Set());
|
|
63
61
|
_classPrivateFieldSet(this, _id, _classStaticPrivateFieldSpecSet(Accessor, Accessor, _NUM_INSTANCES, (_Accessor$NUM_INSTANC2 = _classStaticPrivateFieldSpecGet(Accessor, Accessor, _NUM_INSTANCES), ++_Accessor$NUM_INSTANC2)));
|
|
64
62
|
_classPrivateFieldSet(this, _paths, Array.from(new Set(accessedPropertyPaths)));
|
|
65
|
-
|
|
66
|
-
this.refreshDue = true;
|
|
63
|
+
this.outdatedPaths = _classPrivateFieldGet(this, _paths).slice();
|
|
67
64
|
_classPrivateFieldSet(this, _source, source);
|
|
68
65
|
_classPrivateFieldSet(this, _value, {});
|
|
69
66
|
}
|
|
@@ -87,54 +84,91 @@ var Accessor = function () {
|
|
|
87
84
|
get: function get() {
|
|
88
85
|
return _classPrivateFieldGet(this, _value);
|
|
89
86
|
}
|
|
90
|
-
/** @param {string} clientId */
|
|
91
87
|
}, {
|
|
92
88
|
key: "addClient",
|
|
93
|
-
value:
|
|
89
|
+
value:
|
|
90
|
+
function addClient(clientId) {
|
|
94
91
|
_classPrivateFieldGet(this, _clients).add(clientId);
|
|
95
92
|
}
|
|
96
|
-
/** @type {(clientId: string) => boolean} */
|
|
97
93
|
}, {
|
|
98
94
|
key: "hasClient",
|
|
99
95
|
value: function hasClient(clientId) {
|
|
100
96
|
return _classPrivateFieldGet(this, _clients).has(clientId);
|
|
101
97
|
}
|
|
102
|
-
/** @type {(clientId: string) => boolean} */
|
|
103
98
|
}, {
|
|
104
99
|
key: "removeClient",
|
|
105
100
|
value: function removeClient(clientId) {
|
|
106
101
|
return _classPrivateFieldGet(this, _clients)["delete"](clientId);
|
|
107
102
|
}
|
|
108
|
-
/**
|
|
109
103
|
* @param {{[propertyPath: string]: Atom<*>}} atoms Curated slices of state currently requested
|
|
110
104
|
* @returns {{[propertyPath: string]: Readonly<*>}}
|
|
111
105
|
*/
|
|
112
106
|
}, {
|
|
113
107
|
key: "refreshValue",
|
|
114
108
|
value: function refreshValue(atoms) {
|
|
115
|
-
if (!this.
|
|
109
|
+
if (!this.outdatedPaths.length) {
|
|
116
110
|
return _classPrivateFieldGet(this, _value);
|
|
117
111
|
}
|
|
118
|
-
|
|
119
|
-
var
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
112
|
+
var refreshLen;
|
|
113
|
+
var refreshPaths = {};
|
|
114
|
+
buildRefreshObj: {
|
|
115
|
+
var pathSet = new Set(this.outdatedPaths);
|
|
116
|
+
this.outdatedPaths.length = 0;
|
|
117
|
+
refreshLen = pathSet.size;
|
|
118
|
+
var _iterator = _createForOfIteratorHelper(pathSet),
|
|
119
|
+
_step;
|
|
120
|
+
try {
|
|
121
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
122
|
+
var p = _step.value;
|
|
123
|
+
refreshPaths[p] = true;
|
|
126
124
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
} catch (err) {
|
|
126
|
+
_iterator.e(err);
|
|
127
|
+
} finally {
|
|
128
|
+
_iterator.f();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (refreshLen >= _classPrivateFieldGet(this, _paths).length) {
|
|
132
|
+
var _iterator2 = _createForOfIteratorHelper(_classPrivateFieldGet(this, _paths)),
|
|
133
|
+
_step2;
|
|
134
|
+
try {
|
|
135
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
136
|
+
var _p = _step2.value;
|
|
137
|
+
_p in refreshPaths && _classPrivateMethodGet(this, _setValueAt, _setValueAt2).call(this, _p, atoms[_p]);
|
|
138
|
+
}
|
|
139
|
+
} catch (err) {
|
|
140
|
+
_iterator2.e(err);
|
|
141
|
+
} finally {
|
|
142
|
+
_iterator2.f();
|
|
143
|
+
}
|
|
144
|
+
} else if (_classPrivateFieldGet(this, _paths).length > MODERATE_NUM_PATHS_THRESHOLD) {
|
|
145
|
+
var pathsObj = {};
|
|
146
|
+
var _iterator3 = _createForOfIteratorHelper(_classPrivateFieldGet(this, _paths).length),
|
|
147
|
+
_step3;
|
|
148
|
+
try {
|
|
149
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
150
|
+
var _p3 = _step3.value;
|
|
151
|
+
pathsObj[_p3] = true;
|
|
152
|
+
}
|
|
153
|
+
} catch (err) {
|
|
154
|
+
_iterator3.e(err);
|
|
155
|
+
} finally {
|
|
156
|
+
_iterator3.f();
|
|
157
|
+
}
|
|
158
|
+
for (var _p2 in refreshPaths) {
|
|
159
|
+
_p2 in pathsObj && _classPrivateMethodGet(this, _setValueAt, _setValueAt2).call(this, _p2, atoms[_p2]);
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
for (var _p4 in refreshPaths) {
|
|
163
|
+
_classPrivateFieldGet(this, _paths).includes(_p4) && _classPrivateMethodGet(this, _setValueAt, _setValueAt2).call(this, _p4, atoms[_p4]);
|
|
130
164
|
}
|
|
131
|
-
} catch (err) {
|
|
132
|
-
_iterator.e(err);
|
|
133
|
-
} finally {
|
|
134
|
-
_iterator.f();
|
|
135
165
|
}
|
|
136
166
|
return _classPrivateFieldGet(this, _value);
|
|
137
167
|
}
|
|
138
168
|
}]);
|
|
139
169
|
return Accessor;
|
|
140
170
|
}();
|
|
171
|
+
function _setValueAt2(propertyPath, atom) {
|
|
172
|
+
!atom.isConnected(_classPrivateFieldGet(this, _id)) && atom.connect(_classPrivateFieldGet(this, _id));
|
|
173
|
+
_classPrivateFieldGet(this, _value)[propertyPath] = atom.value;
|
|
174
|
+
}
|
|
141
175
|
var _NUM_INSTANCES = {
|
|
142
176
|
writable: true,
|
|
143
177
|
value: 0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default AccessorCache;
|
|
2
1
|
/** @param {T} origin State object reference from which slices stored in this cache are to be curated */
|
|
3
2
|
constructor(origin: T);
|
|
4
3
|
/**
|
|
5
4
|
* Gets state slice from the cache matching the `propertyPaths`.\
|
|
6
5
|
* If not found, creates a new entry for the client from source, and returns it.
|
|
7
6
|
*
|
|
8
7
|
* @param {string} clientId
|
|
9
8
|
* @param {...string} propertyPaths
|
|
10
9
|
* @return {{[propertyPaths: string]: Readonly<*>}}
|
|
11
10
|
*/
|
|
12
11
|
get(clientId: string, ...propertyPaths: string[]): {
|
|
13
12
|
[propertyPaths: string]: Readonly<any>;
|
|
14
13
|
};
|
|
15
14
|
/**
|
|
16
15
|
* Unlinks a consumer from the cache: performing synchronized state cleanup
|
|
17
16
|
*
|
|
18
17
|
* @param {string} clientId
|
|
19
18
|
*/
|
|
20
19
|
unlinkClient(clientId: string): void;
|
|
21
20
|
watchSource(changes: import("../../types").PartialState<T>): void;
|
|
22
21
|
#private;
|
|
22
|
+
export default AccessorCache;
|
|
23
23
|
constructor(origin: T);
|
|
24
24
|
get(clientId: string, ...propertyPaths: string[]): {
|
|
25
25
|
[propertyPaths: string]: Readonly<any>;
|
|
26
26
|
};
|
|
27
27
|
unlinkClient(clientId: string): void;
|
|
28
28
|
watchSource(changes: import("../../types").PartialState<T>): void;
|
|
29
29
|
#private;
|
|
@@ -34,12 +34,7 @@ var _atoms = new WeakMap();
|
|
|
34
34
|
var _origin = new WeakMap();
|
|
35
35
|
var _createAccessor = new WeakSet();
|
|
36
36
|
var _getOriginAt = new WeakSet();
|
|
37
|
-
/** @template {State} T */
|
|
38
37
|
var AccessorCache = function () {
|
|
39
|
-
/** @type {{[propertyPaths: string]: Accessor<T>}} */
|
|
40
|
-
/** @type {{[propertyPath: string]: Atom<*>}} */
|
|
41
|
-
/** @type {T} */
|
|
42
|
-
/** @param {T} origin State object reference from which slices stored in this cache are to be curated */
|
|
43
38
|
function AccessorCache(origin) {
|
|
44
39
|
_classCallCheck(this, AccessorCache);
|
|
45
40
|
_classPrivateMethodInitSpec(this, _getOriginAt);
|
|
@@ -60,11 +55,9 @@ var AccessorCache = function () {
|
|
|
60
55
|
_classPrivateFieldSet(this, _atoms, {});
|
|
61
56
|
_classPrivateFieldSet(this, _origin, origin);
|
|
62
57
|
}
|
|
63
|
-
/**
|
|
64
58
|
* Add new cache entry
|
|
65
59
|
*
|
|
66
60
|
* @param {string} cacheKey
|
|
67
61
|
* @param {Array<string>} propertyPaths
|
|
68
62
|
* @return {Accessor<T>}
|
|
69
63
|
*/
|
|
70
64
|
_createClass(AccessorCache, [{
|
|
71
65
|
key: "get",
|
|
72
66
|
value:
|
|
73
|
-
/**
|
|
74
67
|
* Gets state slice from the cache matching the `propertyPaths`.\
|
|
75
68
|
* If not found, creates a new entry for the client from source, and returns it.
|
|
76
69
|
*
|
|
77
70
|
* @param {string} clientId
|
|
78
71
|
* @param {...string} propertyPaths
|
|
79
72
|
* @return {{[propertyPaths: string]: Readonly<*>}}
|
|
80
73
|
*/
|
|
81
74
|
function get(clientId) {
|
|
82
75
|
for (var _len = arguments.length, propertyPaths = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
83
76
|
propertyPaths[_key - 1] = arguments[_key];
|
|
@@ -77,7 +70,6 @@ var AccessorCache = function () {
|
|
|
77
70
|
!accessor.hasClient(clientId) && accessor.addClient(clientId);
|
|
78
71
|
return accessor.refreshValue(_classPrivateFieldGet(this, _atoms));
|
|
79
72
|
}
|
|
80
|
-
/**
|
|
81
73
|
* Unlinks a consumer from the cache: performing synchronized state cleanup
|
|
82
74
|
*
|
|
83
75
|
* @param {string} clientId
|
|
84
76
|
*/
|
|
85
77
|
}, {
|
|
86
78
|
key: "unlinkClient",
|
|
87
79
|
value: function unlinkClient(clientId) {
|
|
@@ -105,13 +97,12 @@ var AccessorCache = function () {
|
|
|
105
97
|
delete accessors[k];
|
|
106
98
|
}
|
|
107
99
|
}
|
|
108
|
-
/**
|
|
109
100
|
* Observes the origin state bearing ObservableContext store for state changes to update accessors.
|
|
110
101
|
*
|
|
111
102
|
* @type {Listener<T>}
|
|
112
103
|
*/
|
|
113
104
|
}, {
|
|
114
105
|
key: "watchSource",
|
|
115
106
|
value: function watchSource(originChanges) {
|
|
116
107
|
var accessors = _classPrivateFieldGet(this, _accessors);
|
|
117
108
|
var atoms = _classPrivateFieldGet(this, _atoms);
|
|
118
|
-
var updatedPaths =
|
|
109
|
+
var updatedPaths = [];
|
|
119
110
|
for (var path in atoms) {
|
|
120
111
|
if (path !== _constants.FULL_STATE_SELECTOR && !(0, _lodash2["default"])(originChanges, path)) {
|
|
121
112
|
continue;
|
|
@@ -121,17 +112,14 @@ var AccessorCache = function () {
|
|
|
121
112
|
continue;
|
|
122
113
|
}
|
|
123
114
|
atoms[path].setValue(newAtomVal);
|
|
124
|
-
updatedPaths
|
|
115
|
+
updatedPaths.push(path);
|
|
125
116
|
}
|
|
126
|
-
if (
|
|
117
|
+
if (!updatedPaths.length) {
|
|
127
118
|
return;
|
|
128
119
|
}
|
|
129
120
|
for (var k in accessors) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return p in updatedPaths;
|
|
133
|
-
});
|
|
134
|
-
}
|
|
121
|
+
var _accessors$k$outdated;
|
|
122
|
+
(_accessors$k$outdated = accessors[k].outdatedPaths).push.apply(_accessors$k$outdated, updatedPaths);
|
|
135
123
|
}
|
|
136
124
|
}
|
|
137
125
|
}]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default Atom;
|
|
2
1
|
constructor(value?: any);
|
|
3
2
|
get value(): Readonly<T>;
|
|
4
3
|
/**
|
|
5
4
|
* @param {number} accessorId
|
|
6
5
|
* @returns {number} Number of connections remaining
|
|
7
6
|
*/
|
|
8
7
|
connect(accessorId: number): number;
|
|
9
8
|
/**
|
|
10
9
|
* @param {number} accessorId
|
|
11
10
|
* @returns {number} Number of connections remaining
|
|
12
11
|
*/
|
|
13
12
|
disconnect(accessorId: number): number;
|
|
14
13
|
/** @param {number} accessorId */
|
|
15
14
|
isConnected(accessorId: number): boolean;
|
|
16
15
|
/** @param {T|Readonly<T>} newValue */
|
|
17
16
|
setValue(newValue: T | Readonly<T>): void;
|
|
18
17
|
#private;
|
|
18
|
+
export default Atom;
|
|
19
19
|
constructor(value?: any);
|
|
20
20
|
get value(): Readonly<T>;
|
|
21
21
|
connect(accessorId: number): number;
|
|
22
22
|
disconnect(accessorId: number): number;
|
|
23
23
|
isConnected(accessorId: number): boolean;
|
|
24
24
|
setValue(newValue: T | Readonly<T>): void;
|
|
25
25
|
#private;
|
package/dist/model/atom/index.js
CHANGED
|
@@ -21,11 +21,7 @@ function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!priva
|
|
|
21
21
|
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; } }
|
|
22
22
|
var _connections = new WeakMap();
|
|
23
23
|
var _value = new WeakMap();
|
|
24
|
-
/** An atom represents an entry for each individual property path of the state still in use by client components */
|
|
25
|
-
/** @template T */
|
|
26
24
|
var Atom = function () {
|
|
27
|
-
/** @type {Set<number>} */
|
|
28
|
-
/** @type {Readonly<T>} */
|
|
29
25
|
function Atom() {
|
|
30
26
|
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
31
27
|
_classCallCheck(this, Atom);
|
|
@@ -45,27 +41,23 @@ var Atom = function () {
|
|
|
45
41
|
get: function get() {
|
|
46
42
|
return _classPrivateFieldGet(this, _value);
|
|
47
43
|
}
|
|
48
|
-
/**
|
|
49
44
|
* @param {number} accessorId
|
|
50
45
|
* @returns {number} Number of connections remaining
|
|
51
46
|
*/
|
|
52
47
|
}, {
|
|
53
48
|
key: "connect",
|
|
54
49
|
value: function connect(accessorId) {
|
|
55
50
|
_classPrivateFieldGet(this, _connections).add(accessorId);
|
|
56
51
|
return _classPrivateFieldGet(this, _connections).size;
|
|
57
52
|
}
|
|
58
|
-
/**
|
|
59
53
|
* @param {number} accessorId
|
|
60
54
|
* @returns {number} Number of connections remaining
|
|
61
55
|
*/
|
|
62
56
|
}, {
|
|
63
57
|
key: "disconnect",
|
|
64
58
|
value: function disconnect(accessorId) {
|
|
65
59
|
_classPrivateFieldGet(this, _connections)["delete"](accessorId);
|
|
66
60
|
return _classPrivateFieldGet(this, _connections).size;
|
|
67
61
|
}
|
|
68
|
-
/** @param {number} accessorId */
|
|
69
62
|
}, {
|
|
70
63
|
key: "isConnected",
|
|
71
64
|
value: function isConnected(accessorId) {
|
|
72
65
|
return _classPrivateFieldGet(this, _connections).has(accessorId);
|
|
73
66
|
}
|
|
74
|
-
/** @param {T|Readonly<T>} newValue */
|
|
75
67
|
}, {
|
|
76
68
|
key: "setValue",
|
|
77
69
|
value: function setValue(newValue) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default Storage;
|
|
2
1
|
* @extends {IStorage<T>}
|
|
3
2
|
* @template {State} T
|
|
4
3
|
*/
|
|
5
4
|
static supportsSession: boolean;
|
|
6
5
|
get isKeyRequired(): boolean;
|
|
7
6
|
getItem(key: string): T;
|
|
8
7
|
removeItem(key: string): void;
|
|
9
8
|
setItem(key: string, data: T): void;
|
|
10
9
|
#private;
|
|
10
|
+
export default Storage;
|
|
11
11
|
static supportsSession: boolean;
|
|
12
12
|
get isKeyRequired(): boolean;
|
|
13
13
|
clone(data: T): T;
|
|
14
14
|
getItem(key: string): T;
|
|
15
15
|
removeItem(key: string): void;
|
|
16
16
|
setItem(key: string, data: T): void;
|
|
17
17
|
#private;
|
|
@@ -21,9 +21,7 @@ function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _
|
|
|
21
21
|
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
22
22
|
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; } }
|
|
23
23
|
var _data = new WeakMap();
|
|
24
|
-
/**
|
|
25
24
|
* @class
|
|
26
25
|
* @template {State} T
|
|
27
26
|
*/
|
|
28
27
|
var MemoryStorage = function () {
|
|
29
|
-
/** @type {T} */
|
|
30
28
|
function MemoryStorage() {
|
|
31
29
|
_classCallCheck(this, MemoryStorage);
|
|
32
30
|
_classPrivateFieldInitSpec(this, _data, {
|
|
@@ -32,31 +30,31 @@ var MemoryStorage = function () {
|
|
|
32
30
|
});
|
|
33
31
|
_classPrivateFieldSet(this, _data, null);
|
|
34
32
|
}
|
|
35
|
-
/** @type {IStorage<T>[ "getItem" ]} */
|
|
36
33
|
_createClass(MemoryStorage, [{
|
|
34
|
+
key: "clone",
|
|
35
|
+
value: function clone(data) {
|
|
36
|
+
return (0, _lodash["default"])(data);
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
37
39
|
key: "getItem",
|
|
38
40
|
value: function getItem(key) {
|
|
39
|
-
return
|
|
41
|
+
return _classPrivateFieldGet(this, _data);
|
|
40
42
|
}
|
|
41
|
-
/** @type {IStorage<T>[ "removeItem" ]} */
|
|
42
43
|
}, {
|
|
43
44
|
key: "removeItem",
|
|
44
45
|
value: function removeItem(key) {
|
|
45
46
|
_classPrivateFieldSet(this, _data, null);
|
|
46
47
|
}
|
|
47
|
-
/** @type {IStorage<T>[ "setItem" ]} */
|
|
48
48
|
}, {
|
|
49
49
|
key: "setItem",
|
|
50
50
|
value: function setItem(key, data) {
|
|
51
|
-
_classPrivateFieldSet(this, _data,
|
|
51
|
+
_classPrivateFieldSet(this, _data, data);
|
|
52
52
|
}
|
|
53
53
|
}]);
|
|
54
54
|
return MemoryStorage;
|
|
55
55
|
}();
|
|
56
|
-
/**
|
|
57
56
|
* @extends {IStorage<T>}
|
|
58
57
|
* @template {State} T
|
|
59
58
|
*/
|
|
60
59
|
var _storage = new WeakMap();
|
|
61
60
|
var SessionStorage = function () {
|
|
62
|
-
/** @type {IStorage<T>} */
|
|
63
61
|
function SessionStorage() {
|
|
64
62
|
_classCallCheck(this, SessionStorage);
|
|
65
63
|
_classPrivateFieldInitSpec(this, _storage, {
|
|
@@ -65,19 +63,21 @@ var SessionStorage = function () {
|
|
|
65
63
|
});
|
|
66
64
|
_classPrivateFieldSet(this, _storage, globalThis.sessionStorage);
|
|
67
65
|
}
|
|
68
|
-
/** @type {IStorage<T>[ "getItem" ]} */
|
|
69
66
|
_createClass(SessionStorage, [{
|
|
67
|
+
key: "clone",
|
|
68
|
+
value: function clone(data) {
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
}, {
|
|
70
72
|
key: "getItem",
|
|
71
73
|
value: function getItem(key) {
|
|
72
74
|
return JSON.parse(_classPrivateFieldGet(this, _storage).getItem(key));
|
|
73
75
|
}
|
|
74
|
-
/** @type {IStorage<T>[ "removeItem" ]} */
|
|
75
76
|
}, {
|
|
76
77
|
key: "removeItem",
|
|
77
78
|
value: function removeItem(key) {
|
|
78
79
|
return _classPrivateFieldGet(this, _storage).removeItem(key);
|
|
79
80
|
}
|
|
80
|
-
/** @type {IStorage<T>[ "setItem" ]} */
|
|
81
81
|
}, {
|
|
82
82
|
key: "setItem",
|
|
83
83
|
value: function setItem(key, data) {
|
|
@@ -86,10 +86,8 @@ var SessionStorage = function () {
|
|
|
86
86
|
}]);
|
|
87
87
|
return SessionStorage;
|
|
88
88
|
}();
|
|
89
|
-
/**
|
|
90
89
|
* @extends {IStorage<T>}
|
|
91
90
|
* @template {State} T
|
|
92
91
|
*/
|
|
93
92
|
var _storage2 = new WeakMap();
|
|
94
93
|
var Storage = function () {
|
|
95
|
-
/** @type {IStorage<T>} */
|
|
96
94
|
function Storage() {
|
|
97
95
|
_classCallCheck(this, Storage);
|
|
98
96
|
_classPrivateFieldInitSpec(this, _storage2, {
|
|
@@ -103,19 +101,21 @@ var Storage = function () {
|
|
|
103
101
|
get: function get() {
|
|
104
102
|
return _classPrivateFieldGet(this, _storage2) instanceof SessionStorage;
|
|
105
103
|
}
|
|
106
|
-
|
|
104
|
+
}, {
|
|
105
|
+
key: "clone",
|
|
106
|
+
value: function clone(data) {
|
|
107
|
+
return _classPrivateFieldGet(this, _storage2).clone(data);
|
|
108
|
+
}
|
|
107
109
|
}, {
|
|
108
110
|
key: "getItem",
|
|
109
111
|
value: function getItem(key) {
|
|
110
112
|
return _classPrivateFieldGet(this, _storage2).getItem(key);
|
|
111
113
|
}
|
|
112
|
-
/** @type {IStorage<T>[ "removeItem" ]} */
|
|
113
114
|
}, {
|
|
114
115
|
key: "removeItem",
|
|
115
116
|
value: function removeItem(key) {
|
|
116
117
|
_classPrivateFieldGet(this, _storage2).removeItem(key);
|
|
117
118
|
}
|
|
118
|
-
/** @type {IStorage<T>[ "setItem" ]} */
|
|
119
119
|
}, {
|
|
120
120
|
key: "setItem",
|
|
121
121
|
value: function setItem(key, data) {
|
package/dist/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
declare const _default: any;
|
|
2
1
|
[selectorKey: string]: Readonly<any>;
|
|
3
2
|
getItem: (key: string) => T;
|
|
4
3
|
removeItem: (key: string) => void;
|
|
5
4
|
setItem: (key: string, data: T) => void;
|
|
6
5
|
getState: NonReactUsageReport;
|
|
7
6
|
resetState: NonReactUsageReport;
|
|
8
7
|
setState: NonReactUsageReport;
|
|
9
8
|
subscribe: NonReactUsageReport;
|
|
10
9
|
resetState?: (state: {
|
|
11
10
|
current: T;
|
|
12
11
|
original: T;
|
|
13
12
|
}) => boolean;
|
|
14
13
|
setState?: (newChanges: PartialState<T>) => boolean;
|
|
15
14
|
[x: string]: any;
|
|
16
15
|
resetState: VoidFunction;
|
|
17
16
|
setState: (changes: PartialState<T>) => void;
|
|
18
17
|
getState: (clientId: string, ...propertyPaths?: string[]) => {
|
|
19
18
|
[propertyPaths: string]: Readonly<any>;
|
|
20
19
|
};
|
|
21
20
|
subscribe: (listener: Listener<T>) => Unsubscribe;
|
|
22
21
|
unlinkCache: (clientId: string) => void;
|
|
23
22
|
data: Data;
|
|
24
23
|
resetState: VoidFunction;
|
|
25
24
|
setState: (changes: PartialState<T>) => void;
|
|
25
|
+
declare const _default: any;
|
|
26
26
|
[selectorKey: string]: Readonly<any>;
|
|
27
27
|
clone: (data: T) => T;
|
|
28
28
|
getItem: (key: string) => T;
|
|
29
29
|
removeItem: (key: string) => void;
|
|
30
30
|
setItem: (key: string, data: T) => void;
|
|
31
31
|
getState: NonReactUsageReport;
|
|
32
32
|
resetState: NonReactUsageReport;
|
|
33
33
|
setState: NonReactUsageReport;
|
|
34
34
|
subscribe: NonReactUsageReport;
|
|
35
35
|
resetState?: (resetData: PartialState<T>, state: {
|
|
36
36
|
current: T;
|
|
37
37
|
original: T;
|
|
38
38
|
}) => boolean;
|
|
39
39
|
setState?: (newChanges: PartialState<T>) => boolean;
|
|
40
40
|
[x: string]: any;
|
|
41
41
|
resetState: (propertyPaths?: string[]) => void;
|
|
42
42
|
setState: (changes: PartialState<T>) => void;
|
|
43
43
|
getState: (clientId: string, ...propertyPaths?: string[]) => {
|
|
44
44
|
[propertyPaths: string]: Readonly<any>;
|
|
45
45
|
};
|
|
46
46
|
subscribe: (listener: Listener<T>) => Unsubscribe;
|
|
47
47
|
unlinkCache: (clientId: string) => void;
|
|
48
48
|
data: Data;
|
|
49
49
|
resetState: (propertyPaths?: string[]) => void;
|
|
50
50
|
setState: (changes: PartialState<T>) => void;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function arrangePropertyPaths(propertyPaths: Array<string>): Array<string>;
|
|
2
2
|
[x: string]: any;
|