@dr.pogodin/react-global-state 0.9.3 → 0.10.0-alpha.2

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.
Files changed (55) hide show
  1. package/README.md +3 -328
  2. package/build/GlobalState.d.ts +75 -0
  3. package/build/GlobalState.js +193 -0
  4. package/build/GlobalStateProvider.d.ts +55 -0
  5. package/build/GlobalStateProvider.js +103 -0
  6. package/build/SsrContext.d.ts +6 -0
  7. package/build/SsrContext.js +10 -0
  8. package/build/index.d.ts +8 -0
  9. package/build/index.js +23 -0
  10. package/build/{module/useAsyncCollection.js → useAsyncCollection.d.ts} +16 -23
  11. package/build/useAsyncCollection.js +14 -0
  12. package/build/useAsyncData.d.ts +76 -0
  13. package/build/useAsyncData.js +150 -0
  14. package/build/{module/useGlobalState.js → useGlobalState.d.ts} +11 -62
  15. package/build/useGlobalState.js +49 -0
  16. package/build/utils.d.ts +31 -0
  17. package/build/{node/utils.js → utils.js} +11 -17
  18. package/build/withGlobalStateType.d.ts +39 -0
  19. package/build/withGlobalStateType.js +55 -0
  20. package/package.json +48 -27
  21. package/src/GlobalState.ts +279 -0
  22. package/src/GlobalStateProvider.tsx +116 -0
  23. package/src/SsrContext.ts +11 -0
  24. package/src/index.ts +33 -0
  25. package/{build/node/useAsyncCollection.js → src/useAsyncCollection.ts} +58 -25
  26. package/src/useAsyncData.ts +287 -0
  27. package/src/useGlobalState.ts +158 -0
  28. package/src/utils.ts +59 -0
  29. package/src/withGlobalStateType.ts +118 -0
  30. package/tsconfig.json +9 -0
  31. package/build/module/GlobalState.js +0 -191
  32. package/build/module/GlobalState.js.map +0 -1
  33. package/build/module/GlobalStateProvider.js +0 -81
  34. package/build/module/GlobalStateProvider.js.map +0 -1
  35. package/build/module/index.js +0 -12
  36. package/build/module/index.js.map +0 -1
  37. package/build/module/useAsyncCollection.js.map +0 -1
  38. package/build/module/useAsyncData.js +0 -206
  39. package/build/module/useAsyncData.js.map +0 -1
  40. package/build/module/useGlobalState.js.map +0 -1
  41. package/build/module/utils.js +0 -23
  42. package/build/module/utils.js.map +0 -1
  43. package/build/node/GlobalState.js +0 -174
  44. package/build/node/GlobalState.js.map +0 -1
  45. package/build/node/GlobalStateProvider.js +0 -88
  46. package/build/node/GlobalStateProvider.js.map +0 -1
  47. package/build/node/index.js +0 -56
  48. package/build/node/index.js.map +0 -1
  49. package/build/node/useAsyncCollection.js.map +0 -1
  50. package/build/node/useAsyncData.js +0 -211
  51. package/build/node/useAsyncData.js.map +0 -1
  52. package/build/node/useGlobalState.js +0 -114
  53. package/build/node/useGlobalState.js.map +0 -1
  54. package/build/node/utils.js.map +0 -1
  55. package/index.d.ts +0 -70
@@ -0,0 +1,118 @@
1
+ import {
2
+ type TypeLock,
3
+ type ValueAtPathT,
4
+ type ValueOrInitializerT,
5
+ } from './utils';
6
+
7
+ import GlobalStateProvider, {
8
+ getGlobalState,
9
+ getSsrContext,
10
+ } from './GlobalStateProvider';
11
+
12
+ import SsrContext from './SsrContext';
13
+
14
+ import useGlobalState, {
15
+ type UseGlobalStateResT,
16
+ } from './useGlobalState';
17
+
18
+ import useAsyncCollection, {
19
+ type AsyncCollectionLoaderT,
20
+ } from './useAsyncCollection';
21
+
22
+ import useAsyncData, {
23
+ type AsyncDataLoaderT,
24
+ type DataInEnvelopeAtPathT,
25
+ type UseAsyncDataOptionsT,
26
+ type UseAsyncDataResT,
27
+ } from './useAsyncData';
28
+
29
+ export default function withGlobalStateType<StateT>() {
30
+ // These wrap useGlobalState() with locked-in StateT type.
31
+
32
+ function useGlobalStateWrap(): UseGlobalStateResT<StateT>;
33
+
34
+ function useGlobalStateWrap<PathT extends null | string | undefined>(
35
+ path: PathT,
36
+ initialValue?: ValueOrInitializerT<ValueAtPathT<StateT, PathT, never>>,
37
+ ): UseGlobalStateResT<ValueAtPathT<StateT, PathT, void>>;
38
+
39
+ function useGlobalStateWrap<
40
+ Unlocked extends 0 | 1 = 0,
41
+ ValueT = void,
42
+ >(
43
+ path: null | string | undefined,
44
+ initialValue?: ValueOrInitializerT<TypeLock<Unlocked, never, ValueT>>,
45
+ ): UseGlobalStateResT<TypeLock<Unlocked, void, ValueT>>;
46
+
47
+ function useGlobalStateWrap(
48
+ path?: null | string,
49
+ initialValue?: ValueOrInitializerT<unknown>,
50
+ ): UseGlobalStateResT<any> {
51
+ return useGlobalState<1, unknown>(path, initialValue);
52
+ }
53
+
54
+ // These overloads & implementation wrap useAsyncData() hook to lock-in its
55
+ // underlying StateT.
56
+
57
+ function useAsyncDataWrap<PathT extends null | string | undefined>(
58
+ path: PathT,
59
+ loader: AsyncDataLoaderT<DataInEnvelopeAtPathT<StateT, PathT>>,
60
+ options?: UseAsyncDataOptionsT,
61
+ ): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, PathT>>;
62
+
63
+ function useAsyncDataWrap<
64
+ Unlocked extends 0 | 1 = 0,
65
+ DataT = unknown,
66
+ >(
67
+ path: null | string | undefined,
68
+ loader: AsyncDataLoaderT<TypeLock<Unlocked, void, DataT>>,
69
+ options?: UseAsyncDataOptionsT,
70
+ ): UseAsyncDataResT<TypeLock<Unlocked, never, DataT>>;
71
+
72
+ function useAsyncDataWrap<DataT>(
73
+ path: null | string | undefined,
74
+ loader: AsyncDataLoaderT<DataT>,
75
+ options: UseAsyncDataOptionsT = {},
76
+ ): UseAsyncDataResT<DataT> {
77
+ return useAsyncData<1, DataT>(path, loader, options);
78
+ }
79
+
80
+ // These overloads & implementation wrap useAsyncCollection() hook to lock-in
81
+ // its underlying StateT.
82
+
83
+ function useAsyncCollectionWrap<PathT extends null | string | undefined>(
84
+ id: string,
85
+ path: PathT,
86
+ loader: AsyncCollectionLoaderT<DataInEnvelopeAtPathT<StateT, PathT>>,
87
+ options?: UseAsyncDataOptionsT,
88
+ ): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, PathT>>;
89
+
90
+ function useAsyncCollectionWrap<
91
+ Unlocked extends 0 | 1 = 0,
92
+ DataT = unknown,
93
+ >(
94
+ id: string,
95
+ path: null | string | undefined,
96
+ loader: AsyncCollectionLoaderT<TypeLock<Unlocked, void, DataT>>,
97
+ options?: UseAsyncDataOptionsT,
98
+ ): UseAsyncDataResT<DataT>;
99
+
100
+ function useAsyncCollectionWrap<DataT>(
101
+ id: string,
102
+ path: null | string | undefined,
103
+ loader: AsyncCollectionLoaderT<DataT>,
104
+ options: UseAsyncDataOptionsT = {},
105
+ ): UseAsyncDataResT<DataT> {
106
+ return useAsyncCollection<1, DataT>(id, path, loader, options);
107
+ }
108
+
109
+ return {
110
+ getGlobalState: getGlobalState<StateT>,
111
+ getSsrContext: getSsrContext<StateT>,
112
+ GlobalStateProvider: GlobalStateProvider<StateT>,
113
+ SsrContext: SsrContext<StateT>,
114
+ useAsyncCollection: useAsyncCollectionWrap,
115
+ useAsyncData: useAsyncDataWrap,
116
+ useGlobalState: useGlobalStateWrap,
117
+ };
118
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@tsconfig/recommended",
3
+ "include": ["src/**/*"],
4
+ "compilerOptions": {
5
+ "declaration": true,
6
+ "jsx": "react-jsx",
7
+ "outDir": "build"
8
+ }
9
+ }
@@ -1,191 +0,0 @@
1
- import _classPrivateFieldGet from "@babel/runtime/helpers/classPrivateFieldGet";
2
- import _classPrivateFieldSet from "@babel/runtime/helpers/classPrivateFieldSet";
3
- function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
4
- function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
5
- import { cloneDeep, get, isFunction, isObject, isNil, set, toPath } from 'lodash';
6
- import { isDebugMode } from "./utils";
7
- const ERR_NO_SSR_WATCH = 'GlobalState must not be watched at server side';
8
- var _initialState = /*#__PURE__*/new WeakMap();
9
- var _nextNotifierId = /*#__PURE__*/new WeakMap();
10
- var _ssrContext = /*#__PURE__*/new WeakMap();
11
- var _currentState = /*#__PURE__*/new WeakMap();
12
- var _watchers = /*#__PURE__*/new WeakMap();
13
- export default class GlobalState {
14
- /**
15
- * Creates a new global state object.
16
- * @param {any} [initialState] Intial global state content.
17
- * @param {SsrContext} [ssrContext] Server-side rendering context.
18
- */
19
- constructor(initialState, ssrContext) {
20
- _classPrivateFieldInitSpec(this, _initialState, {
21
- writable: true,
22
- value: void 0
23
- });
24
- _classPrivateFieldInitSpec(this, _nextNotifierId, {
25
- writable: true,
26
- value: null
27
- });
28
- _classPrivateFieldInitSpec(this, _ssrContext, {
29
- writable: true,
30
- value: void 0
31
- });
32
- _classPrivateFieldInitSpec(this, _currentState, {
33
- writable: true,
34
- value: void 0
35
- });
36
- _classPrivateFieldInitSpec(this, _watchers, {
37
- writable: true,
38
- value: []
39
- });
40
- _classPrivateFieldSet(this, _currentState, initialState);
41
- _classPrivateFieldSet(this, _initialState, initialState);
42
- if (ssrContext) {
43
- /* eslint-disable no-param-reassign */
44
- ssrContext.dirty = false;
45
- ssrContext.pending = [];
46
- ssrContext.state = _classPrivateFieldGet(this, _currentState);
47
- /* eslint-enable no-param-reassign */
48
-
49
- _classPrivateFieldSet(this, _ssrContext, ssrContext);
50
- }
51
- if (process.env.NODE_ENV !== 'production' && isDebugMode()) {
52
- /* eslint-disable no-console */
53
- let msg = 'New ReactGlobalState created';
54
- if (ssrContext) msg += ' (SSR mode)';
55
- console.groupCollapsed(msg);
56
- console.log('Initial state:', cloneDeep(initialState));
57
- console.groupEnd();
58
- /* eslint-enable no-console */
59
- }
60
- }
61
-
62
- /**
63
- * Gets current or initial value at the specified "path" of the global state.
64
- * Allows to get the entire global state, and automatically set default value
65
- * at the "path".
66
- * @param {string} [path] Dot-delimitered state path. Pass it "null",
67
- * or "undefined" to refer the entire global state.
68
- * @param {object} [options={}] Additional options.
69
- * @param {boolean} [options.initialState] If "true" the value will be read
70
- * from the initial state instead of the current one.
71
- * @param {any} [options.initialValue] If the value read from the "path" is
72
- * "undefined", this "initialValue" will be returned instead. In such case
73
- * "initialValue" will also be written to the "path" of the current global
74
- * state (no matter "initialState" flag), if "undefined" is stored there.
75
- * @return {any} Retrieved value.
76
- */
77
- get(path) {
78
- let {
79
- initialState,
80
- initialValue
81
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
82
- const state = initialState ? _classPrivateFieldGet(this, _initialState) : _classPrivateFieldGet(this, _currentState);
83
- let value = isNil(path) ? state : get(state, path);
84
- if (value === undefined && initialValue !== undefined) {
85
- value = isFunction(initialValue) ? initialValue() : initialValue;
86
- if (!initialState || this.get(path) === undefined) this.set(path, value);
87
- }
88
- return value;
89
- }
90
-
91
- /**
92
- * Writes the `value` to given global state `path`.
93
- * @param {string} [path] Dot-delimitered state path. If not given, entire
94
- * global state content is replaced by the `value`.
95
- * @param {any} value The value.
96
- * @return {any} Given `value` itself.
97
- */
98
- set(path, value) {
99
- if (value !== this.get(path)) {
100
- if (process.env.NODE_ENV !== 'production' && isDebugMode()) {
101
- /* eslint-disable no-console */
102
- console.groupCollapsed(`ReactGlobalState update. Path: "${path || ''}"`);
103
- console.log('New value:', cloneDeep(value));
104
- /* eslint-enable no-console */
105
- }
106
-
107
- if (isNil(path)) _classPrivateFieldSet(this, _currentState, value);else {
108
- const root = {
109
- state: _classPrivateFieldGet(this, _currentState)
110
- };
111
- let segIdx = 0;
112
- let pos = root;
113
- const pathSegments = toPath(`state.${path}`);
114
- for (; segIdx < pathSegments.length - 1; segIdx += 1) {
115
- const seg = pathSegments[segIdx];
116
- const next = pos[seg];
117
- if (Array.isArray(next)) pos[seg] = [...next];else if (isObject(next)) pos[seg] = {
118
- ...next
119
- };else {
120
- // We arrived to a state sub-segment, where the remaining part of
121
- // the update path does not exist yet. We rely on lodash's set()
122
- // function to create the remaining path, and set the value.
123
- set(pos, pathSegments.slice(segIdx), value);
124
- break;
125
- }
126
- pos = pos[seg];
127
- }
128
- if (segIdx === pathSegments.length - 1) {
129
- pos[pathSegments[segIdx]] = value;
130
- }
131
- _classPrivateFieldSet(this, _currentState, root.state);
132
- }
133
- if (_classPrivateFieldGet(this, _ssrContext)) {
134
- _classPrivateFieldGet(this, _ssrContext).dirty = true;
135
- _classPrivateFieldGet(this, _ssrContext).state = _classPrivateFieldGet(this, _currentState);
136
- } else if (!_classPrivateFieldGet(this, _nextNotifierId)) {
137
- _classPrivateFieldSet(this, _nextNotifierId, setTimeout(() => {
138
- _classPrivateFieldSet(this, _nextNotifierId, null);
139
- [..._classPrivateFieldGet(this, _watchers)].forEach(w => w());
140
- }));
141
- }
142
- if (process.env.NODE_ENV !== 'production' && isDebugMode()) {
143
- /* eslint-disable no-console */
144
- console.log('New state:', cloneDeep(_classPrivateFieldGet(this, _currentState)));
145
- console.groupEnd();
146
- /* eslint-enable no-console */
147
- }
148
- }
149
-
150
- return value;
151
- }
152
-
153
- /**
154
- * Unsubscribes `callback` from watching state updates; no operation if
155
- * `callback` is not subscribed to the state updates.
156
- * @param {function} callback
157
- * @throws if {@link SsrContext} is attached to the state instance: the state
158
- * watching functionality is intended for client-side (non-SSR) only.
159
- */
160
- unWatch(callback) {
161
- if (_classPrivateFieldGet(this, _ssrContext)) throw new Error(ERR_NO_SSR_WATCH);
162
- const watchers = _classPrivateFieldGet(this, _watchers);
163
- const pos = watchers.indexOf(callback);
164
- if (pos >= 0) {
165
- watchers[pos] = watchers[watchers.length - 1];
166
- watchers.pop();
167
- }
168
- }
169
- get ssrContext() {
170
- return _classPrivateFieldGet(this, _ssrContext);
171
- }
172
-
173
- /**
174
- * Subscribes `callback` to watch state updates; no operation if
175
- * `callback` is already subscribed to this state instance.
176
- * @param {function} callback It will be called without any arguments every
177
- * time the state content changes (note, howhever, separate state updates can
178
- * be applied to the state at once, and watching callbacks will be called once
179
- * after such bulk update).
180
- * @throws if {@link SsrContext} is attached to the state instance: the state
181
- * watching functionality is intended for client-side (non-SSR) only.
182
- */
183
- watch(callback) {
184
- if (_classPrivateFieldGet(this, _ssrContext)) throw new Error(ERR_NO_SSR_WATCH);
185
- const watchers = _classPrivateFieldGet(this, _watchers);
186
- if (watchers.indexOf(callback) < 0) {
187
- watchers.push(callback);
188
- }
189
- }
190
- }
191
- //# sourceMappingURL=GlobalState.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"GlobalState.js","names":["cloneDeep","get","isFunction","isObject","isNil","set","toPath","isDebugMode","ERR_NO_SSR_WATCH","_initialState","WeakMap","_nextNotifierId","_ssrContext","_currentState","_watchers","GlobalState","constructor","initialState","ssrContext","_classPrivateFieldInitSpec","writable","value","_classPrivateFieldSet","dirty","pending","state","_classPrivateFieldGet","process","env","NODE_ENV","msg","console","groupCollapsed","log","groupEnd","path","initialValue","arguments","length","undefined","root","segIdx","pos","pathSegments","seg","next","Array","isArray","slice","setTimeout","forEach","w","unWatch","callback","Error","watchers","indexOf","pop","watch","push"],"sources":["../../src/GlobalState.js"],"sourcesContent":["import {\n cloneDeep,\n get,\n isFunction,\n isObject,\n isNil,\n set,\n toPath,\n} from 'lodash';\n\nimport { isDebugMode } from './utils';\n\nconst ERR_NO_SSR_WATCH = 'GlobalState must not be watched at server side';\n\nexport default class GlobalState {\n #initialState;\n\n #nextNotifierId = null;\n\n #ssrContext;\n\n #currentState;\n\n #watchers = [];\n\n /**\n * Creates a new global state object.\n * @param {any} [initialState] Intial global state content.\n * @param {SsrContext} [ssrContext] Server-side rendering context.\n */\n constructor(initialState, ssrContext) {\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:', cloneDeep(initialState));\n console.groupEnd();\n /* eslint-enable no-console */\n }\n }\n\n /**\n * Gets current or initial value at the specified \"path\" of the global state.\n * Allows to get the entire global state, and automatically set default value\n * at the \"path\".\n * @param {string} [path] Dot-delimitered state path. Pass it \"null\",\n * or \"undefined\" to refer the entire global state.\n * @param {object} [options={}] Additional options.\n * @param {boolean} [options.initialState] If \"true\" the value will be read\n * from the initial state instead of the current one.\n * @param {any} [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 {any} Retrieved value.\n */\n get(path, { initialState, initialValue } = {}) {\n const state = initialState ? this.#initialState : this.#currentState;\n let value = isNil(path) ? state : get(state, path);\n if (value === undefined && initialValue !== undefined) {\n value = isFunction(initialValue) ? initialValue() : initialValue;\n if (!initialState || this.get(path) === undefined) this.set(path, value);\n }\n return value;\n }\n\n /**\n * Writes the `value` to given global state `path`.\n * @param {string} [path] Dot-delimitered state path. If not given, entire\n * global state content is replaced by the `value`.\n * @param {any} value The value.\n * @return {any} Given `value` itself.\n */\n set(path, value) {\n if (value !== this.get(path)) {\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.groupCollapsed(\n `ReactGlobalState update. Path: \"${path || ''}\"`,\n );\n console.log('New value:', cloneDeep(value));\n /* eslint-enable no-console */\n }\n\n if (isNil(path)) this.#currentState = value;\n else {\n const root = { state: this.#currentState };\n let segIdx = 0;\n let pos = root;\n const pathSegments = toPath(`state.${path}`);\n for (; segIdx < pathSegments.length - 1; segIdx += 1) {\n const seg = pathSegments[segIdx];\n const next = pos[seg];\n if (Array.isArray(next)) pos[seg] = [...next];\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];\n }\n\n if (segIdx === pathSegments.length - 1) {\n pos[pathSegments[segIdx]] = value;\n }\n\n this.#currentState = root.state;\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 = null;\n [...this.#watchers].forEach((w) => w());\n });\n }\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.log('New state:', cloneDeep(this.#currentState));\n console.groupEnd();\n /* eslint-enable no-console */\n }\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 {function} 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) {\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 get ssrContext() { return this.#ssrContext; }\n\n /**\n * Subscribes `callback` to watch state updates; no operation if\n * `callback` is already subscribed to this state instance.\n * @param {function} 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) {\n if (this.#ssrContext) throw new Error(ERR_NO_SSR_WATCH);\n\n const watchers = this.#watchers;\n if (watchers.indexOf(callback) < 0) {\n watchers.push(callback);\n }\n }\n}\n"],"mappings":";;;;AAAA,SACEA,SAAS,EACTC,GAAG,EACHC,UAAU,EACVC,QAAQ,EACRC,KAAK,EACLC,GAAG,EACHC,MAAM,QACD,QAAQ;AAEf,SAASC,WAAW;AAEpB,MAAMC,gBAAgB,GAAG,gDAAgD;AAAC,IAAAC,aAAA,oBAAAC,OAAA;AAAA,IAAAC,eAAA,oB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AACA;AACA;AACA;EACE8C,KAAKA,CAACL,QAAQ,EAAE;IACd,IAAA3B,qBAAA,CAAI,IAAI,EAAAd,WAAA,GAAc,MAAM,IAAI0C,KAAK,CAAC9C,gBAAgB,CAAC;IAEvD,MAAM+C,QAAQ,GAAA7B,qBAAA,CAAG,IAAI,EAAAZ,SAAA,CAAU;IAC/B,IAAIyC,QAAQ,CAACC,OAAO,CAACH,QAAQ,CAAC,GAAG,CAAC,EAAE;MAClCE,QAAQ,CAACI,IAAI,CAACN,QAAQ,CAAC;IACzB;EACF;AACF"}
@@ -1,81 +0,0 @@
1
- /* eslint-disable react/prop-types */
2
-
3
- import { createContext, useContext, useRef } from 'react';
4
- import GlobalState from "./GlobalState";
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
- const context = /*#__PURE__*/createContext();
7
-
8
- /**
9
- * Gets {@link GlobalState} instance from the context. In most cases
10
- * you should use {@link useGlobalState}, and other hooks to interact with
11
- * the global state, instead of accessing it directly.
12
- * @return {GlobalState}
13
- */
14
- export function getGlobalState() {
15
- // Here Rules of Hooks are violated because "getGlobalState()" does not follow
16
- // convention that hook names should start with use... This is intentional in
17
- // our case, as getGlobalState() hook is intended for advance scenarious,
18
- // while the normal interaction with the global state should happen via
19
- // another hook, useGlobalState().
20
- /* eslint-disable react-hooks/rules-of-hooks */
21
- const globalState = useContext(context);
22
- /* eslint-enable react-hooks/rules-of-hooks */
23
- if (!globalState) throw new Error('Missing GlobalStateProvider');
24
- return globalState;
25
- }
26
-
27
- /**
28
- * @category Hooks
29
- * @desc Gets SSR context.
30
- * @param {boolean} [throwWithoutSsrContext=true] If `true` (default),
31
- * this hook will throw if no SSR context is attached to the global state;
32
- * set `false` to not throw in such case. In either case the hook will throw
33
- * if the {@link &lt;GlobalStateProvider&gt;} (hence the state) is missing.
34
- * @returns {SsrContext} SSR context.
35
- * @throws
36
- * - If current component has no parent {@link &lt;GlobalStateProvider&gt;}
37
- * in the rendered React tree.
38
- * - If `throwWithoutSsrContext` is `true`, and there is no SSR context attached
39
- * to the global state provided by {@link &lt;GlobalStateProvider&gt;}.
40
- */
41
- export function getSsrContext() {
42
- let throwWithoutSsrContext = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
43
- const {
44
- ssrContext
45
- } = getGlobalState();
46
- if (!ssrContext && throwWithoutSsrContext) {
47
- throw new Error('No SSR context found');
48
- }
49
- return ssrContext;
50
- }
51
-
52
- /**
53
- * Provides global state to its children.
54
- * @prop {ReactNode} [children] Component children, which will be provided with
55
- * the global state, and rendered in place of the provider.
56
- * @prop {any} [initialState] Initial content of the global state.
57
- * @prop {SsrContext} [ssrContext] Server-side rendering (SSR) context.
58
- * @prop {boolean|GlobalState} [stateProxy] This option is useful for code
59
- * splitting and SSR implementation:
60
- * - If `true`, this provider instance will fetch and reuse the global state
61
- * from a parent provider.
62
- * - If `GlobalState` instance, it will be used by this provider.
63
- * - If not given, a new `GlobalState` instance will be created and used.
64
- */
65
- export default function GlobalStateProvider(_ref) {
66
- let {
67
- children,
68
- initialState,
69
- ssrContext,
70
- stateProxy
71
- } = _ref;
72
- const state = useRef();
73
- if (!state.current) {
74
- if (stateProxy instanceof GlobalState) state.current = stateProxy;else if (stateProxy) state.current = getGlobalState();else state.current = new GlobalState(initialState, ssrContext);
75
- }
76
- return /*#__PURE__*/_jsx(context.Provider, {
77
- value: state.current,
78
- children: children
79
- });
80
- }
81
- //# sourceMappingURL=GlobalStateProvider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"GlobalStateProvider.js","names":["createContext","useContext","useRef","GlobalState","jsx","_jsx","context","getGlobalState","globalState","Error","getSsrContext","throwWithoutSsrContext","arguments","length","undefined","ssrContext","GlobalStateProvider","_ref","children","initialState","stateProxy","state","current","Provider","value"],"sources":["../../src/GlobalStateProvider.jsx"],"sourcesContent":["/* eslint-disable react/prop-types */\n\nimport { createContext, useContext, useRef } from 'react';\n\nimport GlobalState from './GlobalState';\n\nconst context = createContext();\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 {GlobalState}\n */\nexport function getGlobalState() {\n // Here Rules of Hooks are violated because \"getGlobalState()\" does not follow\n // convention that hook names should start with use... This is intentional in\n // our case, as getGlobalState() hook is intended for advance scenarious,\n // while the normal interaction with the global state should happen via\n // another hook, useGlobalState().\n /* eslint-disable react-hooks/rules-of-hooks */\n const globalState = useContext(context);\n /* eslint-enable react-hooks/rules-of-hooks */\n if (!globalState) throw new Error('Missing GlobalStateProvider');\n return globalState;\n}\n\n/**\n * @category Hooks\n * @desc Gets SSR context.\n * @param {boolean} [throwWithoutSsrContext=true] 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 &lt;GlobalStateProvider&gt;} (hence the state) is missing.\n * @returns {SsrContext} SSR context.\n * @throws\n * - If current component has no parent {@link &lt;GlobalStateProvider&gt;}\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 &lt;GlobalStateProvider&gt;}.\n */\nexport function getSsrContext(throwWithoutSsrContext = true) {\n const { ssrContext } = getGlobalState();\n if (!ssrContext && throwWithoutSsrContext) {\n throw new Error('No SSR context found');\n }\n return ssrContext;\n}\n\n/**\n * Provides global state to its children.\n * @prop {ReactNode} [children] Component children, which will be provided with\n * the global state, and rendered in place of the provider.\n * @prop {any} [initialState] Initial content of the global state.\n * @prop {SsrContext} [ssrContext] Server-side rendering (SSR) context.\n * @prop {boolean|GlobalState} [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 */\nexport default function GlobalStateProvider({\n children,\n initialState,\n ssrContext,\n stateProxy,\n}) {\n const state = useRef();\n if (!state.current) {\n if (stateProxy instanceof GlobalState) state.current = stateProxy;\n else if (stateProxy) state.current = getGlobalState();\n else state.current = new GlobalState(initialState, ssrContext);\n }\n return (\n <context.Provider value={state.current}>\n {children}\n </context.Provider>\n );\n}\n"],"mappings":"AAAA;;AAEA,SAASA,aAAa,EAAEC,UAAU,EAAEC,MAAM,QAAQ,OAAO;AAEzD,OAAOC,WAAW;AAAsB,SAAAC,GAAA,IAAAC,IAAA;AAExC,MAAMC,OAAO,gBAAGN,aAAa,EAAE;;AAE/B;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASO,cAAcA,CAAA,EAAG;EAC/B;EACA;EACA;EACA;EACA;EACA;EACA,MAAMC,WAAW,GAAGP,UAAU,CAACK,OAAO,CAAC;EACvC;EACA,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,EAAgC;EAAA,IAA/BC,sBAAsB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;EACzD,MAAM;IAAEG;EAAW,CAAC,GAAGR,cAAc,EAAE;EACvC,IAAI,CAACQ,UAAU,IAAIJ,sBAAsB,EAAE;IACzC,MAAM,IAAIF,KAAK,CAAC,sBAAsB,CAAC;EACzC;EACA,OAAOM,UAAU;AACnB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,mBAAmBA,CAAAC,IAAA,EAKxC;EAAA,IALyC;IAC1CC,QAAQ;IACRC,YAAY;IACZJ,UAAU;IACVK;EACF,CAAC,GAAAH,IAAA;EACC,MAAMI,KAAK,GAAGnB,MAAM,EAAE;EACtB,IAAI,CAACmB,KAAK,CAACC,OAAO,EAAE;IAClB,IAAIF,UAAU,YAAYjB,WAAW,EAAEkB,KAAK,CAACC,OAAO,GAAGF,UAAU,CAAC,KAC7D,IAAIA,UAAU,EAAEC,KAAK,CAACC,OAAO,GAAGf,cAAc,EAAE,CAAC,KACjDc,KAAK,CAACC,OAAO,GAAG,IAAInB,WAAW,CAACgB,YAAY,EAAEJ,UAAU,CAAC;EAChE;EACA,oBACEV,IAAA,CAACC,OAAO,CAACiB,QAAQ;IAACC,KAAK,EAAEH,KAAK,CAACC,OAAQ;IAAAJ,QAAA,EACpCA;EAAQ,EACQ;AAEvB"}
@@ -1,12 +0,0 @@
1
- // TODO: This is a temporary polyfill for `Promise.allSettled(..)` method,
2
- // which is supported natively by NodeJS >= v12.9.0. As earlier NodeJS version
3
- // are still in a wide use, this polyfill is added here, and it is to be dropped
4
- // some time later.
5
- if (!Promise.allSettled) {
6
- Promise.allSettled = promises => Promise.all(promises.map(p => p instanceof Promise ? p.finally(() => null) : p));
7
- }
8
- export { default as GlobalStateProvider, getGlobalState, getSsrContext } from "./GlobalStateProvider";
9
- export { default as useAsyncCollection } from "./useAsyncCollection";
10
- export { default as useAsyncData } from "./useAsyncData";
11
- export { default as useGlobalState } from "./useGlobalState";
12
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["Promise","allSettled","promises","all","map","p","finally","default","GlobalStateProvider","getGlobalState","getSsrContext","useAsyncCollection","useAsyncData","useGlobalState"],"sources":["../../src/index.js"],"sourcesContent":["// TODO: This is a temporary polyfill for `Promise.allSettled(..)` method,\n// which is supported natively by NodeJS >= v12.9.0. As earlier NodeJS version\n// are still in a wide use, this polyfill is added here, and it is to be dropped\n// some time later.\nif (!Promise.allSettled) {\n Promise.allSettled = (promises) => Promise.all(\n promises.map((p) => (p instanceof Promise ? p.finally(() => null) : p)),\n );\n}\n\nexport {\n default as GlobalStateProvider,\n getGlobalState,\n getSsrContext,\n} from './GlobalStateProvider';\n\nexport { default as useAsyncCollection } from './useAsyncCollection';\nexport { default as useAsyncData } from './useAsyncData';\nexport { default as useGlobalState } from './useGlobalState';\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA,IAAI,CAACA,OAAO,CAACC,UAAU,EAAE;EACvBD,OAAO,CAACC,UAAU,GAAIC,QAAQ,IAAKF,OAAO,CAACG,GAAG,CAC5CD,QAAQ,CAACE,GAAG,CAAEC,CAAC,IAAMA,CAAC,YAAYL,OAAO,GAAGK,CAAC,CAACC,OAAO,CAAC,MAAM,IAAI,CAAC,GAAGD,CAAE,CAAC,CACxE;AACH;AAEA,SACEE,OAAO,IAAIC,mBAAmB,EAC9BC,cAAc,EACdC,aAAa;AAGf,SAASH,OAAO,IAAII,kBAAkB;AACtC,SAASJ,OAAO,IAAIK,YAAY;AAChC,SAASL,OAAO,IAAIM,cAAc"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAsyncCollection.js","names":["useAsyncData","useAsyncCollection","id","path","loader","options","arguments","length","undefined","itemPath","oldData"],"sources":["../../src/useAsyncCollection.js"],"sourcesContent":["/**\n * Loads and uses an item in an async collection.\n */\n\nimport useAsyncData from './useAsyncData';\n\n/**\n * Resolves and stores at the given `path` of global state elements of\n * an asynchronous data collection. In other words, it is an auxiliar wrapper\n * around {@link useAsyncData}, which uses a loader which resolves to different\n * data, based on ID argument passed in, and stores data fetched for different\n * IDs in the state.\n * @param {string} id ID of the collection item to load & use.\n * @param {string} path The global state path where entire collection should be\n * stored.\n * @param {AsyncCollectionLoader} loader A loader function, which takes an\n * ID of data to load, and resolves to the corresponding data.\n * @param {object} [options] Additional options.\n * @param {any[]} [options.deps=[]] An array of dependencies, which trigger\n * data reload when changed. Given dependency changes are watched shallowly\n * (similarly to the standard React's\n * [useEffect()](https://reactjs.org/docs/hooks-reference.html#useeffect)).\n * @param {boolean} [options.noSSR] If `true`, this hook won't load data during\n * server-side rendering.\n * @param {number} [options.garbageCollectAge=maxage] The maximum age of data\n * (in milliseconds), after which they are dropped from the state when the last\n * component referencing them via `useAsyncData()` hook unmounts. Defaults to\n * `maxage` option value.\n * @param {number} [options.maxage=5 x 60 x 1000] The maximum age of\n * data (in milliseconds) acceptable to the hook's caller. If loaded data are\n * older than this value, `null` is returned instead. Defaults to 5 minutes.\n * @param {number} [options.refreshAge=maxage] The maximum age of data\n * (in milliseconds), after which their refreshment will be triggered when\n * any component referencing them via `useAsyncData()` hook (re-)renders.\n * Defaults to `maxage` value.\n * @return {{\n * data: any,\n * loading: boolean,\n * timestamp: number\n * }} Returns an object with three fields: `data` holds the actual result of\n * last `loader` invokation, if any, and if satisfies `maxage` limit; `loading`\n * is a boolean flag, which is `true` if data are being loaded (the hook is\n * waiting for `loader` function resolution); `timestamp` (in milliseconds)\n * is Unix timestamp of related data currently loaded into the global state.\n *\n * Note that loaded data, if any, are stored at the given `path` of global state\n * along with related meta-information, using slightly different state segment\n * structure (see {@link AsyncDataEnvelope}). That segment of the global state\n * can be accessed, and even modified using other hooks,\n * _e.g._ {@link useGlobalState}, but doing so you may interfere with related\n * `useAsyncData()` hooks logic.\n */\nexport default function useAsyncCollection(\n id,\n path,\n loader,\n options = {},\n) {\n const itemPath = path ? `${path}.${id}` : id;\n return useAsyncData(itemPath, (oldData) => loader(id, oldData), options);\n}\n"],"mappings":"AAAA;AACA;AACA;;AAEA,OAAOA,YAAY;;AAEnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,kBAAkBA,CACxCC,EAAE,EACFC,IAAI,EACJC,MAAM,EAEN;EAAA,IADAC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEZ,MAAMG,QAAQ,GAAGN,IAAI,GAAI,GAAEA,IAAK,IAAGD,EAAG,EAAC,GAAGA,EAAE;EAC5C,OAAOF,YAAY,CAACS,QAAQ,EAAGC,OAAO,IAAKN,MAAM,CAACF,EAAE,EAAEQ,OAAO,CAAC,EAAEL,OAAO,CAAC;AAC1E"}