@dr.pogodin/react-global-state 0.18.1 → 0.19.1
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/LICENSE.md +1 -1
- package/build/{module → code}/GlobalState.js +15 -5
- package/build/code/GlobalState.js.map +1 -0
- package/build/{module → code}/GlobalStateProvider.js +8 -0
- package/build/code/GlobalStateProvider.js.map +1 -0
- package/build/code/SsrContext.js.map +1 -0
- package/build/{module → code}/index.js +9 -3
- package/build/code/index.js.map +1 -0
- package/build/{module → code}/useAsyncCollection.js +58 -28
- package/build/code/useAsyncCollection.js.map +1 -0
- package/build/{module → code}/useAsyncData.js +73 -46
- package/build/code/useAsyncData.js.map +1 -0
- package/build/{module → code}/useGlobalState.js +25 -8
- package/build/code/useGlobalState.js.map +1 -0
- package/build/{module → code}/utils.js +1 -1
- package/build/code/utils.js.map +1 -0
- package/build/types/GlobalState.d.ts +2 -2
- package/build/types/GlobalStateProvider.d.ts +3 -3
- package/build/types/SsrContext.d.ts +3 -3
- package/build/types/useAsyncCollection.d.ts +4 -8
- package/build/types/useAsyncData.d.ts +5 -5
- package/build/types/utils.d.ts +2 -3
- package/eslint.config.mjs +19 -0
- package/package.json +25 -41
- package/build/common/GlobalState.js +0 -279
- package/build/common/GlobalState.js.map +0 -1
- package/build/common/GlobalStateProvider.js +0 -89
- package/build/common/GlobalStateProvider.js.map +0 -1
- package/build/common/SsrContext.js +0 -15
- package/build/common/SsrContext.js.map +0 -1
- package/build/common/index.js +0 -84
- package/build/common/index.js.map +0 -1
- package/build/common/useAsyncCollection.js +0 -242
- package/build/common/useAsyncCollection.js.map +0 -1
- package/build/common/useAsyncData.js +0 -233
- package/build/common/useAsyncData.js.map +0 -1
- package/build/common/useGlobalState.js +0 -134
- package/build/common/useGlobalState.js.map +0 -1
- package/build/common/utils.js +0 -91
- package/build/common/utils.js.map +0 -1
- package/build/module/GlobalState.js.map +0 -1
- package/build/module/GlobalStateProvider.js.map +0 -1
- package/build/module/SsrContext.js.map +0 -1
- package/build/module/index.js.map +0 -1
- package/build/module/useAsyncCollection.js.map +0 -1
- package/build/module/useAsyncData.js.map +0 -1
- package/build/module/useGlobalState.js.map +0 -1
- package/build/module/utils.js.map +0 -1
- package/src/GlobalState.ts +0 -342
- package/src/GlobalStateProvider.tsx +0 -108
- package/src/SsrContext.ts +0 -11
- package/src/index.ts +0 -84
- package/src/useAsyncCollection.ts +0 -493
- package/src/useAsyncData.ts +0 -362
- package/src/useGlobalState.ts +0 -225
- package/src/utils.ts +0 -116
- /package/build/{module → code}/SsrContext.js +0 -0
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# MIT License
|
|
2
2
|
|
|
3
|
-
_Copyright © 2019–
|
|
3
|
+
_Copyright © 2019–2025, Dr. Sergey Pogodin_
|
|
4
4
|
— <doc@pogodin.studio> (https://dr.pogodin.studio)
|
|
5
5
|
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
@@ -132,9 +132,7 @@ export default class GlobalState {
|
|
|
132
132
|
_classPrivateFieldSet(_nextNotifierId, this, setTimeout(() => {
|
|
133
133
|
_classPrivateFieldSet(_nextNotifierId, this, undefined);
|
|
134
134
|
const watchers = [..._classPrivateFieldGet(_watchers, this)];
|
|
135
|
-
for (
|
|
136
|
-
watchers[i]();
|
|
137
|
-
}
|
|
135
|
+
for (const watcher of watchers) watcher();
|
|
138
136
|
}));
|
|
139
137
|
}
|
|
140
138
|
}
|
|
@@ -193,7 +191,10 @@ export default class GlobalState {
|
|
|
193
191
|
if (res !== undefined || (opts === null || opts === void 0 ? void 0 : opts.initialValue) === undefined) return res;
|
|
194
192
|
const iv = opts.initialValue;
|
|
195
193
|
res = isFunction(iv) ? iv() : iv;
|
|
196
|
-
|
|
194
|
+
|
|
195
|
+
// TODO: Revise.
|
|
196
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
197
|
+
if (!opts.initialState || this.get(path) === undefined) {
|
|
197
198
|
this.set(path, res);
|
|
198
199
|
}
|
|
199
200
|
return res;
|
|
@@ -214,15 +215,24 @@ export default class GlobalState {
|
|
|
214
215
|
|
|
215
216
|
set(path, value) {
|
|
216
217
|
if (isNil(path)) return this.setEntireState(value);
|
|
218
|
+
|
|
219
|
+
// TODO: Revise.
|
|
220
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
217
221
|
if (value !== this.get(path)) {
|
|
218
222
|
const root = {
|
|
219
223
|
state: _classPrivateFieldGet(_currentState, this)
|
|
220
224
|
};
|
|
221
225
|
let segIdx = 0;
|
|
226
|
+
|
|
227
|
+
// TODO: It is not 100% correct, as `pos` can be an array, or any other
|
|
228
|
+
// value as we travel through the state tree. To simplify the typing for
|
|
229
|
+
// now, I guess, we can go with this record type, though.
|
|
222
230
|
let pos = root;
|
|
223
231
|
const pathSegments = toPath(`state.${path}`);
|
|
224
232
|
for (; segIdx < pathSegments.length - 1; segIdx += 1) {
|
|
225
233
|
const seg = pathSegments[segIdx];
|
|
234
|
+
|
|
235
|
+
// TODO: Revise: Typing is not quite correct here, but it works fine in the runtime.
|
|
226
236
|
const next = pos[seg];
|
|
227
237
|
if (Array.isArray(next)) pos[seg] = [...next];else if (isObject(next)) pos[seg] = {
|
|
228
238
|
...next
|
|
@@ -274,7 +284,7 @@ export default class GlobalState {
|
|
|
274
284
|
watch(callback) {
|
|
275
285
|
if (this.ssrContext) throw new Error(ERR_NO_SSR_WATCH);
|
|
276
286
|
const watchers = _classPrivateFieldGet(_watchers, this);
|
|
277
|
-
if (watchers.
|
|
287
|
+
if (!watchers.includes(callback)) {
|
|
278
288
|
watchers.push(callback);
|
|
279
289
|
}
|
|
280
290
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GlobalState.js","names":["get","isFunction","isObject","isNil","set","toPath","cloneDeepForLog","isDebugMode","ERR_NO_SSR_WATCH","_asyncDataAbortCallbacks","WeakMap","_dependencies","_initialState","_watchers","_nextNotifierId","_currentState","GlobalState","constructor","initialState","ssrContext","_classPrivateFieldInitSpec","_classPrivateFieldSet","dirty","pending","state","_classPrivateFieldGet","process","env","NODE_ENV","msg","console","groupCollapsed","log","groupEnd","numAsyncDataAbortCallbacks","Object","keys","length","asyncDataLoadDone","opid","aborted","_classPrivateFieldGet2","_classPrivateFieldGet3","call","dropDependencies","path","hasChangedDependencies","deps","prevDeps","changed","i","freeze","getEntireState","opts","undefined","initialValue","iv","setEntireState","notifyStateUpdate","value","p","setTimeout","watchers","watcher","setAsyncDataAbortCallback","cb","res","root","segIdx","pos","pathSegments","seg","next","Array","isArray","slice","unWatch","callback","Error","indexOf","pop","watch","includes","push"],"sources":["../../src/GlobalState.ts"],"sourcesContent":["import {\n get,\n isFunction,\n isObject,\n isNil,\n set,\n toPath,\n} from 'lodash';\n\nimport type SsrContext from './SsrContext';\n\nimport {\n type CallbackT,\n type ForceT,\n type LockT,\n type TypeLock,\n type ValueAtPathT,\n type ValueOrInitializerT,\n cloneDeepForLog,\n isDebugMode,\n} from './utils';\n\nconst ERR_NO_SSR_WATCH = 'GlobalState must not be watched at server side';\n\ntype GetOptsT<T> = {\n initialState?: boolean;\n initialValue?: ValueOrInitializerT<T>;\n};\n\nexport default class GlobalState<\n StateT,\n SsrContextT extends SsrContext<StateT> = SsrContext<StateT>,\n> {\n readonly ssrContext?: SsrContextT;\n\n #asyncDataAbortCallbacks: Record<string, () => void> = {};\n\n #dependencies: Record<string, readonly unknown[]> = {};\n\n #initialState: StateT;\n\n // TODO: It is tempting to replace watchers here by\n // Emitter from @dr.pogodin/js-utils, but we need to clone\n // current watchers for emitting later, and this is not something\n // Emitter supports right now.\n #watchers: CallbackT[] = [];\n\n #nextNotifierId?: NodeJS.Timeout;\n\n #currentState: StateT;\n\n /**\n * Creates a new global state object.\n * @param initialState Intial global state content.\n * @param ssrContext Server-side rendering context.\n */\n constructor(\n initialState: StateT,\n ssrContext?: SsrContextT,\n ) {\n this.#currentState = initialState;\n this.#initialState = initialState;\n\n if (ssrContext) {\n /* eslint-disable no-param-reassign */\n ssrContext.dirty = false;\n ssrContext.pending = [];\n ssrContext.state = this.#currentState;\n /* eslint-enable no-param-reassign */\n\n this.ssrContext = ssrContext;\n }\n\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n let msg = 'New ReactGlobalState created';\n if (ssrContext) msg += ' (SSR mode)';\n console.groupCollapsed(msg);\n console.log('Initial state:', cloneDeepForLog(initialState));\n console.groupEnd();\n /* eslint-enable no-console */\n }\n }\n\n /**\n * Returns the number of currently registered async data abort callbacks,\n * just for the sake of testing the library.\n */\n get numAsyncDataAbortCallbacks(): number {\n return Object.keys(this.#asyncDataAbortCallbacks).length;\n }\n\n /**\n * If `aborted` is \"true\" and there is an abort callback registered for\n * the specified operation, it triggers the callback. Then, in any case,\n * it drops the callback.\n */\n asyncDataLoadDone(opid: string, aborted: boolean): void {\n if (aborted) this.#asyncDataAbortCallbacks[opid]?.();\n delete this.#asyncDataAbortCallbacks[opid];\n }\n\n /**\n * Drops the record of dependencies, if any, for the given path.\n */\n dropDependencies(path: string): void {\n delete this.#dependencies[path];\n }\n\n /**\n * Checks if given `deps` are different from previously recorded ones for\n * the given `path`. If they are, `deps` are recorded as the new deps for\n * the `path`, and also the array is frozen, to prevent it from being\n * modified.\n *\n * TODO: This may not work as expected if path string is not normalized,\n * and the for the same path different alternative ways to spell it down\n * are used. We should normalize given path here, I guess, or on a higher\n * level in the logic?\n */\n hasChangedDependencies(path: string, deps: unknown[]): boolean {\n const prevDeps = this.#dependencies[path];\n let changed = !prevDeps || prevDeps.length !== deps.length;\n for (let i = 0; !changed && i < deps.length; ++i) {\n changed = prevDeps![i] !== deps[i];\n }\n this.#dependencies[path] = Object.freeze(deps);\n return changed;\n }\n\n /**\n * Gets entire state, the same way as .get(null, opts) would do.\n * @param opts.initialState\n * @param opts.initialValue\n */\n getEntireState(opts?: GetOptsT<StateT>): StateT {\n let state = opts?.initialState ? this.#initialState : this.#currentState;\n if (state !== undefined || opts?.initialValue === undefined) return state;\n\n const iv = opts.initialValue;\n state = isFunction(iv) ? iv() : iv;\n if (this.#currentState === undefined) this.setEntireState(state);\n return state;\n }\n\n /**\n * Notifies all connected state watchers that a state update has happened.\n */\n private notifyStateUpdate(path: null | string | undefined, value: unknown) {\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n const p = typeof path === 'string'\n ? `\"${path}\"` : 'none (entire state update)';\n console.groupCollapsed(`ReactGlobalState update. Path: ${p}`);\n console.log('New value:', cloneDeepForLog(value, path ?? ''));\n console.log('New state:', cloneDeepForLog(this.#currentState));\n console.groupEnd();\n /* eslint-enable no-console */\n }\n\n if (this.ssrContext) {\n this.ssrContext.dirty = true;\n this.ssrContext.state = this.#currentState;\n } else if (!this.#nextNotifierId) {\n this.#nextNotifierId = setTimeout(() => {\n this.#nextNotifierId = undefined;\n const watchers = [...this.#watchers];\n for (const watcher of watchers) watcher();\n });\n }\n }\n\n /**\n * Registers an abort callback for an async data retrieval operation with\n * the given operation ID. Throws if already registered.\n */\n setAsyncDataAbortCallback(opid: string, cb: () => void): void {\n this.#asyncDataAbortCallbacks[opid] = cb;\n }\n\n /**\n * Sets entire state, the same way as .set(null, value) would do.\n * @param value\n */\n setEntireState(value: StateT): StateT {\n if (this.#currentState !== value) {\n this.#currentState = value;\n this.notifyStateUpdate(null, value);\n }\n return value;\n }\n\n /**\n * Gets current or initial value at the specified \"path\" of the global state.\n * @param path Dot-delimitered state path.\n * @param options Additional options.\n * @param options.initialState If \"true\" the value will be read\n * from the initial state instead of the current one.\n * @param options.initialValue If the value read from the \"path\" is\n * \"undefined\", this \"initialValue\" will be returned instead. In such case\n * \"initialValue\" will also be written to the \"path\" of the current global\n * state (no matter \"initialState\" flag), if \"undefined\" is stored there.\n * @return Retrieved value.\n */\n\n // .get() without arguments just falls back to .getEntireState().\n get(): StateT;\n\n // This variant attempts to automatically resolve and check the type of value\n // at the given path, as precise as the actual state and path types permit.\n // If the automatic path resolution is not possible, the ValueT fallsback\n // to `never` (or to `undefined` in some cases), effectively forbidding\n // to use this .get() variant.\n get<\n PathT extends null | string | undefined,\n ValueArgT extends ValueAtPathT<StateT, PathT, never>,\n ValueResT extends ValueAtPathT<StateT, PathT, void>,\n >(path: PathT, opts?: GetOptsT<ValueArgT>): ValueResT;\n\n // This variant is not callable by default (without generic arguments),\n // otherwise it allows to set the correct ValueT directly.\n get<Forced extends ForceT | LockT = LockT, ValueT = void>(\n path?: null | string,\n opts?: GetOptsT<TypeLock<Forced, never, ValueT>>,\n ): TypeLock<Forced, void, ValueT>;\n\n get<ValueT>(path?: null | string, opts?: GetOptsT<ValueT>): ValueT {\n if (isNil(path)) {\n const res = this.getEntireState((opts as unknown) as GetOptsT<StateT>);\n return (res as unknown) as ValueT;\n }\n\n const state = opts?.initialState ? this.#initialState : this.#currentState;\n\n let res = get(state, path) as ValueT;\n if (res !== undefined || opts?.initialValue === undefined) return res;\n\n const iv = opts.initialValue;\n res = isFunction(iv) ? iv() : iv;\n\n // TODO: Revise.\n // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression\n if (!opts.initialState || (this.get(path) as unknown) === undefined) {\n this.set<ForceT, unknown>(path, res);\n }\n\n return res;\n }\n\n /**\n * Writes the `value` to given global state `path`.\n * @param path Dot-delimitered state path. If not given, entire\n * global state content is replaced by the `value`.\n * @param value The value.\n * @return Given `value` itself.\n */\n\n // This variant attempts automatic value type resolution & checking.\n set<\n PathT extends null | string | undefined,\n ValueArgT extends ValueAtPathT<StateT, PathT, never>,\n ValueResT extends ValueAtPathT<StateT, PathT, void>,\n >(path: PathT, value: ValueArgT): ValueResT;\n\n // This variant is disabled by default, otherwise allows to give\n // expected value type explicitly.\n set<Forced extends ForceT | LockT = LockT, ValueT = never>(\n path: null | string | undefined,\n value: TypeLock<Forced, never, ValueT>,\n ): TypeLock<Forced, void, ValueT>;\n\n set(path: null | string | undefined, value: unknown): unknown {\n if (isNil(path)) return this.setEntireState(value as StateT);\n\n // TODO: Revise.\n // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression\n if (value !== this.get(path)) {\n const root = { state: this.#currentState };\n let segIdx = 0;\n\n // TODO: It is not 100% correct, as `pos` can be an array, or any other\n // value as we travel through the state tree. To simplify the typing for\n // now, I guess, we can go with this record type, though.\n let pos: Record<string, unknown> = root;\n const pathSegments = toPath(`state.${path}`);\n for (; segIdx < pathSegments.length - 1; segIdx += 1) {\n const seg = pathSegments[segIdx]!;\n\n // TODO: Revise: Typing is not quite correct here, but it works fine in the runtime.\n const next = pos[seg];\n if (Array.isArray(next)) pos[seg] = [...(next as unknown[])];\n else if (isObject(next)) pos[seg] = { ...next };\n else {\n // We arrived to a state sub-segment, where the remaining part of\n // the update path does not exist yet. We rely on lodash's set()\n // function to create the remaining path, and set the value.\n set(pos, pathSegments.slice(segIdx), value);\n break;\n }\n pos = pos[seg] as Record<string, unknown>;\n }\n\n if (segIdx === pathSegments.length - 1) {\n pos[pathSegments[segIdx]!] = value;\n }\n\n this.#currentState = root.state;\n\n this.notifyStateUpdate(path, value);\n }\n return value;\n }\n\n /**\n * Unsubscribes `callback` from watching state updates; no operation if\n * `callback` is not subscribed to the state updates.\n * @param callback\n * @throws if {@link SsrContext} is attached to the state instance: the state\n * watching functionality is intended for client-side (non-SSR) only.\n */\n unWatch(callback: CallbackT): void {\n if (this.ssrContext) throw new Error(ERR_NO_SSR_WATCH);\n\n const watchers = this.#watchers;\n const pos = watchers.indexOf(callback);\n if (pos >= 0) {\n watchers[pos] = watchers[watchers.length - 1]!;\n watchers.pop();\n }\n }\n\n /**\n * Subscribes `callback` to watch state updates; no operation if\n * `callback` is already subscribed to this state instance.\n * @param callback It will be called without any arguments every\n * time the state content changes (note, howhever, separate state updates can\n * be applied to the state at once, and watching callbacks will be called once\n * after such bulk update).\n * @throws if {@link SsrContext} is attached to the state instance: the state\n * watching functionality is intended for client-side (non-SSR) only.\n */\n watch(callback: CallbackT): void {\n if (this.ssrContext) throw new Error(ERR_NO_SSR_WATCH);\n\n const watchers = this.#watchers;\n if (!watchers.includes(callback)) {\n watchers.push(callback);\n }\n }\n}\n"],"mappings":";;;;;AAAA,SACEA,GAAG,EACHC,UAAU,EACVC,QAAQ,EACRC,KAAK,EACLC,GAAG,EACHC,MAAM,QACD,QAAQ;AAIf,SAOEC,eAAe,EACfC,WAAW;AAGb,MAAMC,gBAAgB,GAAG,gDAAgD;AAAC,IAAAC,wBAAA,oBAAAC,OAAA;AAAA,IAAAC,aAAA,oBAAAD,OAAA;AAAA,IAAAE,aAAA,oBAAAF,OAAA;AAAA,IAAAG,SAAA,oBAAAH,OAAA;AAAA,IAAAI,eAAA,oBAAAJ,OAAA;AAAA,IAAAK,aAAA,oBAAAL,OAAA;AAO1E,eAAe,MAAMM,WAAW,CAG9B;EAmBA;AACF;AACA;AACA;AACA;EACEC,WAAWA,CACTC,YAAoB,EACpBC,UAAwB,EACxB;IAxBFC,0BAAA,OAAAX,wBAAwB,EAA+B,CAAC,CAAC;IAEzDW,0BAAA,OAAAT,aAAa,EAAuC,CAAC,CAAC;IAEtDS,0BAAA,OAAAR,aAAa;IAEb;IACA;IACA;IACA;IACAQ,0BAAA,OAAAP,SAAS,EAAgB,EAAE;IAE3BO,0BAAA,OAAAN,eAAe;IAEfM,0BAAA,OAAAL,aAAa;IAWXM,qBAAA,CAAKN,aAAa,EAAlB,IAAI,EAAiBG,YAAJ,CAAC;IAClBG,qBAAA,CAAKT,aAAa,EAAlB,IAAI,EAAiBM,YAAJ,CAAC;IAElB,IAAIC,UAAU,EAAE;MACd;MACAA,UAAU,CAACG,KAAK,GAAG,KAAK;MACxBH,UAAU,CAACI,OAAO,GAAG,EAAE;MACvBJ,UAAU,CAACK,KAAK,GAAGC,qBAAA,CAAKV,aAAa,EAAlB,IAAiB,CAAC;MACrC;;MAEA,IAAI,CAACI,UAAU,GAAGA,UAAU;IAC9B;IAEA,IAAIO,OAAO,CAACC,GAAG,CAACC,QAAQ,K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N,aAAa,EAAlB,IAAI,EAAiBoD,IAAI,CAAC3C,KAAT,CAAC;MAElB,IAAI,CAACkC,iBAAiB,CAACb,IAAI,EAAEc,KAAK,CAAC;IACrC;IACA,OAAOA,KAAK;EACd;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEiB,OAAOA,CAACC,QAAmB,EAAQ;IACjC,IAAI,IAAI,CAAC1D,UAAU,EAAE,MAAM,IAAI2D,KAAK,CAACtE,gBAAgB,CAAC;IAEtD,MAAMsD,QAAQ,GAAGrC,qBAAA,CAAKZ,SAAS,EAAd,IAAa,CAAC;IAC/B,MAAMwD,GAAG,GAAGP,QAAQ,CAACiB,OAAO,CAACF,QAAQ,CAAC;IACtC,IAAIR,GAAG,IAAI,CAAC,EAAE;MACZP,QAAQ,CAACO,GAAG,CAAC,GAAGP,QAAQ,CAACA,QAAQ,CAACzB,MAAM,GAAG,CAAC,CAAE;MAC9CyB,QAAQ,CAACkB,GAAG,CAAC,CAAC;IAChB;EACF;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,KAAKA,CAACJ,QAAmB,EAAQ;IAC/B,IAAI,IAAI,CAAC1D,UAAU,EAAE,MAAM,IAAI2D,KAAK,CAACtE,gBAAgB,CAAC;IAEtD,MAAMsD,QAAQ,GAAGrC,qBAAA,CAAKZ,SAAS,EAAd,IAAa,CAAC;IAC/B,IAAI,CAACiD,QAAQ,CAACoB,QAAQ,CAACL,QAAQ,CAAC,EAAE;MAChCf,QAAQ,CAACqB,IAAI,CAACN,QAAQ,CAAC;IACzB;EACF;AACF","ignoreList":[]}
|
|
@@ -11,6 +11,12 @@ const Context = /*#__PURE__*/createContext(null);
|
|
|
11
11
|
* @return
|
|
12
12
|
*/
|
|
13
13
|
export function getGlobalState() {
|
|
14
|
+
// TODO: Think about it: on one hand we on purpose called this function
|
|
15
|
+
// as getGlobalState(), so that ppl looking for the state hook prefer using
|
|
16
|
+
// useGlobalState(), while this getGlobalState() is reserved for nieche cases;
|
|
17
|
+
// on the other hand, perhaps we can rename it into useSomething, to both
|
|
18
|
+
// follow conventions, and to keep stuff clearly named at the same time.
|
|
19
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
14
20
|
const globalState = use(Context);
|
|
15
21
|
if (!globalState) throw new Error('Missing GlobalStateProvider');
|
|
16
22
|
return globalState;
|
|
@@ -60,6 +66,8 @@ const GlobalStateProvider = _ref => {
|
|
|
60
66
|
} = _ref;
|
|
61
67
|
const localStateRef = useRef(undefined);
|
|
62
68
|
let state;
|
|
69
|
+
// TODO: Revise.
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
63
71
|
if ('stateProxy' in rest && rest.stateProxy) {
|
|
64
72
|
localStateRef.current = undefined;
|
|
65
73
|
state = rest.stateProxy === true ? getGlobalState() : rest.stateProxy;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GlobalStateProvider.js","names":["isFunction","createContext","use","useRef","GlobalState","jsx","_jsx","Context","getGlobalState","globalState","Error","getSsrContext","throwWithoutSsrContext","arguments","length","undefined","ssrContext","GlobalStateProvider","_ref","children","rest","localStateRef","state","stateProxy","current","initialState","value"],"sources":["../../src/GlobalStateProvider.tsx"],"sourcesContent":["import { isFunction } from 'lodash';\n\nimport {\n type ReactNode,\n createContext,\n use,\n useRef,\n} from 'react';\n\nimport GlobalState from './GlobalState';\nimport type SsrContext from './SsrContext';\n\nimport type { ValueOrInitializerT } from './utils';\n\nconst Context = createContext<GlobalState<unknown> | null>(null);\n\n/**\n * Gets {@link GlobalState} instance from the context. In most cases\n * you should use {@link useGlobalState}, and other hooks to interact with\n * the global state, instead of accessing it directly.\n * @return\n */\nexport function getGlobalState<\n StateT,\n SsrContextT extends SsrContext<StateT> = SsrContext<StateT>,\n>(): GlobalState<StateT, SsrContextT> {\n // TODO: Think about it: on one hand we on purpose called this function\n // as getGlobalState(), so that ppl looking for the state hook prefer using\n // useGlobalState(), while this getGlobalState() is reserved for nieche cases;\n // on the other hand, perhaps we can rename it into useSomething, to both\n // follow conventions, and to keep stuff clearly named at the same time.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const globalState = use(Context);\n if (!globalState) throw new Error('Missing GlobalStateProvider');\n return globalState as GlobalState<StateT, SsrContextT>;\n}\n\n/**\n * @category Hooks\n * @desc Gets SSR context.\n * @param throwWithoutSsrContext If `true` (default),\n * this hook will throw if no SSR context is attached to the global state;\n * set `false` to not throw in such case. In either case the hook will throw\n * if the {@link <GlobalStateProvider>} (hence the state) is missing.\n * @returns SSR context.\n * @throws\n * - If current component has no parent {@link <GlobalStateProvider>}\n * in the rendered React tree.\n * - If `throwWithoutSsrContext` is `true`, and there is no SSR context attached\n * to the global state provided by {@link <GlobalStateProvider>}.\n */\nexport function getSsrContext<\n SsrContextT extends SsrContext<unknown>,\n>(\n throwWithoutSsrContext = true,\n): SsrContextT | undefined {\n const { ssrContext } = getGlobalState<SsrContextT['state'], SsrContextT>();\n if (!ssrContext && throwWithoutSsrContext) {\n throw new Error('No SSR context found');\n }\n return ssrContext;\n}\n\ntype NewStateProps<StateT, SsrContextT extends SsrContext<StateT>> = {\n initialState: ValueOrInitializerT<StateT>;\n ssrContext?: SsrContextT;\n};\n\ntype GlobalStateProviderProps<\n StateT,\n SsrContextT extends SsrContext<StateT>,\n> = {\n children?: ReactNode;\n} & (NewStateProps<StateT, SsrContextT> | {\n stateProxy: true | GlobalState<StateT, SsrContextT>;\n});\n\n/**\n * Provides global state to its children.\n * @param prop.children Component children, which will be provided with\n * the global state, and rendered in place of the provider.\n * @param prop.initialState Initial content of the global state.\n * @param prop.ssrContext Server-side rendering (SSR) context.\n * @param prop.stateProxy This option is useful for code\n * splitting and SSR implementation:\n * - If `true`, this provider instance will fetch and reuse the global state\n * from a parent provider.\n * - If `GlobalState` instance, it will be used by this provider.\n * - If not given, a new `GlobalState` instance will be created and used.\n */\nconst GlobalStateProvider = <\n StateT,\n SsrContextT extends SsrContext<StateT> = SsrContext<StateT>,\n>(\n { children, ...rest }: GlobalStateProviderProps<StateT, SsrContextT>,\n): ReactNode => {\n type GST = GlobalState<StateT, SsrContextT>;\n const localStateRef = useRef<GST>(undefined);\n let state: GST;\n // TODO: Revise.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if ('stateProxy' in rest && rest.stateProxy) {\n localStateRef.current = undefined;\n state = rest.stateProxy === true ? getGlobalState() : rest.stateProxy;\n } else {\n if (!localStateRef.current) {\n const {\n initialState,\n ssrContext,\n } = rest as NewStateProps<StateT, SsrContextT>;\n localStateRef.current = new GlobalState(\n isFunction(initialState) ? initialState() : initialState,\n ssrContext,\n );\n }\n state = localStateRef.current;\n }\n return <Context value={state}>{children}</Context>;\n};\n\nexport default GlobalStateProvider;\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,QAAQ;AAEnC,SAEEC,aAAa,EACbC,GAAG,EACHC,MAAM,QACD,OAAO;AAEd,OAAOC,WAAW;AAAsB,SAAAC,GAAA,IAAAC,IAAA;AAKxC,MAAMC,OAAO,gBAAGN,aAAa,CAA8B,IAAI,CAAC;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASO,cAAcA,CAAA,EAGQ;EACpC;EACA;EACA;EACA;EACA;EACA;EACA,MAAMC,WAAW,GAAGP,GAAG,CAACK,OAAO,CAAC;EAChC,IAAI,CAACE,WAAW,EAAE,MAAM,IAAIC,KAAK,CAAC,6BAA6B,CAAC;EAChE,OAAOD,WAAW;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,aAAaA,CAAA,EAIF;EAAA,IADzBC,sBAAsB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;EAE7B,MAAM;IAAEG;EAAW,CAAC,GAAGR,cAAc,CAAoC,CAAC;EAC1E,IAAI,CAACQ,UAAU,IAAIJ,sBAAsB,EAAE;IACzC,MAAM,IAAIF,KAAK,CAAC,sBAAsB,CAAC;EACzC;EACA,OAAOM,UAAU;AACnB;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mBAAmB,GAAGC,IAAA,IAKZ;EAAA,IADd;IAAEC,QAAQ;IAAE,GAAGC;EAAoD,CAAC,GAAAF,IAAA;EAGpE,MAAMG,aAAa,GAAGlB,MAAM,CAAMY,SAAS,CAAC;EAC5C,IAAIO,KAAU;EACd;EACA;EACA,IAAI,YAAY,IAAIF,IAAI,IAAIA,IAAI,CAACG,UAAU,EAAE;IAC3CF,aAAa,CAACG,OAAO,GAAGT,SAAS;IACjCO,KAAK,GAAGF,IAAI,CAACG,UAAU,KAAK,IAAI,GAAGf,cAAc,CAAC,CAAC,GAAGY,IAAI,CAACG,UAAU;EACvE,CAAC,MAAM;IACL,IAAI,CAACF,aAAa,CAACG,OAAO,EAAE;MAC1B,MAAM;QACJC,YAAY;QACZT;MACF,CAAC,GAAGI,IAA0C;MAC9CC,aAAa,CAACG,OAAO,GAAG,IAAIpB,WAAW,CACrCJ,UAAU,CAACyB,YAAY,CAAC,GAAGA,YAAY,CAAC,CAAC,GAAGA,YAAY,EACxDT,UACF,CAAC;IACH;IACAM,KAAK,GAAGD,aAAa,CAACG,OAAO;EAC/B;EACA,oBAAOlB,IAAA,CAACC,OAAO;IAACmB,KAAK,EAAEJ,KAAM;IAAAH,QAAA,EAAEA;EAAQ,CAAU,CAAC;AACpD,CAAC;AAED,eAAeF,mBAAmB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SsrContext.js","names":["SsrContext","constructor","state","_defineProperty"],"sources":["../../src/SsrContext.ts"],"sourcesContent":["export default class SsrContext<StateT> {\n dirty: boolean = false;\n\n pending: Array<Promise<void>> = [];\n\n constructor(public state?: StateT) { }\n}\n"],"mappings":";AAAA,eAAe,MAAMA,UAAU,CAAS;EAKtCC,WAAWA,CAAQC,KAAc,EAAE;IAAAC,eAAA,gBAJlB,KAAK;IAAAA,eAAA,kBAEU,EAAE;IAAA,KAEfD,KAAc,GAAdA,KAAc;EAAI;AACvC","ignoreList":[]}
|
|
@@ -5,13 +5,19 @@ import useAsyncCollection from "./useAsyncCollection";
|
|
|
5
5
|
import { newAsyncDataEnvelope, useAsyncData } from "./useAsyncData";
|
|
6
6
|
import useGlobalState from "./useGlobalState";
|
|
7
7
|
export { getGlobalState, getSsrContext, GlobalState, GlobalStateProvider, newAsyncDataEnvelope, SsrContext, useAsyncCollection, useAsyncData, useGlobalState };
|
|
8
|
+
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
10
|
+
|
|
8
11
|
const api = {
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
// TODO: I am puzzled, why ESLint eforces this sorting order as alphabetical?
|
|
13
|
+
// Perhaps, we should tune something in its config settings, as it seems to mix
|
|
14
|
+
// some extra sorting logic, which I am not sure I like.
|
|
11
15
|
GlobalState,
|
|
12
16
|
GlobalStateProvider,
|
|
13
|
-
newAsyncDataEnvelope,
|
|
14
17
|
SsrContext,
|
|
18
|
+
getGlobalState,
|
|
19
|
+
getSsrContext,
|
|
20
|
+
newAsyncDataEnvelope,
|
|
15
21
|
useAsyncCollection,
|
|
16
22
|
useAsyncData,
|
|
17
23
|
useGlobalState
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["GlobalState","GlobalStateProvider","getGlobalState","getSsrContext","SsrContext","useAsyncCollection","newAsyncDataEnvelope","useAsyncData","useGlobalState","api","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 { AsyncCollectionLoaderT, AsyncCollectionT } 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,OAAOA,WAAW;AAElB,OAAOC,mBAAmB,IACxBC,cAAc,EACdC,aAAa;AAGf,OAAOC,UAAU;AAEjB,OAAOC,kBAAkB;AAKzB,SAOEC,oBAAoB,EACpBC,YAAY;AAGd,OAAOC,cAAc;AAQrB,SAOEN,cAAc,EACdC,aAAa,EACbH,WAAW,EACXC,mBAAmB,EACnBK,oBAAoB,EACpBF,UAAU,EACVC,kBAAkB,EAClBE,YAAY,EACZC,cAAc;;AAGhB;;AAgBA,MAAMC,GAAG,GAAG;EACV;EACA;EACA;EACAT,WAAW;EACXC,mBAAmB;EACnBG,UAAU;EACVF,cAAc;EACdC,aAAa;EACbG,oBAAoB;EACpBD,kBAAkB;EAClBE,YAAY;EACZC;AACF,CAAC;AAED,OAAO,SAASE,mBAAmBA,CAAA,EAGL;EAC5B,OAAOD,GAAG;AACZ","ignoreList":[]}
|
|
@@ -18,8 +18,7 @@ function gcOnWithhold(ids, path, gs) {
|
|
|
18
18
|
const collection = {
|
|
19
19
|
...gs.get(path)
|
|
20
20
|
};
|
|
21
|
-
for (
|
|
22
|
-
const id = ids[i];
|
|
21
|
+
for (const id of ids) {
|
|
23
22
|
let envelope = collection[id];
|
|
24
23
|
if (envelope) envelope = {
|
|
25
24
|
...envelope,
|
|
@@ -33,8 +32,8 @@ function gcOnWithhold(ids, path, gs) {
|
|
|
33
32
|
}
|
|
34
33
|
function idsToStringSet(ids) {
|
|
35
34
|
const res = new Set();
|
|
36
|
-
for (
|
|
37
|
-
res.add(
|
|
35
|
+
for (const id of ids) {
|
|
36
|
+
res.add(id.toString());
|
|
38
37
|
}
|
|
39
38
|
return res;
|
|
40
39
|
}
|
|
@@ -51,8 +50,7 @@ function gcOnRelease(ids, path, gs, gcAge) {
|
|
|
51
50
|
const now = Date.now();
|
|
52
51
|
const idSet = idsToStringSet(ids);
|
|
53
52
|
const collection = {};
|
|
54
|
-
for (
|
|
55
|
-
const [id, envelope] = entries[i];
|
|
53
|
+
for (const [id, envelope] of entries) {
|
|
56
54
|
if (envelope) {
|
|
57
55
|
const toBeReleased = idSet.has(id);
|
|
58
56
|
let {
|
|
@@ -75,7 +73,7 @@ function gcOnRelease(ids, path, gs, gcAge) {
|
|
|
75
73
|
function normalizeIds(idOrIds) {
|
|
76
74
|
if (Array.isArray(idOrIds)) {
|
|
77
75
|
const res = [...idOrIds];
|
|
78
|
-
res.sort();
|
|
76
|
+
res.sort((a, b) => a.toString().localeCompare(b.toString()));
|
|
79
77
|
return res;
|
|
80
78
|
}
|
|
81
79
|
return [idOrIds];
|
|
@@ -97,25 +95,46 @@ function useHeap(ids, path, loader, gs) {
|
|
|
97
95
|
// Initialization.
|
|
98
96
|
const reload = async customLoader => {
|
|
99
97
|
const heap2 = ref.current;
|
|
100
|
-
const localLoader = customLoader
|
|
98
|
+
const localLoader = customLoader !== null && customLoader !== void 0 ? customLoader : heap2.loader;
|
|
99
|
+
// TODO: Revise - not sure all related typing is 100% correct,
|
|
100
|
+
// thus let's keep this runtime assertion.
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
101
102
|
if (!localLoader || !heap2.globalState || !heap2.ids) {
|
|
102
103
|
throw Error('Internal error');
|
|
103
104
|
}
|
|
104
|
-
for (
|
|
105
|
-
const id = heap2.ids[i];
|
|
105
|
+
for (const id of heap2.ids) {
|
|
106
106
|
const itemPath = heap2.path ? `${heap2.path}.${id}` : `${id}`;
|
|
107
|
-
|
|
108
|
-
//
|
|
109
|
-
|
|
107
|
+
const promiseOrVoid = load(itemPath,
|
|
108
|
+
// TODO: Revise! Most probably we don't have fully correct loader
|
|
109
|
+
// typing, as it may return either promise or value, and those two
|
|
110
|
+
// cases call for different runtime behavior, which in turns only
|
|
111
|
+
// happens if the outer function on the next line matches the same
|
|
112
|
+
// async / sync signature.
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
114
|
+
(oldData, meta) => localLoader(id, oldData, meta), heap2.globalState);
|
|
115
|
+
if (promiseOrVoid instanceof Promise) await promiseOrVoid;
|
|
110
116
|
}
|
|
111
117
|
};
|
|
112
118
|
heap = {
|
|
113
119
|
globalState: gs,
|
|
114
120
|
ids,
|
|
115
|
-
path,
|
|
116
121
|
loader,
|
|
122
|
+
path,
|
|
117
123
|
reload,
|
|
118
|
-
|
|
124
|
+
// TODO: Revise! Most probably we don't have fully correct loader
|
|
125
|
+
// typing, as it may return either promise or value, and those two
|
|
126
|
+
// cases call for different runtime behavior, which in turns only
|
|
127
|
+
// happens if the outer function on the next line matches the same
|
|
128
|
+
// async / sync signature.
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
130
|
+
reloadSingle: customLoader => ref.current.reload(
|
|
131
|
+
// TODO: Revise! Most probably we don't have fully correct loader
|
|
132
|
+
// typing, as it may return either promise or value, and those two
|
|
133
|
+
// cases call for different runtime behavior, which in turns only
|
|
134
|
+
// happens if the outer function on the next line matches the same
|
|
135
|
+
// async / sync signature.
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
137
|
+
customLoader && function (id) {
|
|
119
138
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
120
139
|
args[_key - 1] = arguments[_key];
|
|
121
140
|
}
|
|
@@ -135,6 +154,7 @@ function useHeap(ids, path, loader, gs) {
|
|
|
135
154
|
// TODO: This is largely similar to useAsyncData() logic, just more generic.
|
|
136
155
|
// Perhaps, a bunch of logic blocks can be split into stand-alone functions,
|
|
137
156
|
// and reused in both hooks.
|
|
157
|
+
// eslint-disable-next-line complexity
|
|
138
158
|
function useAsyncCollection(idOrIds, path, loader) {
|
|
139
159
|
var _options$maxage, _options$refreshAge, _options$garbageColle;
|
|
140
160
|
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
@@ -148,14 +168,13 @@ function useAsyncCollection(idOrIds, path, loader) {
|
|
|
148
168
|
// Server-side logic.
|
|
149
169
|
if (globalState.ssrContext && !options.noSSR) {
|
|
150
170
|
const operationId = `S${uuid()}`;
|
|
151
|
-
for (
|
|
152
|
-
const id = ids[i];
|
|
171
|
+
for (const id of ids) {
|
|
153
172
|
const itemPath = path ? `${path}.${id}` : `${id}`;
|
|
154
173
|
const state = globalState.get(itemPath, {
|
|
155
174
|
initialValue: newAsyncDataEnvelope()
|
|
156
175
|
});
|
|
157
176
|
if (!state.timestamp && !state.operationId) {
|
|
158
|
-
|
|
177
|
+
const promiseOrVoid = load(itemPath, function () {
|
|
159
178
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
160
179
|
args[_key2] = arguments[_key2];
|
|
161
180
|
}
|
|
@@ -163,7 +182,10 @@ function useAsyncCollection(idOrIds, path, loader) {
|
|
|
163
182
|
}, globalState, {
|
|
164
183
|
data: state.data,
|
|
165
184
|
timestamp: state.timestamp
|
|
166
|
-
}, operationId)
|
|
185
|
+
}, operationId);
|
|
186
|
+
if (promiseOrVoid instanceof Promise) {
|
|
187
|
+
globalState.ssrContext.pending.push(promiseOrVoid);
|
|
188
|
+
}
|
|
167
189
|
}
|
|
168
190
|
}
|
|
169
191
|
|
|
@@ -178,7 +200,9 @@ function useAsyncCollection(idOrIds, path, loader) {
|
|
|
178
200
|
useEffect(() => {
|
|
179
201
|
// eslint-disable-line react-hooks/rules-of-hooks
|
|
180
202
|
gcOnWithhold(ids, path, globalState);
|
|
181
|
-
return () =>
|
|
203
|
+
return () => {
|
|
204
|
+
gcOnRelease(ids, path, globalState, garbageCollectAge);
|
|
205
|
+
};
|
|
182
206
|
|
|
183
207
|
// `ids` are represented in the dependencies array by `idsHash` value,
|
|
184
208
|
// as useEffect() hook requires a constant size of dependencies array.
|
|
@@ -191,20 +215,23 @@ function useAsyncCollection(idOrIds, path, loader) {
|
|
|
191
215
|
// Data loading and refreshing.
|
|
192
216
|
useEffect(() => {
|
|
193
217
|
// eslint-disable-line react-hooks/rules-of-hooks
|
|
194
|
-
(async () => {
|
|
195
|
-
for (
|
|
218
|
+
void (async () => {
|
|
219
|
+
for (const id of ids) {
|
|
196
220
|
var _state2$timestamp;
|
|
197
|
-
const id = ids[i];
|
|
198
221
|
const itemPath = path ? `${path}.${id}` : `${id}`;
|
|
199
222
|
const state2 = globalState.get(itemPath);
|
|
200
223
|
const {
|
|
201
224
|
deps
|
|
202
225
|
} = options;
|
|
203
|
-
if (deps && globalState.hasChangedDependencies(itemPath, deps) || refreshAge < Date.now() - ((_state2$timestamp = state2 === null || state2 === void 0 ? void 0 : state2.timestamp) !== null && _state2$timestamp !== void 0 ? _state2$timestamp : 0) && (!(state2 !== null && state2 !== void 0 && state2.operationId) || state2.operationId.
|
|
226
|
+
if (deps && globalState.hasChangedDependencies(itemPath, deps) || refreshAge < Date.now() - ((_state2$timestamp = state2 === null || state2 === void 0 ? void 0 : state2.timestamp) !== null && _state2$timestamp !== void 0 ? _state2$timestamp : 0) && (!(state2 !== null && state2 !== void 0 && state2.operationId) || state2.operationId.startsWith('S'))) {
|
|
204
227
|
var _state2$timestamp2;
|
|
205
228
|
if (!deps) globalState.dropDependencies(itemPath);
|
|
206
|
-
|
|
207
|
-
|
|
229
|
+
await load(itemPath,
|
|
230
|
+
// TODO: I guess, the loader is not correctly typed here -
|
|
231
|
+
// it can be synchronous, and in that case the following method
|
|
232
|
+
// should be kept synchronous to not alter the sync logic.
|
|
233
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
234
|
+
function (old) {
|
|
208
235
|
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
209
236
|
args[_key3 - 1] = arguments[_key3];
|
|
210
237
|
}
|
|
@@ -221,6 +248,7 @@ function useAsyncCollection(idOrIds, path, loader) {
|
|
|
221
248
|
const [localState] = useGlobalState(path, {});
|
|
222
249
|
if (!Array.isArray(idOrIds)) {
|
|
223
250
|
var _e$timestamp, _e$data;
|
|
251
|
+
// TODO: Revise related typings!
|
|
224
252
|
const e = localState[idOrIds];
|
|
225
253
|
const timestamp = (_e$timestamp = e === null || e === void 0 ? void 0 : e.timestamp) !== null && _e$timestamp !== void 0 ? _e$timestamp : 0;
|
|
226
254
|
return {
|
|
@@ -236,9 +264,9 @@ function useAsyncCollection(idOrIds, path, loader) {
|
|
|
236
264
|
reload: heap.reload,
|
|
237
265
|
timestamp: Number.MAX_VALUE
|
|
238
266
|
};
|
|
239
|
-
for (
|
|
267
|
+
for (const id of ids) {
|
|
240
268
|
var _e$timestamp2, _e$data2;
|
|
241
|
-
|
|
269
|
+
// TODO: Revise related typing. Should `localState` have a more specific type?
|
|
242
270
|
const e = localState[id];
|
|
243
271
|
const loading = !!(e !== null && e !== void 0 && e.operationId);
|
|
244
272
|
const timestamp = (_e$timestamp2 = e === null || e === void 0 ? void 0 : e.timestamp) !== null && _e$timestamp2 !== void 0 ? _e$timestamp2 : 0;
|
|
@@ -253,4 +281,6 @@ function useAsyncCollection(idOrIds, path, loader) {
|
|
|
253
281
|
return res;
|
|
254
282
|
}
|
|
255
283
|
export default useAsyncCollection;
|
|
284
|
+
|
|
285
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
256
286
|
//# sourceMappingURL=useAsyncCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAsyncCollection.js","names":["useEffect","useRef","v4","uuid","getGlobalState","DEFAULT_MAXAGE","load","newAsyncDataEnvelope","useGlobalState","hash","isDebugMode","gcOnWithhold","ids","path","gs","collection","get","id","envelope","numRefs","set","idsToStringSet","res","Set","add","toString","gcOnRelease","gcAge","entries","Object","now","Date","idSet","toBeReleased","has","timestamp","process","env","NODE_ENV","console","log","normalizeIds","idOrIds","Array","isArray","sort","a","b","localeCompare","useHeap","loader","ref","undefined","heap","current","globalState","reload","customLoader","heap2","localLoader","Error","itemPath","promiseOrVoid","oldData","meta","Promise","reloadSingle","_len","arguments","length","args","_key","useAsyncCollection","_options$maxage","_options$refreshAge","_options$garbageColle","options","maxage","refreshAge","garbageCollectAge","ssrContext","noSSR","operationId","state","initialValue","_len2","_key2","data","pending","push","idsHash","_state2$timestamp","state2","deps","hasChangedDependencies","startsWith","_state2$timestamp2","dropDependencies","old","_len3","_key3","localState","_e$timestamp","_e$data","e","loading","items","Number","MAX_VALUE","_e$timestamp2","_e$data2"],"sources":["../../src/useAsyncCollection.ts"],"sourcesContent":["/**\n * Loads and uses item(s) in an async collection.\n */\n\nimport { useEffect, useRef } 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> =\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>\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 HeapT<\n DataT,\n IdT extends number | string,\n> = {\n // Note: these heap fields are necessary to make reload() a stable function.\n globalState: GlobalState<unknown>;\n ids: IdT[];\n path: null | string | undefined;\n loader: AsyncCollectionLoaderT<DataT, IdT>;\n reload: AsyncCollectionReloaderT<DataT, IdT>;\n reloadSingle: AsyncDataReloaderT<DataT>;\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 const res = [...idOrIds];\n res.sort((a, b) => a.toString().localeCompare(b.toString()));\n return res;\n }\n return [idOrIds];\n}\n\n/**\n * Inits/updates, and returns the heap.\n */\nfunction useHeap<\n DataT,\n IdT extends number | string,\n>(\n ids: IdT[],\n path: null | string | undefined,\n loader: AsyncCollectionLoaderT<DataT, IdT>,\n gs: GlobalState<unknown>,\n): HeapT<DataT, IdT> {\n const ref = useRef<HeapT<DataT, IdT>>(undefined);\n\n let heap = ref.current;\n\n if (heap) {\n // Update.\n heap.ids = ids;\n heap.path = path;\n heap.loader = loader;\n heap.globalState = gs;\n } else {\n // Initialization.\n const reload = async (\n customLoader?: AsyncCollectionLoaderT<DataT, IdT>,\n ) => {\n const heap2 = ref.current!;\n\n const localLoader = customLoader ?? heap2.loader;\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 || !heap2.globalState || !heap2.ids) {\n throw Error('Internal error');\n }\n\n for (const id of heap2.ids) {\n const itemPath = heap2.path ? `${heap2.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 heap2.globalState,\n );\n\n if (promiseOrVoid instanceof Promise) await promiseOrVoid;\n }\n };\n heap = {\n globalState: gs,\n ids,\n loader,\n path,\n 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 reloadSingle: (customLoader) => ref.current!.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 ref.current = heap;\n }\n\n return heap;\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 const heap = useHeap(ids, path, loader, globalState);\n\n // Server-side logic.\n if (globalState.ssrContext && !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 // Client-side logic.\n } else {\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 gcOnWithhold(ids, path, globalState);\n return () => {\n 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 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 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 const [localState] = useGlobalState<\n ForceT, Record<string, AsyncDataEnvelopeT<DataT>>\n >(path, {});\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: heap.reloadSingle,\n timestamp,\n };\n }\n\n const res: UseAsyncCollectionResT<DataT, IdT> = {\n items: {} as Record<IdT, CollectionItemT<DataT>>,\n loading: false,\n reload: heap.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":"AAAA;AACA;AACA;;AAEA,SAASA,SAAS,EAAEC,MAAM,QAAQ,OAAO;AACzC,SAASC,EAAE,IAAIC,IAAI,QAAQ,MAAM;AAGjC,SAASC,cAAc;AAEvB,SAOEC,cAAc,EACdC,IAAI,EACJC,oBAAoB;AAGtB,OAAOC,cAAc;AAErB,SAIEC,IAAI,EACJC,WAAW;AAqDb;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,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,GAA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