@dr.pogodin/react-global-state 0.20.1 → 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/package.json +4 -6
- package/build/cjs/GlobalState.js +0 -295
- 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 -149
- package/build/cjs/useGlobalState.js.map +0 -1
- package/build/cjs/utils.js +0 -92
- package/build/cjs/utils.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dr.pogodin/react-global-state",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Hook-based global state for React",
|
|
5
5
|
"main": "./build/code/index.js",
|
|
6
6
|
"types": "./build/types/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
|
-
"require": "./build/cjs/index.js",
|
|
9
8
|
"types": "./build/types/index.d.ts",
|
|
10
9
|
"default": "./build/code/index.js"
|
|
11
10
|
},
|
|
12
11
|
"scripts": {
|
|
13
|
-
"build": "rimraf build && npm run build:types && npm run build:code
|
|
14
|
-
"build:cjs": "rimraf buidl/cjs && babel src -x .ts,.tsx --out-dir build/cjs --source-maps",
|
|
12
|
+
"build": "rimraf build && npm run build:types && npm run build:code",
|
|
15
13
|
"build:code": "rimraf build/code && babel src -x .ts,.tsx --out-dir build/code --source-maps --config-file ./babel.module.config.js",
|
|
16
14
|
"build:types": "rimraf build/types && tsc --project tsconfig.types.json",
|
|
17
15
|
"jest": "npm run jest:types && npm run jest:logic",
|
|
@@ -58,7 +56,7 @@
|
|
|
58
56
|
"@dr.pogodin/eslint-configs": "^0.1.1",
|
|
59
57
|
"@testing-library/dom": "^10.4.1",
|
|
60
58
|
"@testing-library/react": "^16.3.0",
|
|
61
|
-
"@tsconfig/recommended": "^1.0.
|
|
59
|
+
"@tsconfig/recommended": "^1.0.11",
|
|
62
60
|
"@types/jest": "^30.0.0",
|
|
63
61
|
"@types/pretty": "^2.0.3",
|
|
64
62
|
"@types/react": "^19.2.2",
|
|
@@ -69,7 +67,7 @@
|
|
|
69
67
|
"jest": "^30.2.0",
|
|
70
68
|
"jest-environment-jsdom": "^30.2.0",
|
|
71
69
|
"mockdate": "^3.0.5",
|
|
72
|
-
"rimraf": "^6.0
|
|
70
|
+
"rimraf": "^6.1.0",
|
|
73
71
|
"tstyche": "^5.0.0",
|
|
74
72
|
"typescript": "^5.9.3"
|
|
75
73
|
},
|
package/build/cjs/GlobalState.js
DELETED
|
@@ -1,295 +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 _get = _interopRequireDefault(require("lodash/get.js"));
|
|
9
|
-
var _isFunction = _interopRequireDefault(require("lodash/isFunction.js"));
|
|
10
|
-
var _isObject = _interopRequireDefault(require("lodash/isObject.js"));
|
|
11
|
-
var _isNil = _interopRequireDefault(require("lodash/isNil.js"));
|
|
12
|
-
var _set = _interopRequireDefault(require("lodash/set.js"));
|
|
13
|
-
var _toPath = _interopRequireDefault(require("lodash/toPath.js"));
|
|
14
|
-
var _utils = require("./utils");
|
|
15
|
-
const ERR_NO_SSR_WATCH = 'GlobalState must not be watched at server side';
|
|
16
|
-
class GlobalState {
|
|
17
|
-
#asyncDataAbortCallbacks = {};
|
|
18
|
-
#dependencies = {};
|
|
19
|
-
#initialState;
|
|
20
|
-
|
|
21
|
-
// TODO: It is tempting to replace watchers here by
|
|
22
|
-
// Emitter from @dr.pogodin/js-utils, but we need to clone
|
|
23
|
-
// current watchers for emitting later, and this is not something
|
|
24
|
-
// Emitter supports right now.
|
|
25
|
-
#watchers = [];
|
|
26
|
-
#nextNotifierId;
|
|
27
|
-
#currentState;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Creates a new global state object.
|
|
31
|
-
* @param initialState Intial global state content.
|
|
32
|
-
* @param ssrContext Server-side rendering context.
|
|
33
|
-
*/
|
|
34
|
-
constructor(initialState, ssrContext) {
|
|
35
|
-
this.#currentState = initialState;
|
|
36
|
-
this.#initialState = initialState;
|
|
37
|
-
if (ssrContext) {
|
|
38
|
-
/* eslint-disable no-param-reassign */
|
|
39
|
-
ssrContext.dirty = false;
|
|
40
|
-
ssrContext.pending = [];
|
|
41
|
-
ssrContext.state = this.#currentState;
|
|
42
|
-
/* eslint-enable no-param-reassign */
|
|
43
|
-
|
|
44
|
-
this.ssrContext = ssrContext;
|
|
45
|
-
}
|
|
46
|
-
if (process.env.NODE_ENV !== 'production' && (0, _utils.isDebugMode)()) {
|
|
47
|
-
/* eslint-disable no-console */
|
|
48
|
-
let msg = 'New ReactGlobalState created';
|
|
49
|
-
if (ssrContext) msg += ' (SSR mode)';
|
|
50
|
-
console.groupCollapsed(msg);
|
|
51
|
-
console.log('Initial state:', (0, _utils.cloneDeepForLog)(initialState));
|
|
52
|
-
console.groupEnd();
|
|
53
|
-
/* eslint-enable no-console */
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Returns the number of currently registered async data abort callbacks,
|
|
59
|
-
* just for the sake of testing the library.
|
|
60
|
-
*/
|
|
61
|
-
get numAsyncDataAbortCallbacks() {
|
|
62
|
-
return Object.keys(this.#asyncDataAbortCallbacks).length;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* If `aborted` is "true" and there is an abort callback registered for
|
|
67
|
-
* the specified operation, it triggers the callback. Then, in any case,
|
|
68
|
-
* it drops the callback.
|
|
69
|
-
*/
|
|
70
|
-
asyncDataLoadDone(opid, aborted) {
|
|
71
|
-
if (aborted) this.#asyncDataAbortCallbacks[opid]?.();
|
|
72
|
-
delete this.#asyncDataAbortCallbacks[opid];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Drops the record of dependencies, if any, for the given path.
|
|
77
|
-
*/
|
|
78
|
-
dropDependencies(path) {
|
|
79
|
-
delete this.#dependencies[path];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Checks if given `deps` are different from previously recorded ones for
|
|
84
|
-
* the given `path`. If they are, `deps` are recorded as the new deps for
|
|
85
|
-
* the `path`, and also the array is frozen, to prevent it from being
|
|
86
|
-
* modified.
|
|
87
|
-
*
|
|
88
|
-
* TODO: This may not work as expected if path string is not normalized,
|
|
89
|
-
* and the for the same path different alternative ways to spell it down
|
|
90
|
-
* are used. We should normalize given path here, I guess, or on a higher
|
|
91
|
-
* level in the logic?
|
|
92
|
-
*/
|
|
93
|
-
hasChangedDependencies(path, deps) {
|
|
94
|
-
const prevDeps = this.#dependencies[path];
|
|
95
|
-
let changed = !prevDeps || prevDeps.length !== deps.length;
|
|
96
|
-
for (let i = 0; !changed && i < deps.length; ++i) {
|
|
97
|
-
changed = prevDeps[i] !== deps[i];
|
|
98
|
-
}
|
|
99
|
-
this.#dependencies[path] = Object.freeze(deps);
|
|
100
|
-
return changed;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Gets entire state, the same way as .get(null, opts) would do.
|
|
105
|
-
* @param opts.initialState
|
|
106
|
-
* @param opts.initialValue
|
|
107
|
-
*/
|
|
108
|
-
getEntireState(opts) {
|
|
109
|
-
let state = opts?.initialState ? this.#initialState : this.#currentState;
|
|
110
|
-
if (state !== undefined || opts?.initialValue === undefined) return state;
|
|
111
|
-
const iv = opts.initialValue;
|
|
112
|
-
state = (0, _isFunction.default)(iv) ? iv() : iv;
|
|
113
|
-
if (this.#currentState === undefined) this.setEntireState(state);
|
|
114
|
-
return state;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Notifies all connected state watchers that a state update has happened.
|
|
119
|
-
*/
|
|
120
|
-
notifyStateUpdate(path, value) {
|
|
121
|
-
if (process.env.NODE_ENV !== 'production' && (0, _utils.isDebugMode)()) {
|
|
122
|
-
/* eslint-disable no-console */
|
|
123
|
-
const p = typeof path === 'string' ? `"${path}"` : 'none (entire state update)';
|
|
124
|
-
console.groupCollapsed(`ReactGlobalState update. Path: ${p}`);
|
|
125
|
-
console.log('New value:', (0, _utils.cloneDeepForLog)(value, path ?? ''));
|
|
126
|
-
console.log('New state:', (0, _utils.cloneDeepForLog)(this.#currentState));
|
|
127
|
-
console.groupEnd();
|
|
128
|
-
/* eslint-enable no-console */
|
|
129
|
-
}
|
|
130
|
-
if (this.ssrContext) {
|
|
131
|
-
this.ssrContext.dirty = true;
|
|
132
|
-
this.ssrContext.state = this.#currentState;
|
|
133
|
-
} else if (!this.#nextNotifierId) {
|
|
134
|
-
this.#nextNotifierId = setTimeout(() => {
|
|
135
|
-
this.#nextNotifierId = undefined;
|
|
136
|
-
const watchers = [...this.#watchers];
|
|
137
|
-
for (const watcher of watchers) watcher();
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Registers an abort callback for an async data retrieval operation with
|
|
144
|
-
* the given operation ID. Throws if already registered.
|
|
145
|
-
*/
|
|
146
|
-
setAsyncDataAbortCallback(opid, cb) {
|
|
147
|
-
this.#asyncDataAbortCallbacks[opid] = cb;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Sets entire state, the same way as .set(null, value) would do.
|
|
152
|
-
* @param value
|
|
153
|
-
*/
|
|
154
|
-
setEntireState(value) {
|
|
155
|
-
if (this.#currentState !== value) {
|
|
156
|
-
this.#currentState = value;
|
|
157
|
-
this.notifyStateUpdate(null, value);
|
|
158
|
-
}
|
|
159
|
-
return value;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Gets current or initial value at the specified "path" of the global state.
|
|
164
|
-
* @param path Dot-delimitered state path.
|
|
165
|
-
* @param options Additional options.
|
|
166
|
-
* @param options.initialState If "true" the value will be read
|
|
167
|
-
* from the initial state instead of the current one.
|
|
168
|
-
* @param options.initialValue If the value read from the "path" is
|
|
169
|
-
* "undefined", this "initialValue" will be returned instead. In such case
|
|
170
|
-
* "initialValue" will also be written to the "path" of the current global
|
|
171
|
-
* state (no matter "initialState" flag), if "undefined" is stored there.
|
|
172
|
-
* @return Retrieved value.
|
|
173
|
-
*/
|
|
174
|
-
|
|
175
|
-
// .get() without arguments just falls back to .getEntireState().
|
|
176
|
-
|
|
177
|
-
// This variant attempts to automatically resolve and check the type of value
|
|
178
|
-
// at the given path, as precise as the actual state and path types permit.
|
|
179
|
-
// If the automatic path resolution is not possible, the ValueT fallsback
|
|
180
|
-
// to `never` (or to `undefined` in some cases), effectively forbidding
|
|
181
|
-
// to use this .get() variant.
|
|
182
|
-
|
|
183
|
-
// This variant is not callable by default (without generic arguments),
|
|
184
|
-
// otherwise it allows to set the correct ValueT directly.
|
|
185
|
-
|
|
186
|
-
get(path, opts) {
|
|
187
|
-
if ((0, _isNil.default)(path)) {
|
|
188
|
-
const res = this.getEntireState(opts);
|
|
189
|
-
return res;
|
|
190
|
-
}
|
|
191
|
-
const state = opts?.initialState ? this.#initialState : this.#currentState;
|
|
192
|
-
let res = (0, _get.default)(state, path);
|
|
193
|
-
if (res !== undefined || opts?.initialValue === undefined) return res;
|
|
194
|
-
const iv = opts.initialValue;
|
|
195
|
-
res = (0, _isFunction.default)(iv) ? iv() : iv;
|
|
196
|
-
|
|
197
|
-
// TODO: Revise.
|
|
198
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
199
|
-
if (!opts.initialState || this.get(path) === undefined) {
|
|
200
|
-
this.set(path, res);
|
|
201
|
-
}
|
|
202
|
-
return res;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Writes the `value` to given global state `path`.
|
|
207
|
-
* @param path Dot-delimitered state path. If not given, entire
|
|
208
|
-
* global state content is replaced by the `value`.
|
|
209
|
-
* @param value The value.
|
|
210
|
-
* @return Given `value` itself.
|
|
211
|
-
*/
|
|
212
|
-
|
|
213
|
-
// This variant attempts automatic value type resolution & checking.
|
|
214
|
-
|
|
215
|
-
// This variant is disabled by default, otherwise allows to give
|
|
216
|
-
// expected value type explicitly.
|
|
217
|
-
|
|
218
|
-
set(path, value) {
|
|
219
|
-
if ((0, _isNil.default)(path)) return this.setEntireState(value);
|
|
220
|
-
|
|
221
|
-
// TODO: Revise.
|
|
222
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
223
|
-
if (value !== this.get(path)) {
|
|
224
|
-
const root = {
|
|
225
|
-
state: this.#currentState
|
|
226
|
-
};
|
|
227
|
-
let segIdx = 0;
|
|
228
|
-
|
|
229
|
-
// TODO: It is not 100% correct, as `pos` can be an array, or any other
|
|
230
|
-
// value as we travel through the state tree. To simplify the typing for
|
|
231
|
-
// now, I guess, we can go with this record type, though.
|
|
232
|
-
let pos = root;
|
|
233
|
-
const pathSegments = (0, _toPath.default)(`state.${path}`);
|
|
234
|
-
for (; segIdx < pathSegments.length - 1; segIdx += 1) {
|
|
235
|
-
const seg = pathSegments[segIdx];
|
|
236
|
-
|
|
237
|
-
// TODO: Revise: Typing is not quite correct here, but it works fine in the runtime.
|
|
238
|
-
const next = pos[seg];
|
|
239
|
-
if (Array.isArray(next)) pos[seg] = [...next];else if ((0, _isObject.default)(next)) pos[seg] = {
|
|
240
|
-
...next
|
|
241
|
-
};else {
|
|
242
|
-
// We arrived to a state sub-segment, where the remaining part of
|
|
243
|
-
// the update path does not exist yet. We rely on lodash's set()
|
|
244
|
-
// function to create the remaining path, and set the value.
|
|
245
|
-
(0, _set.default)(pos, pathSegments.slice(segIdx), value);
|
|
246
|
-
break;
|
|
247
|
-
}
|
|
248
|
-
pos = pos[seg];
|
|
249
|
-
}
|
|
250
|
-
if (segIdx === pathSegments.length - 1) {
|
|
251
|
-
pos[pathSegments[segIdx]] = value;
|
|
252
|
-
}
|
|
253
|
-
this.#currentState = root.state;
|
|
254
|
-
this.notifyStateUpdate(path, value);
|
|
255
|
-
}
|
|
256
|
-
return value;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Unsubscribes `callback` from watching state updates; no operation if
|
|
261
|
-
* `callback` is not subscribed to the state updates.
|
|
262
|
-
* @param callback
|
|
263
|
-
* @throws if {@link SsrContext} is attached to the state instance: the state
|
|
264
|
-
* watching functionality is intended for client-side (non-SSR) only.
|
|
265
|
-
*/
|
|
266
|
-
unWatch(callback) {
|
|
267
|
-
if (this.ssrContext) throw new Error(ERR_NO_SSR_WATCH);
|
|
268
|
-
const watchers = this.#watchers;
|
|
269
|
-
const pos = watchers.indexOf(callback);
|
|
270
|
-
if (pos >= 0) {
|
|
271
|
-
watchers[pos] = watchers[watchers.length - 1];
|
|
272
|
-
watchers.pop();
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Subscribes `callback` to watch state updates; no operation if
|
|
278
|
-
* `callback` is already subscribed to this state instance.
|
|
279
|
-
* @param callback It will be called without any arguments every
|
|
280
|
-
* time the state content changes (note, howhever, separate state updates can
|
|
281
|
-
* be applied to the state at once, and watching callbacks will be called once
|
|
282
|
-
* after such bulk update).
|
|
283
|
-
* @throws if {@link SsrContext} is attached to the state instance: the state
|
|
284
|
-
* watching functionality is intended for client-side (non-SSR) only.
|
|
285
|
-
*/
|
|
286
|
-
watch(callback) {
|
|
287
|
-
if (this.ssrContext) throw new Error(ERR_NO_SSR_WATCH);
|
|
288
|
-
const watchers = this.#watchers;
|
|
289
|
-
if (!watchers.includes(callback)) {
|
|
290
|
-
watchers.push(callback);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
exports.default = GlobalState;
|
|
295
|
-
//# sourceMappingURL=GlobalState.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalState.js","names":["_get","_interopRequireDefault","require","_isFunction","_isObject","_isNil","_set","_toPath","_utils","ERR_NO_SSR_WATCH","GlobalState","asyncDataAbortCallbacks","dependencies","initialState","watchers","nextNotifierId","currentState","constructor","ssrContext","dirty","pending","state","process","env","NODE_ENV","isDebugMode","msg","console","groupCollapsed","log","cloneDeepForLog","groupEnd","numAsyncDataAbortCallbacks","Object","keys","length","asyncDataLoadDone","opid","aborted","dropDependencies","path","hasChangedDependencies","deps","prevDeps","changed","i","freeze","getEntireState","opts","undefined","initialValue","iv","isFunction","setEntireState","notifyStateUpdate","value","p","setTimeout","watcher","setAsyncDataAbortCallback","cb","get","isNil","res","set","root","segIdx","pos","pathSegments","toPath","seg","next","Array","isArray","isObject","slice","unWatch","callback","Error","indexOf","pop","watch","includes","push","exports","default"],"sources":["../../src/GlobalState.ts"],"sourcesContent":["import get from 'lodash/get.js';\nimport isFunction from 'lodash/isFunction.js';\nimport isObject from 'lodash/isObject.js';\nimport isNil from 'lodash/isNil.js';\nimport set from 'lodash/set.js';\nimport toPath from 'lodash/toPath.js';\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,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,SAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,IAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,OAAA,GAAAN,sBAAA,CAAAC,OAAA;AAIA,IAAAM,MAAA,GAAAN,OAAA;AAWA,MAAMO,gBAAgB,GAAG,gDAAgD;AAO1D,MAAMC,WAAW,CAG9B;EAGA,CAACC,uBAAuB,GAA+B,CAAC,CAAC;EAEzD,CAACC,YAAY,GAAuC,CAAC,CAAC;EAEtD,CAACC,YAAY;;EAEb;EACA;EACA;EACA;EACA,CAACC,QAAQ,GAAgB,EAAE;EAE3B,CAACC,cAAc;EAEf,CAACC,YAAY;;EAEb;AACF;AACA;AACA;AACA;EACEC,WAAWA,CACTJ,YAAoB,EACpBK,UAAwB,EACxB;IACA,IAAI,CAAC,CA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AM,IAAI4D,KAAK,CAACrE,gBAAgB,CAAC;IAEtD,MAAMK,QAAQ,GAAG,IAAI,CAAC,CAACA,QAAQ;IAC/B,MAAMqD,GAAG,GAAGrD,QAAQ,CAACiE,OAAO,CAACF,QAAQ,CAAC;IACtC,IAAIV,GAAG,IAAI,CAAC,EAAE;MACZrD,QAAQ,CAACqD,GAAG,CAAC,GAAGrD,QAAQ,CAACA,QAAQ,CAACqB,MAAM,GAAG,CAAC,CAAE;MAC9CrB,QAAQ,CAACkE,GAAG,CAAC,CAAC;IAChB;EACF;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,KAAKA,CAACJ,QAAmB,EAAQ;IAC/B,IAAI,IAAI,CAAC3D,UAAU,EAAE,MAAM,IAAI4D,KAAK,CAACrE,gBAAgB,CAAC;IAEtD,MAAMK,QAAQ,GAAG,IAAI,CAAC,CAACA,QAAQ;IAC/B,IAAI,CAACA,QAAQ,CAACoE,QAAQ,CAACL,QAAQ,CAAC,EAAE;MAChC/D,QAAQ,CAACqE,IAAI,CAACN,QAAQ,CAAC;IACzB;EACF;AACF;AAACO,OAAA,CAAAC,OAAA,GAAA3E,WAAA","ignoreList":[]}
|
|
@@ -1,100 +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
|
-
exports.getGlobalState = getGlobalState;
|
|
9
|
-
exports.getSsrContext = getSsrContext;
|
|
10
|
-
var _isFunction = _interopRequireDefault(require("lodash/isFunction.js"));
|
|
11
|
-
var _react = require("react");
|
|
12
|
-
var _GlobalState = _interopRequireDefault(require("./GlobalState"));
|
|
13
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
-
const Context = /*#__PURE__*/(0, _react.createContext)(null);
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Gets {@link GlobalState} instance from the context. In most cases
|
|
18
|
-
* you should use {@link useGlobalState}, and other hooks to interact with
|
|
19
|
-
* the global state, instead of accessing it directly.
|
|
20
|
-
* @return
|
|
21
|
-
*/
|
|
22
|
-
function getGlobalState() {
|
|
23
|
-
// TODO: Think about it: on one hand we on purpose called this function
|
|
24
|
-
// as getGlobalState(), so that ppl looking for the state hook prefer using
|
|
25
|
-
// useGlobalState(), while this getGlobalState() is reserved for nieche cases;
|
|
26
|
-
// on the other hand, perhaps we can rename it into useSomething, to both
|
|
27
|
-
// follow conventions, and to keep stuff clearly named at the same time.
|
|
28
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
29
|
-
const globalState = (0, _react.use)(Context);
|
|
30
|
-
if (!globalState) throw new Error('Missing GlobalStateProvider');
|
|
31
|
-
return globalState;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @category Hooks
|
|
36
|
-
* @desc Gets SSR context.
|
|
37
|
-
* @param throwWithoutSsrContext If `true` (default),
|
|
38
|
-
* this hook will throw if no SSR context is attached to the global state;
|
|
39
|
-
* set `false` to not throw in such case. In either case the hook will throw
|
|
40
|
-
* if the {@link <GlobalStateProvider>} (hence the state) is missing.
|
|
41
|
-
* @returns SSR context.
|
|
42
|
-
* @throws
|
|
43
|
-
* - If current component has no parent {@link <GlobalStateProvider>}
|
|
44
|
-
* in the rendered React tree.
|
|
45
|
-
* - If `throwWithoutSsrContext` is `true`, and there is no SSR context attached
|
|
46
|
-
* to the global state provided by {@link <GlobalStateProvider>}.
|
|
47
|
-
*/
|
|
48
|
-
function getSsrContext(throwWithoutSsrContext = true) {
|
|
49
|
-
const {
|
|
50
|
-
ssrContext
|
|
51
|
-
} = getGlobalState();
|
|
52
|
-
if (!ssrContext && throwWithoutSsrContext) {
|
|
53
|
-
throw new Error('No SSR context found');
|
|
54
|
-
}
|
|
55
|
-
return ssrContext;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Provides global state to its children.
|
|
59
|
-
* @param prop.children Component children, which will be provided with
|
|
60
|
-
* the global state, and rendered in place of the provider.
|
|
61
|
-
* @param prop.initialState Initial content of the global state.
|
|
62
|
-
* @param prop.ssrContext Server-side rendering (SSR) context.
|
|
63
|
-
* @param prop.stateProxy This option is useful for code
|
|
64
|
-
* splitting and SSR implementation:
|
|
65
|
-
* - If `true`, this provider instance will fetch and reuse the global state
|
|
66
|
-
* from a parent provider.
|
|
67
|
-
* - If `GlobalState` instance, it will be used by this provider.
|
|
68
|
-
* - If not given, a new `GlobalState` instance will be created and used.
|
|
69
|
-
*/
|
|
70
|
-
const GlobalStateProvider = ({
|
|
71
|
-
children,
|
|
72
|
-
...rest
|
|
73
|
-
}) => {
|
|
74
|
-
const [localState, setLocalState] = (0, _react.useState)();
|
|
75
|
-
let state;
|
|
76
|
-
|
|
77
|
-
// Below we cast `rest.stateProxy` as "boolean" for safe backward
|
|
78
|
-
// compatibility with plain JavaScript (as TypeScript typings only
|
|
79
|
-
// permit "true" or GlobalState value; while legacy codebase may
|
|
80
|
-
// pass in a boolean value here, occasionally equal "false").
|
|
81
|
-
if ('stateProxy' in rest && rest.stateProxy) {
|
|
82
|
-
if (localState) setLocalState(undefined);
|
|
83
|
-
state = rest.stateProxy === true ? getGlobalState() : rest.stateProxy;
|
|
84
|
-
} else if (localState) {
|
|
85
|
-
state = localState;
|
|
86
|
-
} else {
|
|
87
|
-
const {
|
|
88
|
-
initialState,
|
|
89
|
-
ssrContext
|
|
90
|
-
} = rest;
|
|
91
|
-
state = new _GlobalState.default((0, _isFunction.default)(initialState) ? initialState() : initialState, ssrContext);
|
|
92
|
-
setLocalState(state);
|
|
93
|
-
}
|
|
94
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Context, {
|
|
95
|
-
value: state,
|
|
96
|
-
children: children
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
var _default = exports.default = GlobalStateProvider;
|
|
100
|
-
//# sourceMappingURL=GlobalStateProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalStateProvider.js","names":["_isFunction","_interopRequireDefault","require","_react","_GlobalState","_jsxRuntime","Context","createContext","getGlobalState","globalState","use","Error","getSsrContext","throwWithoutSsrContext","ssrContext","GlobalStateProvider","children","rest","localState","setLocalState","useState","state","stateProxy","undefined","initialState","GlobalState","isFunction","jsx","value","_default","exports","default"],"sources":["../../src/GlobalStateProvider.tsx"],"sourcesContent":["import isFunction from 'lodash/isFunction.js';\n\nimport {\n type ReactNode,\n createContext,\n use,\n useState,\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\n const [localState, setLocalState] = useState<GST>();\n\n let state: GST;\n\n // Below we cast `rest.stateProxy` as \"boolean\" for safe backward\n // compatibility with plain JavaScript (as TypeScript typings only\n // permit \"true\" or GlobalState value; while legacy codebase may\n // pass in a boolean value here, occasionally equal \"false\").\n if ('stateProxy' in rest && (rest.stateProxy as boolean)) {\n if (localState) setLocalState(undefined);\n state = rest.stateProxy === true ? getGlobalState() : rest.stateProxy;\n } else if (localState) {\n state = localState;\n } else {\n const {\n initialState,\n ssrContext,\n } = rest as NewStateProps<StateT, SsrContextT>;\n\n state = new GlobalState(\n isFunction(initialState) ? initialState() : initialState,\n ssrContext,\n );\n\n setLocalState(state);\n }\n\n return <Context value={state}>{children}</Context>;\n};\n\nexport default GlobalStateProvider;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAOA,IAAAE,YAAA,GAAAH,sBAAA,CAAAC,OAAA;AAAwC,IAAAG,WAAA,GAAAH,OAAA;AAKxC,MAAMI,OAAO,gBAAG,IAAAC,oBAAa,EAA8B,IAAI,CAAC;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,cAAcA,CAAA,EAGQ;EACpC;EACA;EACA;EACA;EACA;EACA;EACA,MAAMC,WAAW,GAAG,IAAAC,UAAG,EAACJ,OAAO,CAAC;EAChC,IAAI,CAACG,WAAW,EAAE,MAAM,IAAIE,KAAK,CAAC,6BAA6B,CAAC;EAChE,OAAOF,WAAW;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,aAAaA,CAG3BC,sBAAsB,GAAG,IAAI,EACJ;EACzB,MAAM;IAAEC;EAAW,CAAC,GAAGN,cAAc,CAAoC,CAAC;EAC1E,IAAI,CAACM,UAAU,IAAID,sBAAsB,EAAE;IACzC,MAAM,IAAIF,KAAK,CAAC,sBAAsB,CAAC;EACzC;EACA,OAAOG,UAAU;AACnB;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mBAAmB,GAAGA,CAI1B;EAAEC,QAAQ;EAAE,GAAGC;AAAoD,CAAC,KACtD;EAGd,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAC,eAAQ,EAAM,CAAC;EAEnD,IAAIC,KAAU;;EAEd;EACA;EACA;EACA;EACA,IAAI,YAAY,IAAIJ,IAAI,IAAKA,IAAI,CAACK,UAAsB,EAAE;IACxD,IAAIJ,UAAU,EAAEC,aAAa,CAACI,SAAS,CAAC;IACxCF,KAAK,GAAGJ,IAAI,CAACK,UAAU,KAAK,IAAI,GAAGd,cAAc,CAAC,CAAC,GAAGS,IAAI,CAACK,UAAU;EACvE,CAAC,MAAM,IAAIJ,UAAU,EAAE;IACrBG,KAAK,GAAGH,UAAU;EACpB,CAAC,MAAM;IACL,MAAM;MACJM,YAAY;MACZV;IACF,CAAC,GAAGG,IAA0C;IAE9CI,KAAK,GAAG,IAAII,oBAAW,CACrB,IAAAC,mBAAU,EAACF,YAAY,CAAC,GAAGA,YAAY,CAAC,CAAC,GAAGA,YAAY,EACxDV,UACF,CAAC;IAEDK,aAAa,CAACE,KAAK,CAAC;EACtB;EAEA,oBAAO,IAAAhB,WAAA,CAAAsB,GAAA,EAACrB,OAAO;IAACsB,KAAK,EAAEP,KAAM;IAAAL,QAAA,EAAEA;EAAQ,CAAU,CAAC;AACpD,CAAC;AAAC,IAAAa,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEahB,mBAAmB","ignoreList":[]}
|
package/build/cjs/SsrContext.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
class SsrContext {
|
|
8
|
-
dirty = false;
|
|
9
|
-
pending = [];
|
|
10
|
-
constructor(state) {
|
|
11
|
-
this.state = state;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.default = SsrContext;
|
|
15
|
-
//# sourceMappingURL=SsrContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SsrContext.js","names":["SsrContext","dirty","pending","constructor","state","exports","default"],"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":";;;;;;AAAe,MAAMA,UAAU,CAAS;EACtCC,KAAK,GAAY,KAAK;EAEtBC,OAAO,GAAyB,EAAE;EAElCC,WAAWA,CAAQC,KAAc,EAAE;IAAA,KAAhBA,KAAc,GAAdA,KAAc;EAAI;AACvC;AAACC,OAAA,CAAAC,OAAA,GAAAN,UAAA","ignoreList":[]}
|
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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