@dr.pogodin/react-global-state 0.20.0 → 0.21.0
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/build/code/GlobalState.js +7 -2
- package/build/code/GlobalState.js.map +1 -1
- package/build/code/GlobalStateProvider.js +2 -2
- package/build/code/GlobalStateProvider.js.map +1 -1
- package/build/code/index.js +6 -6
- package/build/code/index.js.map +1 -1
- package/build/code/useAsyncCollection.js +4 -4
- package/build/code/useAsyncCollection.js.map +1 -1
- package/build/code/useAsyncData.js +3 -3
- package/build/code/useAsyncData.js.map +1 -1
- package/build/code/useGlobalState.js +3 -8
- package/build/code/useGlobalState.js.map +1 -1
- package/build/code/utils.js +1 -1
- package/build/code/utils.js.map +1 -1
- package/build/types/utils.d.ts +1 -1
- package/package.json +15 -16
- package/tstyche.config.json +1 -1
- package/build/cjs/GlobalState.js +0 -289
- package/build/cjs/GlobalState.js.map +0 -1
- package/build/cjs/GlobalStateProvider.js +0 -100
- package/build/cjs/GlobalStateProvider.js.map +0 -1
- package/build/cjs/SsrContext.js +0 -15
- package/build/cjs/SsrContext.js.map +0 -1
- package/build/cjs/index.js +0 -88
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/useAsyncCollection.js +0 -283
- package/build/cjs/useAsyncCollection.js.map +0 -1
- package/build/cjs/useAsyncData.js +0 -273
- package/build/cjs/useAsyncData.js.map +0 -1
- package/build/cjs/useGlobalState.js +0 -148
- package/build/cjs/useGlobalState.js.map +0 -1
- package/build/cjs/utils.js +0 -91
- package/build/cjs/utils.js.map +0 -1
package/build/cjs/index.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
Object.defineProperty(exports, "GlobalState", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return _GlobalState.default;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
Object.defineProperty(exports, "GlobalStateProvider", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () {
|
|
16
|
-
return _GlobalStateProvider.default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports, "SsrContext", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () {
|
|
22
|
-
return _SsrContext.default;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
Object.defineProperty(exports, "getGlobalState", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function () {
|
|
28
|
-
return _GlobalStateProvider.getGlobalState;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(exports, "getSsrContext", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: function () {
|
|
34
|
-
return _GlobalStateProvider.getSsrContext;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
Object.defineProperty(exports, "newAsyncDataEnvelope", {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
get: function () {
|
|
40
|
-
return _useAsyncData.newAsyncDataEnvelope;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
Object.defineProperty(exports, "useAsyncCollection", {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () {
|
|
46
|
-
return _useAsyncCollection.default;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
Object.defineProperty(exports, "useAsyncData", {
|
|
50
|
-
enumerable: true,
|
|
51
|
-
get: function () {
|
|
52
|
-
return _useAsyncData.useAsyncData;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
Object.defineProperty(exports, "useGlobalState", {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
get: function () {
|
|
58
|
-
return _useGlobalState.default;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
exports.withGlobalStateType = withGlobalStateType;
|
|
62
|
-
var _GlobalState = _interopRequireDefault(require("./GlobalState"));
|
|
63
|
-
var _GlobalStateProvider = _interopRequireWildcard(require("./GlobalStateProvider"));
|
|
64
|
-
var _SsrContext = _interopRequireDefault(require("./SsrContext"));
|
|
65
|
-
var _useAsyncCollection = _interopRequireDefault(require("./useAsyncCollection"));
|
|
66
|
-
var _useAsyncData = require("./useAsyncData");
|
|
67
|
-
var _useGlobalState = _interopRequireDefault(require("./useGlobalState"));
|
|
68
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
70
|
-
|
|
71
|
-
const api = {
|
|
72
|
-
// TODO: I am puzzled, why ESLint eforces this sorting order as alphabetical?
|
|
73
|
-
// Perhaps, we should tune something in its config settings, as it seems to mix
|
|
74
|
-
// some extra sorting logic, which I am not sure I like.
|
|
75
|
-
GlobalState: _GlobalState.default,
|
|
76
|
-
GlobalStateProvider: _GlobalStateProvider.default,
|
|
77
|
-
SsrContext: _SsrContext.default,
|
|
78
|
-
getGlobalState: _GlobalStateProvider.getGlobalState,
|
|
79
|
-
getSsrContext: _GlobalStateProvider.getSsrContext,
|
|
80
|
-
newAsyncDataEnvelope: _useAsyncData.newAsyncDataEnvelope,
|
|
81
|
-
useAsyncCollection: _useAsyncCollection.default,
|
|
82
|
-
useAsyncData: _useAsyncData.useAsyncData,
|
|
83
|
-
useGlobalState: _useGlobalState.default
|
|
84
|
-
};
|
|
85
|
-
function withGlobalStateType() {
|
|
86
|
-
return api;
|
|
87
|
-
}
|
|
88
|
-
//# sourceMappingURL=index.js.map
|
package/build/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_GlobalState","_interopRequireDefault","require","_GlobalStateProvider","_interopRequireWildcard","_SsrContext","_useAsyncCollection","_useAsyncData","_useGlobalState","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","api","GlobalState","GlobalStateProvider","SsrContext","getGlobalState","getSsrContext","newAsyncDataEnvelope","useAsyncCollection","useAsyncData","useGlobalState","withGlobalStateType"],"sources":["../../src/index.ts"],"sourcesContent":["import GlobalState from './GlobalState';\n\nimport GlobalStateProvider, {\n getGlobalState,\n getSsrContext,\n} from './GlobalStateProvider';\n\nimport SsrContext from './SsrContext';\n\nimport useAsyncCollection, {\n type UseAsyncCollectionI,\n type UseAsyncCollectionResT,\n} from './useAsyncCollection';\n\nimport {\n type AsyncDataEnvelopeT,\n type AsyncDataLoaderT,\n type AsyncDataReloaderT,\n type UseAsyncDataI,\n type UseAsyncDataOptionsT,\n type UseAsyncDataResT,\n newAsyncDataEnvelope,\n useAsyncData,\n} from './useAsyncData';\n\nimport useGlobalState, { type UseGlobalStateI } from './useGlobalState';\n\nexport type {\n AsyncCollectionLoaderT,\n AsyncCollectionReloaderT,\n AsyncCollectionT,\n} from './useAsyncCollection';\n\nexport type { SetterT, UseGlobalStateResT } from './useGlobalState';\n\nexport type { ForceT, ValueOrInitializerT } from './utils';\n\nexport {\n type AsyncDataEnvelopeT,\n type AsyncDataLoaderT,\n type AsyncDataReloaderT,\n type UseAsyncCollectionResT,\n type UseAsyncDataOptionsT,\n type UseAsyncDataResT,\n getGlobalState,\n getSsrContext,\n GlobalState,\n GlobalStateProvider,\n newAsyncDataEnvelope,\n SsrContext,\n useAsyncCollection,\n useAsyncData,\n useGlobalState,\n};\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\ninterface API<\n StateT,\n SsrContextT extends SsrContext<StateT> = SsrContext<StateT>,\n> {\n getGlobalState: typeof getGlobalState<StateT, SsrContextT>;\n getSsrContext: typeof getSsrContext<SsrContextT>;\n GlobalState: typeof GlobalState<StateT, SsrContextT>;\n GlobalStateProvider: typeof GlobalStateProvider<StateT, SsrContextT>;\n newAsyncDataEnvelope: typeof newAsyncDataEnvelope;\n SsrContext: typeof SsrContext<StateT>;\n useAsyncCollection: UseAsyncCollectionI<StateT>;\n useAsyncData: UseAsyncDataI<StateT>;\n useGlobalState: UseGlobalStateI<StateT>;\n}\n\nconst api = {\n // TODO: I am puzzled, why ESLint eforces this sorting order as alphabetical?\n // Perhaps, we should tune something in its config settings, as it seems to mix\n // some extra sorting logic, which I am not sure I like.\n GlobalState,\n GlobalStateProvider,\n SsrContext,\n getGlobalState,\n getSsrContext,\n newAsyncDataEnvelope,\n useAsyncCollection,\n useAsyncData,\n useGlobalState,\n};\n\nexport function withGlobalStateType<\n StateT,\n SsrContextT extends SsrContext<StateT> = SsrContext<StateT>,\n>(): API<StateT, SsrContextT> {\n return api as API<StateT, SsrContextT>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,oBAAA,GAAAC,uBAAA,CAAAF,OAAA;AAKA,IAAAG,WAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAEA,IAAAI,mBAAA,GAAAL,sBAAA,CAAAC,OAAA;AAKA,IAAAK,aAAA,GAAAL,OAAA;AAWA,IAAAM,eAAA,GAAAP,sBAAA,CAAAC,OAAA;AAAwE,SAAAE,wBAAAK,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YA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,283 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
var _uuid = require("uuid");
|
|
10
|
-
var _GlobalStateProvider = require("./GlobalStateProvider");
|
|
11
|
-
var _useAsyncData = require("./useAsyncData");
|
|
12
|
-
var _useGlobalState = _interopRequireDefault(require("./useGlobalState"));
|
|
13
|
-
var _utils = require("./utils");
|
|
14
|
-
/**
|
|
15
|
-
* Loads and uses item(s) in an async collection.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* GarbageCollector: the piece of logic executed on mounting of
|
|
20
|
-
* an useAsyncCollection() hook, and on update of hook params, to update
|
|
21
|
-
* the state according to the new param values. It increments by 1 `numRefs`
|
|
22
|
-
* counters for the requested collection items.
|
|
23
|
-
*/
|
|
24
|
-
function gcOnWithhold(ids, path, gs) {
|
|
25
|
-
const collection = {
|
|
26
|
-
...gs.get(path)
|
|
27
|
-
};
|
|
28
|
-
for (const id of ids) {
|
|
29
|
-
let envelope = collection[id];
|
|
30
|
-
if (envelope) envelope = {
|
|
31
|
-
...envelope,
|
|
32
|
-
numRefs: 1 + envelope.numRefs
|
|
33
|
-
};else envelope = (0, _useAsyncData.newAsyncDataEnvelope)(null, {
|
|
34
|
-
numRefs: 1
|
|
35
|
-
});
|
|
36
|
-
collection[id] = envelope;
|
|
37
|
-
}
|
|
38
|
-
gs.set(path, collection);
|
|
39
|
-
}
|
|
40
|
-
function idsToStringSet(ids) {
|
|
41
|
-
const res = new Set();
|
|
42
|
-
for (const id of ids) {
|
|
43
|
-
res.add(id.toString());
|
|
44
|
-
}
|
|
45
|
-
return res;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* GarbageCollector: the piece of logic executed on un-mounting of
|
|
50
|
-
* an useAsyncCollection() hook, and on update of hook params, to clean-up
|
|
51
|
-
* after the previous param values. It decrements by 1 `numRefs` counters
|
|
52
|
-
* for previously requested collection items, and also drops from the state
|
|
53
|
-
* stale records.
|
|
54
|
-
*/
|
|
55
|
-
function gcOnRelease(ids, path, gs, gcAge) {
|
|
56
|
-
const entries = Object.entries(gs.get(path));
|
|
57
|
-
const now = Date.now();
|
|
58
|
-
const idSet = idsToStringSet(ids);
|
|
59
|
-
const collection = {};
|
|
60
|
-
for (const [id, envelope] of entries) {
|
|
61
|
-
if (envelope) {
|
|
62
|
-
const toBeReleased = idSet.has(id);
|
|
63
|
-
let {
|
|
64
|
-
numRefs
|
|
65
|
-
} = envelope;
|
|
66
|
-
if (toBeReleased) --numRefs;
|
|
67
|
-
if (gcAge > now - envelope.timestamp || numRefs > 0) {
|
|
68
|
-
collection[id] = toBeReleased ? {
|
|
69
|
-
...envelope,
|
|
70
|
-
numRefs
|
|
71
|
-
} : envelope;
|
|
72
|
-
} else if (process.env.NODE_ENV !== 'production' && (0, _utils.isDebugMode)()) {
|
|
73
|
-
// eslint-disable-next-line no-console
|
|
74
|
-
console.log(`useAsyncCollection(): Garbage collected at the path "${path}", ID = ${id}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
gs.set(path, collection);
|
|
79
|
-
}
|
|
80
|
-
function normalizeIds(idOrIds) {
|
|
81
|
-
if (Array.isArray(idOrIds)) {
|
|
82
|
-
// Removes ID duplicates.
|
|
83
|
-
const res = Array.from(new Set(idOrIds));
|
|
84
|
-
|
|
85
|
-
// Ensures stable ID order.
|
|
86
|
-
res.sort((a, b) => a.toString().localeCompare(b.toString()));
|
|
87
|
-
return res;
|
|
88
|
-
}
|
|
89
|
-
return [idOrIds];
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Resolves and stores at the given `path` of the global state elements of
|
|
94
|
-
* an asynchronous data collection.
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
// TODO: This is largely similar to useAsyncData() logic, just more generic.
|
|
98
|
-
// Perhaps, a bunch of logic blocks can be split into stand-alone functions,
|
|
99
|
-
// and reused in both hooks.
|
|
100
|
-
// eslint-disable-next-line complexity
|
|
101
|
-
function useAsyncCollection(idOrIds, path, loader, options = {}) {
|
|
102
|
-
const ids = normalizeIds(idOrIds);
|
|
103
|
-
const maxage = options.maxage ?? _useAsyncData.DEFAULT_MAXAGE;
|
|
104
|
-
const refreshAge = options.refreshAge ?? maxage;
|
|
105
|
-
const garbageCollectAge = options.garbageCollectAge ?? maxage;
|
|
106
|
-
const globalState = (0, _GlobalStateProvider.getGlobalState)();
|
|
107
|
-
|
|
108
|
-
// Server-side logic.
|
|
109
|
-
if (globalState.ssrContext) {
|
|
110
|
-
if (!options.disabled && !options.noSSR) {
|
|
111
|
-
const operationId = `S${(0, _uuid.v4)()}`;
|
|
112
|
-
for (const id of ids) {
|
|
113
|
-
const itemPath = path ? `${path}.${id}` : `${id}`;
|
|
114
|
-
const state = globalState.get(itemPath, {
|
|
115
|
-
initialValue: (0, _useAsyncData.newAsyncDataEnvelope)()
|
|
116
|
-
});
|
|
117
|
-
if (!state.timestamp && !state.operationId) {
|
|
118
|
-
const promiseOrVoid = (0, _useAsyncData.load)(itemPath, (...args) => loader(id, ...args), globalState, {
|
|
119
|
-
data: state.data,
|
|
120
|
-
timestamp: state.timestamp
|
|
121
|
-
}, operationId);
|
|
122
|
-
if (promiseOrVoid instanceof Promise) {
|
|
123
|
-
globalState.ssrContext.pending.push(promiseOrVoid);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Client-side logic.
|
|
130
|
-
} else {
|
|
131
|
-
const {
|
|
132
|
-
disabled
|
|
133
|
-
} = options;
|
|
134
|
-
|
|
135
|
-
// Reference-counting & garbage collection.
|
|
136
|
-
|
|
137
|
-
const idsHash = (0, _utils.hash)(ids);
|
|
138
|
-
|
|
139
|
-
// TODO: Violation of rules of hooks is fine here,
|
|
140
|
-
// but perhaps it can be refactored to avoid the need for it.
|
|
141
|
-
(0, _react.useEffect)(() => {
|
|
142
|
-
// eslint-disable-line react-hooks/rules-of-hooks
|
|
143
|
-
if (!disabled) gcOnWithhold(ids, path, globalState);
|
|
144
|
-
return () => {
|
|
145
|
-
if (!disabled) gcOnRelease(ids, path, globalState, garbageCollectAge);
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// `ids` are represented in the dependencies array by `idsHash` value,
|
|
149
|
-
// as useEffect() hook requires a constant size of dependencies array.
|
|
150
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
151
|
-
}, [disabled, garbageCollectAge, globalState, idsHash, path]);
|
|
152
|
-
|
|
153
|
-
// NOTE: a bunch of Rules of Hooks ignored belows because in our very
|
|
154
|
-
// special case the otherwise wrong behavior is actually what we need.
|
|
155
|
-
|
|
156
|
-
// Data loading and refreshing.
|
|
157
|
-
(0, _react.useEffect)(() => {
|
|
158
|
-
// eslint-disable-line react-hooks/rules-of-hooks
|
|
159
|
-
if (!disabled) {
|
|
160
|
-
void (async () => {
|
|
161
|
-
for (const id of ids) {
|
|
162
|
-
const itemPath = path ? `${path}.${id}` : `${id}`;
|
|
163
|
-
const state2 = globalState.get(itemPath);
|
|
164
|
-
const {
|
|
165
|
-
deps
|
|
166
|
-
} = options;
|
|
167
|
-
if (deps && globalState.hasChangedDependencies(itemPath, deps) || refreshAge < Date.now() - (state2?.timestamp ?? 0) && (!state2?.operationId || state2.operationId.startsWith('S'))) {
|
|
168
|
-
if (!deps) globalState.dropDependencies(itemPath);
|
|
169
|
-
await (0, _useAsyncData.load)(itemPath,
|
|
170
|
-
// TODO: I guess, the loader is not correctly typed here -
|
|
171
|
-
// it can be synchronous, and in that case the following method
|
|
172
|
-
// should be kept synchronous to not alter the sync logic.
|
|
173
|
-
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
174
|
-
(old, ...args) => loader(id, old, ...args), globalState, {
|
|
175
|
-
data: state2?.data,
|
|
176
|
-
timestamp: state2?.timestamp ?? 0
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
})();
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
const [localState] = (0, _useGlobalState.default)(path, {});
|
|
185
|
-
const ref = (0, _react.useRef)(null);
|
|
186
|
-
ref.current ??= {
|
|
187
|
-
globalState,
|
|
188
|
-
ids,
|
|
189
|
-
loader,
|
|
190
|
-
path
|
|
191
|
-
};
|
|
192
|
-
(0, _react.useEffect)(() => {
|
|
193
|
-
ref.current = {
|
|
194
|
-
globalState,
|
|
195
|
-
ids,
|
|
196
|
-
loader,
|
|
197
|
-
path
|
|
198
|
-
};
|
|
199
|
-
}, [globalState, ids, loader, path]);
|
|
200
|
-
const [stable] = (0, _react.useState)(() => {
|
|
201
|
-
const reload = async customLoader => {
|
|
202
|
-
const rc = ref.current;
|
|
203
|
-
if (!rc) throw Error('Internal error');
|
|
204
|
-
const localLoader = customLoader ?? rc.loader;
|
|
205
|
-
|
|
206
|
-
// TODO: Revise - not sure all related typing is 100% correct,
|
|
207
|
-
// thus let's keep this runtime assertion.
|
|
208
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
209
|
-
if (!localLoader || !rc.globalState || !rc.ids) {
|
|
210
|
-
throw Error('Internal error');
|
|
211
|
-
}
|
|
212
|
-
for (const id of rc.ids) {
|
|
213
|
-
const itemPath = rc.path ? `${rc.path}.${id}` : `${id}`;
|
|
214
|
-
const promiseOrVoid = (0, _useAsyncData.load)(itemPath,
|
|
215
|
-
// TODO: Revise! Most probably we don't have fully correct loader
|
|
216
|
-
// typing, as it may return either promise or value, and those two
|
|
217
|
-
// cases call for different runtime behavior, which in turns only
|
|
218
|
-
// happens if the outer function on the next line matches the same
|
|
219
|
-
// async / sync signature.
|
|
220
|
-
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
221
|
-
(oldData, meta) => localLoader(id, oldData, meta), rc.globalState);
|
|
222
|
-
if (promiseOrVoid instanceof Promise) await promiseOrVoid;
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
// TODO: Revise! Most probably we don't have fully correct loader
|
|
227
|
-
// typing, as it may return either promise or value, and those two
|
|
228
|
-
// cases call for different runtime behavior, which in turns only
|
|
229
|
-
// happens if the outer function on the next line matches the same
|
|
230
|
-
// async / sync signature.
|
|
231
|
-
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
232
|
-
const reloadSingle = customLoader => reload(
|
|
233
|
-
// TODO: Revise! Most probably we don't have fully correct loader
|
|
234
|
-
// typing, as it may return either promise or value, and those two
|
|
235
|
-
// cases call for different runtime behavior, which in turns only
|
|
236
|
-
// happens if the outer function on the next line matches the same
|
|
237
|
-
// async / sync signature.
|
|
238
|
-
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
239
|
-
customLoader && ((id, ...args) => customLoader(...args)));
|
|
240
|
-
const setSingle = data => {
|
|
241
|
-
void reload(() => data);
|
|
242
|
-
};
|
|
243
|
-
return {
|
|
244
|
-
reload,
|
|
245
|
-
reloadSingle,
|
|
246
|
-
setSingle
|
|
247
|
-
};
|
|
248
|
-
});
|
|
249
|
-
if (!Array.isArray(idOrIds)) {
|
|
250
|
-
// TODO: Revise related typings!
|
|
251
|
-
const e = localState[idOrIds];
|
|
252
|
-
const timestamp = e?.timestamp ?? 0;
|
|
253
|
-
return {
|
|
254
|
-
data: maxage < Date.now() - timestamp ? null : e?.data ?? null,
|
|
255
|
-
loading: !!e?.operationId,
|
|
256
|
-
reload: stable.reloadSingle,
|
|
257
|
-
set: stable.setSingle,
|
|
258
|
-
timestamp
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
const res = {
|
|
262
|
-
items: {},
|
|
263
|
-
loading: false,
|
|
264
|
-
reload: stable.reload,
|
|
265
|
-
timestamp: Number.MAX_VALUE
|
|
266
|
-
};
|
|
267
|
-
for (const id of ids) {
|
|
268
|
-
// TODO: Revise related typing. Should `localState` have a more specific type?
|
|
269
|
-
const e = localState[id];
|
|
270
|
-
const loading = !!e?.operationId;
|
|
271
|
-
const timestamp = e?.timestamp ?? 0;
|
|
272
|
-
res.items[id] = {
|
|
273
|
-
data: maxage < Date.now() - timestamp ? null : e?.data ?? null,
|
|
274
|
-
loading,
|
|
275
|
-
timestamp
|
|
276
|
-
};
|
|
277
|
-
res.loading ||= loading;
|
|
278
|
-
if (res.timestamp > timestamp) res.timestamp = timestamp;
|
|
279
|
-
}
|
|
280
|
-
return res;
|
|
281
|
-
}
|
|
282
|
-
var _default = exports.default = useAsyncCollection; // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
283
|
-
//# sourceMappingURL=useAsyncCollection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAsyncCollection.js","names":["_react","require","_uuid","_GlobalStateProvider","_useAsyncData","_useGlobalState","_interopRequireDefault","_utils","gcOnWithhold","ids","path","gs","collection","get","id","envelope","numRefs","newAsyncDataEnvelope","set","idsToStringSet","res","Set","add","toString","gcOnRelease","gcAge","entries","Object","now","Date","idSet","toBeReleased","has","timestamp","process","env","NODE_ENV","isDebugMode","console","log","normalizeIds","idOrIds","Array","isArray","from","sort","a","b","localeCompare","useAsyncCollection","loader","options","maxage","DEFAULT_MAXAGE","refreshAge","garbageCollectAge","globalState","getGlobalState","ssrContext","disabled","noSSR","operationId","uuid","itemPath","state","initialValue","promiseOrVoid","load","args","data","Promise","pending","push","idsHash","hash","useEffect","state2","deps","hasChangedDependencies","startsWith","dropDependencies","old","localState","useGlobalState","ref","useRef","current","stable","useState","reload","customLoader","rc","Error","localLoader","oldData","meta","reloadSingle","setSingle","e","loading","items","Number","MAX_VALUE","_default","exports","default"],"sources":["../../src/useAsyncCollection.ts"],"sourcesContent":["/**\n * Loads and uses item(s) in an async collection.\n */\n\nimport { useEffect, useRef, useState } from 'react';\nimport { v4 as uuid } from 'uuid';\n\nimport type GlobalState from './GlobalState';\nimport { getGlobalState } from './GlobalStateProvider';\n\nimport {\n type AsyncDataEnvelopeT,\n type AsyncDataReloaderT,\n type DataInEnvelopeAtPathT,\n type OperationIdT,\n type UseAsyncDataOptionsT,\n type UseAsyncDataResT,\n DEFAULT_MAXAGE,\n load,\n newAsyncDataEnvelope,\n} from './useAsyncData';\n\nimport useGlobalState from './useGlobalState';\n\nimport {\n type ForceT,\n type LockT,\n type TypeLock,\n hash,\n isDebugMode,\n} from './utils';\n\nexport type AsyncCollectionT<\n DataT = unknown,\n IdT extends number | string = number | string,\n> = Record<IdT, AsyncDataEnvelopeT<DataT>>;\n\nexport type AsyncCollectionLoaderT<\n DataT,\n IdT extends number | string = number | string,\n> = (id: IdT, oldData: null | DataT, meta: {\n isAborted: () => boolean;\n oldDataTimestamp: number;\n setAbortCallback: (cb: () => void) => void;\n}) => DataT | null | Promise<DataT | null>;\n\nexport type AsyncCollectionReloaderT<\n DataT,\n IdT extends number | string = number | string,\n> = (loader?: AsyncCollectionLoaderT<DataT, IdT>) => void | Promise<void>;\n\ntype CollectionItemT<DataT> = {\n data: DataT | null;\n loading: boolean;\n timestamp: number;\n};\n\nexport type UseAsyncCollectionResT<\n DataT,\n IdT extends number | string = number | string,\n> = {\n items: Record<IdT, CollectionItemT<DataT>>;\n loading: boolean;\n reload: AsyncCollectionReloaderT<DataT, IdT>;\n timestamp: number;\n};\n\ntype CurrentT<DataT, IdT extends number | string> = {\n globalState: GlobalState<unknown>;\n ids: IdT[];\n loader: AsyncCollectionLoaderT<DataT, IdT>;\n path: null | string | undefined;\n};\n\ntype StableT<DataT, IdT extends number | string> = {\n reload: AsyncCollectionReloaderT<DataT, IdT>;\n reloadSingle: AsyncDataReloaderT<DataT>;\n setSingle: (data: DataT | null) => void;\n};\n\n/**\n * GarbageCollector: the piece of logic executed on mounting of\n * an useAsyncCollection() hook, and on update of hook params, to update\n * the state according to the new param values. It increments by 1 `numRefs`\n * counters for the requested collection items.\n */\nfunction gcOnWithhold<IdT extends number | string>(\n ids: IdT[],\n path: null | string | undefined,\n gs: GlobalState<unknown>,\n) {\n const collection = { ...gs.get<ForceT, AsyncCollectionT>(path) };\n\n for (const id of ids) {\n let envelope = collection[id];\n if (envelope) envelope = { ...envelope, numRefs: 1 + envelope.numRefs };\n else envelope = newAsyncDataEnvelope<unknown>(null, { numRefs: 1 });\n collection[id] = envelope;\n }\n\n gs.set<ForceT, AsyncCollectionT>(path, collection);\n}\n\nfunction idsToStringSet<IdT extends number | string>(ids: IdT[]): Set<string> {\n const res = new Set<string>();\n for (const id of ids) {\n res.add(id.toString());\n }\n return res;\n}\n\n/**\n * GarbageCollector: the piece of logic executed on un-mounting of\n * an useAsyncCollection() hook, and on update of hook params, to clean-up\n * after the previous param values. It decrements by 1 `numRefs` counters\n * for previously requested collection items, and also drops from the state\n * stale records.\n */\nfunction gcOnRelease<IdT extends number | string>(\n ids: IdT[],\n path: null | string | undefined,\n gs: GlobalState<unknown>,\n gcAge: number,\n) {\n type EnvelopeT = AsyncDataEnvelopeT<unknown>;\n\n const entries = Object.entries<EnvelopeT | undefined>(\n gs.get<ForceT, AsyncCollectionT>(path),\n );\n\n const now = Date.now();\n const idSet = idsToStringSet(ids);\n const collection: AsyncCollectionT = {};\n for (const [id, envelope] of entries) {\n if (envelope) {\n const toBeReleased = idSet.has(id);\n\n let { numRefs } = envelope;\n if (toBeReleased) --numRefs;\n\n if (gcAge > now - envelope.timestamp || numRefs > 0) {\n collection[id as IdT] = toBeReleased\n ? { ...envelope, numRefs }\n : envelope;\n } else if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n // eslint-disable-next-line no-console\n console.log(\n `useAsyncCollection(): Garbage collected at the path \"${\n path}\", ID = ${id}`,\n );\n }\n }\n }\n\n gs.set<ForceT, AsyncCollectionT>(path, collection);\n}\n\nfunction normalizeIds<IdT extends number | string>(\n idOrIds: IdT | IdT[],\n): IdT[] {\n if (Array.isArray(idOrIds)) {\n // Removes ID duplicates.\n const res = Array.from(new Set(idOrIds));\n\n // Ensures stable ID order.\n res.sort((a, b) => a.toString().localeCompare(b.toString()));\n\n return res;\n }\n return [idOrIds];\n}\n\n/**\n * Resolves and stores at the given `path` of the global state elements of\n * an asynchronous data collection.\n */\n\nfunction useAsyncCollection<\n StateT,\n PathT extends null | string | undefined,\n IdT extends number | string,\n\n DataT extends DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`> = DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>,\n>(\n id: IdT,\n path: PathT,\n loader: AsyncCollectionLoaderT<DataT, IdT>,\n options?: UseAsyncDataOptionsT,\n): UseAsyncDataResT<DataT>;\n\nfunction useAsyncCollection<\n Forced extends ForceT | LockT = LockT,\n DataT = unknown,\n IdT extends number | string = number | string,\n>(\n id: IdT,\n path: null | string | undefined,\n loader: AsyncCollectionLoaderT<TypeLock<Forced, void, DataT>, IdT>,\n options?: UseAsyncDataOptionsT,\n): UseAsyncDataResT<TypeLock<Forced, void, DataT>>;\n\nfunction useAsyncCollection<\n StateT,\n PathT extends null | string | undefined,\n IdT extends number | string,\n\n DataT extends DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`> = DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>,\n>(\n id: IdT[],\n path: PathT,\n loader: AsyncCollectionLoaderT<DataT, IdT>,\n options?: UseAsyncDataOptionsT,\n): UseAsyncCollectionResT<DataT, IdT>;\n\nfunction useAsyncCollection<\n Forced extends ForceT | LockT = LockT,\n DataT = unknown,\n IdT extends number | string = number | string,\n>(\n id: IdT[],\n path: null | string | undefined,\n loader: AsyncCollectionLoaderT<TypeLock<Forced, void, DataT>, IdT>,\n options?: UseAsyncDataOptionsT,\n): UseAsyncCollectionResT<DataT, IdT>;\n\nfunction useAsyncCollection<\n StateT,\n PathT extends null | string | undefined,\n IdT extends number | string,\n\n DataT extends DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`> = DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>,\n>(\n id: IdT | IdT[],\n path: PathT,\n loader: AsyncCollectionLoaderT<DataT, IdT>,\n options?: UseAsyncDataOptionsT,\n): UseAsyncDataResT<DataT> | UseAsyncCollectionResT<DataT, IdT>;\n\n// TODO: This is largely similar to useAsyncData() logic, just more generic.\n// Perhaps, a bunch of logic blocks can be split into stand-alone functions,\n// and reused in both hooks.\n// eslint-disable-next-line complexity\nfunction useAsyncCollection<\n DataT,\n IdT extends number | string,\n>(\n idOrIds: IdT | IdT[],\n path: null | string | undefined,\n loader: AsyncCollectionLoaderT<DataT, IdT>,\n options: UseAsyncDataOptionsT = {},\n): UseAsyncDataResT<DataT> | UseAsyncCollectionResT<DataT, IdT> {\n const ids = normalizeIds(idOrIds);\n const maxage: number = options.maxage ?? DEFAULT_MAXAGE;\n const refreshAge: number = options.refreshAge ?? maxage;\n const garbageCollectAge: number = options.garbageCollectAge ?? maxage;\n\n const globalState = getGlobalState();\n\n // Server-side logic.\n if (globalState.ssrContext) {\n if (!options.disabled && !options.noSSR) {\n const operationId: OperationIdT = `S${uuid()}`;\n for (const id of ids) {\n const itemPath = path ? `${path}.${id}` : `${id}`;\n const state = globalState.get<ForceT, AsyncDataEnvelopeT<DataT>>(\n itemPath,\n {\n initialValue: newAsyncDataEnvelope<DataT>(),\n },\n );\n if (!state.timestamp && !state.operationId) {\n const promiseOrVoid = load(\n itemPath,\n (...args):\n DataT | null | Promise<DataT | null> => loader(id, ...args),\n globalState,\n {\n data: state.data,\n timestamp: state.timestamp,\n },\n operationId,\n );\n\n if (promiseOrVoid instanceof Promise) {\n globalState.ssrContext.pending.push(promiseOrVoid);\n }\n }\n }\n }\n\n // Client-side logic.\n } else {\n const { disabled } = options;\n\n // Reference-counting & garbage collection.\n\n const idsHash = hash(ids);\n\n // TODO: Violation of rules of hooks is fine here,\n // but perhaps it can be refactored to avoid the need for it.\n useEffect(() => { // eslint-disable-line react-hooks/rules-of-hooks\n if (!disabled) gcOnWithhold(ids, path, globalState);\n return () => {\n if (!disabled) gcOnRelease(ids, path, globalState, garbageCollectAge);\n };\n\n // `ids` are represented in the dependencies array by `idsHash` value,\n // as useEffect() hook requires a constant size of dependencies array.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n disabled,\n garbageCollectAge,\n globalState,\n idsHash,\n path,\n ]);\n\n // NOTE: a bunch of Rules of Hooks ignored belows because in our very\n // special case the otherwise wrong behavior is actually what we need.\n\n // Data loading and refreshing.\n useEffect(() => { // eslint-disable-line react-hooks/rules-of-hooks\n if (!disabled) {\n void (async () => {\n for (const id of ids) {\n const itemPath = path ? `${path}.${id}` : `${id}`;\n\n type EnvT = AsyncDataEnvelopeT<DataT> | undefined;\n const state2: EnvT = globalState.get<ForceT, EnvT>(itemPath);\n\n const { deps } = options;\n if (\n (deps && globalState.hasChangedDependencies(itemPath, deps))\n || (\n refreshAge < Date.now() - (state2?.timestamp ?? 0)\n && (!state2?.operationId || state2.operationId.startsWith('S'))\n )\n ) {\n if (!deps) globalState.dropDependencies(itemPath);\n await load(\n itemPath,\n // TODO: I guess, the loader is not correctly typed here -\n // it can be synchronous, and in that case the following method\n // should be kept synchronous to not alter the sync logic.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n (old, ...args) => loader(id, old as DataT, ...args),\n globalState,\n {\n data: state2?.data,\n timestamp: state2?.timestamp ?? 0,\n },\n );\n }\n }\n })();\n }\n });\n }\n\n const [localState] = useGlobalState<\n ForceT, Record<string, AsyncDataEnvelopeT<DataT>>\n >(path, {});\n\n const ref = useRef<CurrentT<DataT, IdT>>(null);\n\n ref.current ??= {\n globalState,\n ids,\n loader,\n path,\n };\n\n useEffect(() => {\n ref.current = {\n globalState,\n ids,\n loader,\n path,\n };\n }, [globalState, ids, loader, path]);\n\n const [stable] = useState<StableT<DataT, IdT>>(() => {\n const reload = async (\n customLoader?: AsyncCollectionLoaderT<DataT, IdT>,\n ) => {\n const rc = ref.current;\n if (!rc) throw Error('Internal error');\n\n const localLoader = customLoader ?? rc.loader;\n\n // TODO: Revise - not sure all related typing is 100% correct,\n // thus let's keep this runtime assertion.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!localLoader || !rc.globalState || !rc.ids) {\n throw Error('Internal error');\n }\n\n for (const id of rc.ids) {\n const itemPath = rc.path ? `${rc.path}.${id}` : `${id}`;\n\n const promiseOrVoid = load(\n itemPath,\n // TODO: Revise! Most probably we don't have fully correct loader\n // typing, as it may return either promise or value, and those two\n // cases call for different runtime behavior, which in turns only\n // happens if the outer function on the next line matches the same\n // async / sync signature.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n (oldData: DataT | null, meta) => localLoader(id, oldData, meta),\n rc.globalState,\n );\n\n if (promiseOrVoid instanceof Promise) await promiseOrVoid;\n }\n };\n\n // TODO: Revise! Most probably we don't have fully correct loader\n // typing, as it may return either promise or value, and those two\n // cases call for different runtime behavior, which in turns only\n // happens if the outer function on the next line matches the same\n // async / sync signature.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const reloadSingle: AsyncDataReloaderT<DataT> = (customLoader) => reload(\n // TODO: Revise! Most probably we don't have fully correct loader\n // typing, as it may return either promise or value, and those two\n // cases call for different runtime behavior, which in turns only\n // happens if the outer function on the next line matches the same\n // async / sync signature.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n customLoader && ((id, ...args) => customLoader(...args)),\n );\n\n const setSingle = (data: DataT | null) => {\n void reload(() => data);\n };\n\n return { reload, reloadSingle, setSingle };\n });\n\n if (!Array.isArray(idOrIds)) {\n // TODO: Revise related typings!\n const e = localState[idOrIds as string];\n const timestamp = e?.timestamp ?? 0;\n return {\n data: maxage < Date.now() - timestamp ? null : e?.data ?? null,\n loading: !!e?.operationId,\n reload: stable.reloadSingle,\n set: stable.setSingle,\n timestamp,\n };\n }\n\n const res: UseAsyncCollectionResT<DataT, IdT> = {\n items: {} as Record<IdT, CollectionItemT<DataT>>,\n loading: false,\n reload: stable.reload,\n timestamp: Number.MAX_VALUE,\n };\n\n for (const id of ids) {\n // TODO: Revise related typing. Should `localState` have a more specific type?\n const e = localState[id as string];\n const loading = !!e?.operationId;\n const timestamp = e?.timestamp ?? 0;\n\n res.items[id] = {\n data: maxage < Date.now() - timestamp ? null : e?.data ?? null,\n loading,\n timestamp,\n };\n res.loading ||= loading;\n if (res.timestamp > timestamp) res.timestamp = timestamp;\n }\n\n return res;\n}\n\nexport default useAsyncCollection;\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface UseAsyncCollectionI<StateT> {\n <PathT extends null | string | undefined, IdT extends number | string>(\n id: IdT,\n path: PathT,\n loader: AsyncCollectionLoaderT<DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>, IdT>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>>;\n\n <\n Forced extends ForceT | LockT = LockT,\n DataT = unknown,\n IdT extends number | string = number | string,\n >(\n id: IdT,\n path: null | string | undefined,\n loader: AsyncCollectionLoaderT<TypeLock<Forced, void, DataT>, IdT>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<TypeLock<Forced, void, DataT>>;\n\n <PathT extends null | string | undefined, IdT extends number | string>(\n id: IdT[],\n path: PathT,\n loader: AsyncCollectionLoaderT<DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>, IdT>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncCollectionResT<DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>, IdT>;\n\n <\n Forced extends ForceT | LockT = LockT,\n DataT = unknown,\n IdT extends number | string = number | string,\n >(\n id: IdT[],\n path: null | string | undefined,\n loader: AsyncCollectionLoaderT<TypeLock<Forced, void, DataT>, IdT>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncCollectionResT<DataT, IdT>;\n\n <PathT extends null | string | undefined, IdT extends number | string>(\n id: IdT | IdT[],\n path: PathT,\n loader: AsyncCollectionLoaderT<DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>, IdT>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>>\n | UseAsyncCollectionResT<DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>, IdT>;\n}\n"],"mappings":";;;;;;;AAIA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAGA,IAAAE,oBAAA,GAAAF,OAAA;AAEA,IAAAG,aAAA,GAAAH,OAAA;AAYA,IAAAI,eAAA,GAAAC,sBAAA,CAAAL,OAAA;AAEA,IAAAM,MAAA,GAAAN,OAAA;AAxBA;AACA;AACA;;AA8EA;AACA;AACA;AACA;AACA;AACA;AACA,SAASO,YAAYA,CACnBC,GAAU,EACVC,IAA+B,EAC/BC,EAAwB,EACxB;EACA,MAAMC,UAAU,GAAG;IAAE,GAAGD,EAAE,CAACE,GAAG,CAA2BH,IAAI;EAAE,CAAC;EAEhE,KAAK,MAAMI,EAAE,IAAIL,GAAG,EAAE;IACpB,IAAIM,QAAQ,GAAGH,UAAU,CAACE,EAAE,CAAC;IAC7B,IAAIC,QAAQ,EAAEA,QAAQ,GAAG;MAAE,GAAGA,QAAQ;MAAEC,OAAO,EAAE,CAAC,GAAGD,QAAQ,CAACC;IAAQ,CAAC,CAAC,KACnED,QAAQ,GAAG,IAAAE,kCAAoB,EAAU,IAAI,EAAE;MAAED,OAAO,EAAE;IAAE,CAAC,CAAC;IACnEJ,UAAU,CAACE,EAAE,CAAC,GAAGC,QAAQ;EAC3B;EAEAJ,EAAE,CAACO,GAAG,CAA2BR,IAAI,EAAEE,UAAU,CAAC;AACpD;AAEA,SAASO,cAAcA,CAA8BV,GAAU,EAAe;EAC5E,MAAMW,GAAG,GAAG,IAAIC,GAAG,CAAS,CAAC;EAC7B,KAAK,MAAMP,EAAE,IAAIL,GAAG,EAAE;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