cross-state 0.6.7 → 0.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/hash.cjs +712 -0
- package/dist/cjs/hash.cjs.map +1 -0
- package/dist/cjs/immer.cjs +7 -2
- package/dist/cjs/immer.cjs.map +1 -1
- package/dist/cjs/index.cjs +341 -19
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/react.cjs +289 -11
- package/dist/cjs/react.cjs.map +1 -1
- package/dist/es/hash.mjs +713 -0
- package/dist/es/hash.mjs.map +1 -0
- package/dist/es/{immer/immerActions.js → immer.mjs} +1 -1
- package/dist/es/immer.mjs.map +1 -0
- package/dist/es/{core/cache.js → index.mjs} +126 -8
- package/dist/es/index.mjs.map +1 -0
- package/dist/es/react.mjs +292 -0
- package/dist/es/react.mjs.map +1 -0
- package/package.json +8 -8
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.development.cjs +0 -103
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.development.cjs.map +0 -1
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.development2.cjs +0 -5
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.development2.cjs.map +0 -1
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.production.min.cjs +0 -71
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.production.min.cjs.map +0 -1
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.production.min2.cjs +0 -5
- package/dist/cjs/_virtual/use-sync-external-store-with-selector.production.min2.cjs.map +0 -1
- package/dist/cjs/_virtual/with-selector.cjs +0 -12
- package/dist/cjs/_virtual/with-selector.cjs.map +0 -1
- package/dist/cjs/_virtual/with-selector2.cjs +0 -13
- package/dist/cjs/_virtual/with-selector2.cjs.map +0 -1
- package/dist/cjs/core/cache.cjs +0 -227
- package/dist/cjs/core/cache.cjs.map +0 -1
- package/dist/cjs/core/resourceGroup.cjs +0 -53
- package/dist/cjs/core/resourceGroup.cjs.map +0 -1
- package/dist/cjs/core/store.cjs +0 -259
- package/dist/cjs/core/store.cjs.map +0 -1
- package/dist/cjs/immer/immerActions.cjs +0 -10
- package/dist/cjs/immer/immerActions.cjs.map +0 -1
- package/dist/cjs/lib/calcDuration.cjs +0 -9
- package/dist/cjs/lib/calcDuration.cjs.map +0 -1
- package/dist/cjs/lib/calculationHelper.cjs +0 -140
- package/dist/cjs/lib/calculationHelper.cjs.map +0 -1
- package/dist/cjs/lib/callable.cjs +0 -11
- package/dist/cjs/lib/callable.cjs.map +0 -1
- package/dist/cjs/lib/clone.cjs +0 -19
- package/dist/cjs/lib/clone.cjs.map +0 -1
- package/dist/cjs/lib/debounce.cjs +0 -28
- package/dist/cjs/lib/debounce.cjs.map +0 -1
- package/dist/cjs/lib/equals.cjs +0 -5
- package/dist/cjs/lib/equals.cjs.map +0 -1
- package/dist/cjs/lib/forwardError.cjs +0 -9
- package/dist/cjs/lib/forwardError.cjs.map +0 -1
- package/dist/cjs/lib/hash.cjs +0 -19
- package/dist/cjs/lib/hash.cjs.map +0 -1
- package/dist/cjs/lib/instanceCache.cjs +0 -68
- package/dist/cjs/lib/instanceCache.cjs.map +0 -1
- package/dist/cjs/lib/makeSelector.cjs +0 -14
- package/dist/cjs/lib/makeSelector.cjs.map +0 -1
- package/dist/cjs/lib/propAccess.cjs +0 -66
- package/dist/cjs/lib/propAccess.cjs.map +0 -1
- package/dist/cjs/lib/queue.cjs +0 -61
- package/dist/cjs/lib/queue.cjs.map +0 -1
- package/dist/cjs/lib/standardMethods.cjs +0 -78
- package/dist/cjs/lib/standardMethods.cjs.map +0 -1
- package/dist/cjs/lib/throttle.cjs +0 -25
- package/dist/cjs/lib/throttle.cjs.map +0 -1
- package/dist/cjs/lib/trackingProxy.cjs +0 -39
- package/dist/cjs/lib/trackingProxy.cjs.map +0 -1
- package/dist/cjs/react/read.cjs +0 -15
- package/dist/cjs/react/read.cjs.map +0 -1
- package/dist/cjs/react/storeScope.cjs +0 -31
- package/dist/cjs/react/storeScope.cjs.map +0 -1
- package/dist/cjs/react/useCache.cjs +0 -31
- package/dist/cjs/react/useCache.cjs.map +0 -1
- package/dist/cjs/react/useProp.cjs +0 -9
- package/dist/cjs/react/useProp.cjs.map +0 -1
- package/dist/cjs/react/useStore.cjs +0 -51
- package/dist/cjs/react/useStore.cjs.map +0 -1
- package/dist/es/_virtual/use-sync-external-store-with-selector.development.js +0 -103
- package/dist/es/_virtual/use-sync-external-store-with-selector.development.js.map +0 -1
- package/dist/es/_virtual/use-sync-external-store-with-selector.development2.js +0 -5
- package/dist/es/_virtual/use-sync-external-store-with-selector.development2.js.map +0 -1
- package/dist/es/_virtual/use-sync-external-store-with-selector.production.min.js +0 -71
- package/dist/es/_virtual/use-sync-external-store-with-selector.production.min.js.map +0 -1
- package/dist/es/_virtual/use-sync-external-store-with-selector.production.min2.js +0 -5
- package/dist/es/_virtual/use-sync-external-store-with-selector.production.min2.js.map +0 -1
- package/dist/es/_virtual/with-selector.js +0 -11
- package/dist/es/_virtual/with-selector.js.map +0 -1
- package/dist/es/_virtual/with-selector2.js +0 -14
- package/dist/es/_virtual/with-selector2.js.map +0 -1
- package/dist/es/core/cache.js.map +0 -1
- package/dist/es/core/resourceGroup.js +0 -53
- package/dist/es/core/resourceGroup.js.map +0 -1
- package/dist/es/core/store.js +0 -259
- package/dist/es/core/store.js.map +0 -1
- package/dist/es/immer/immerActions.js.map +0 -1
- package/dist/es/immer.js +0 -5
- package/dist/es/immer.js.map +0 -1
- package/dist/es/index.js +0 -22
- package/dist/es/index.js.map +0 -1
- package/dist/es/lib/calcDuration.js +0 -9
- package/dist/es/lib/calcDuration.js.map +0 -1
- package/dist/es/lib/calculationHelper.js +0 -140
- package/dist/es/lib/calculationHelper.js.map +0 -1
- package/dist/es/lib/callable.js +0 -11
- package/dist/es/lib/callable.js.map +0 -1
- package/dist/es/lib/clone.js +0 -19
- package/dist/es/lib/clone.js.map +0 -1
- package/dist/es/lib/debounce.js +0 -28
- package/dist/es/lib/debounce.js.map +0 -1
- package/dist/es/lib/equals.js +0 -5
- package/dist/es/lib/equals.js.map +0 -1
- package/dist/es/lib/forwardError.js +0 -9
- package/dist/es/lib/forwardError.js.map +0 -1
- package/dist/es/lib/hash.js +0 -19
- package/dist/es/lib/hash.js.map +0 -1
- package/dist/es/lib/instanceCache.js +0 -68
- package/dist/es/lib/instanceCache.js.map +0 -1
- package/dist/es/lib/makeSelector.js +0 -14
- package/dist/es/lib/makeSelector.js.map +0 -1
- package/dist/es/lib/propAccess.js +0 -66
- package/dist/es/lib/propAccess.js.map +0 -1
- package/dist/es/lib/queue.js +0 -61
- package/dist/es/lib/queue.js.map +0 -1
- package/dist/es/lib/standardMethods.js +0 -78
- package/dist/es/lib/standardMethods.js.map +0 -1
- package/dist/es/lib/throttle.js +0 -25
- package/dist/es/lib/throttle.js.map +0 -1
- package/dist/es/lib/trackingProxy.js +0 -39
- package/dist/es/lib/trackingProxy.js.map +0 -1
- package/dist/es/react/read.js +0 -15
- package/dist/es/react/read.js.map +0 -1
- package/dist/es/react/storeScope.js +0 -31
- package/dist/es/react/storeScope.js.map +0 -1
- package/dist/es/react/useCache.js +0 -31
- package/dist/es/react/useCache.js.map +0 -1
- package/dist/es/react/useProp.js +0 -9
- package/dist/es/react/useProp.js.map +0 -1
- package/dist/es/react/useStore.js +0 -51
- package/dist/es/react/useStore.js.map +0 -1
- package/dist/es/react.js +0 -14
- package/dist/es/react.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cross-state",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"description": "(React) state library",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "schummar/schummar-state",
|
|
@@ -16,23 +16,23 @@
|
|
|
16
16
|
"react.d.ts"
|
|
17
17
|
],
|
|
18
18
|
"main": "dist/cjs/index.cjs",
|
|
19
|
-
"module": "dist/es/index.
|
|
19
|
+
"module": "dist/es/index.mjs",
|
|
20
20
|
"types": "dist/types/index.d.ts",
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
23
|
-
"import": "./dist/es/index.
|
|
23
|
+
"import": "./dist/es/index.mjs",
|
|
24
24
|
"require": "./dist/cjs/index.cjs",
|
|
25
|
-
"default": "./dist/es/index.
|
|
25
|
+
"default": "./dist/es/index.mjs"
|
|
26
26
|
},
|
|
27
27
|
"./react": {
|
|
28
|
-
"import": "./dist/es/react.
|
|
28
|
+
"import": "./dist/es/react.mjs",
|
|
29
29
|
"require": "./dist/cjs/react.cjs",
|
|
30
|
-
"default": "./dist/es/react.
|
|
30
|
+
"default": "./dist/es/react.mjs"
|
|
31
31
|
},
|
|
32
32
|
"./immer": {
|
|
33
|
-
"import": "./dist/es/immer.
|
|
33
|
+
"import": "./dist/es/immer.mjs",
|
|
34
34
|
"require": "./dist/cjs/immer.cjs",
|
|
35
|
-
"default": "./dist/es/immer.
|
|
35
|
+
"default": "./dist/es/immer.mjs"
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"typesVersions": {
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const useSyncExternalStoreWithSelector_development = require("./use-sync-external-store-with-selector.development2.cjs");
|
|
4
|
-
const require$$0 = require("react");
|
|
5
|
-
/**
|
|
6
|
-
* @license React
|
|
7
|
-
* use-sync-external-store-with-selector.development.js
|
|
8
|
-
*
|
|
9
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
10
|
-
*
|
|
11
|
-
* This source code is licensed under the MIT license found in the
|
|
12
|
-
* LICENSE file in the root directory of this source tree.
|
|
13
|
-
*/
|
|
14
|
-
var hasRequiredUseSyncExternalStoreWithSelector_development;
|
|
15
|
-
function requireUseSyncExternalStoreWithSelector_development() {
|
|
16
|
-
if (hasRequiredUseSyncExternalStoreWithSelector_development)
|
|
17
|
-
return useSyncExternalStoreWithSelector_development.__exports;
|
|
18
|
-
hasRequiredUseSyncExternalStoreWithSelector_development = 1;
|
|
19
|
-
if (process.env.NODE_ENV !== "production") {
|
|
20
|
-
(function() {
|
|
21
|
-
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
|
|
22
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
23
|
-
}
|
|
24
|
-
var React = require$$0;
|
|
25
|
-
function is(x, y) {
|
|
26
|
-
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
27
|
-
}
|
|
28
|
-
var objectIs = typeof Object.is === "function" ? Object.is : is;
|
|
29
|
-
var useSyncExternalStore = React.useSyncExternalStore;
|
|
30
|
-
var useRef = React.useRef, useEffect = React.useEffect, useMemo = React.useMemo, useDebugValue = React.useDebugValue;
|
|
31
|
-
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
|
|
32
|
-
var instRef = useRef(null);
|
|
33
|
-
var inst;
|
|
34
|
-
if (instRef.current === null) {
|
|
35
|
-
inst = {
|
|
36
|
-
hasValue: false,
|
|
37
|
-
value: null
|
|
38
|
-
};
|
|
39
|
-
instRef.current = inst;
|
|
40
|
-
} else {
|
|
41
|
-
inst = instRef.current;
|
|
42
|
-
}
|
|
43
|
-
var _useMemo = useMemo(function() {
|
|
44
|
-
var hasMemo = false;
|
|
45
|
-
var memoizedSnapshot;
|
|
46
|
-
var memoizedSelection;
|
|
47
|
-
var memoizedSelector = function(nextSnapshot) {
|
|
48
|
-
if (!hasMemo) {
|
|
49
|
-
hasMemo = true;
|
|
50
|
-
memoizedSnapshot = nextSnapshot;
|
|
51
|
-
var _nextSelection = selector(nextSnapshot);
|
|
52
|
-
if (isEqual !== void 0) {
|
|
53
|
-
if (inst.hasValue) {
|
|
54
|
-
var currentSelection = inst.value;
|
|
55
|
-
if (isEqual(currentSelection, _nextSelection)) {
|
|
56
|
-
memoizedSelection = currentSelection;
|
|
57
|
-
return currentSelection;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
memoizedSelection = _nextSelection;
|
|
62
|
-
return _nextSelection;
|
|
63
|
-
}
|
|
64
|
-
var prevSnapshot = memoizedSnapshot;
|
|
65
|
-
var prevSelection = memoizedSelection;
|
|
66
|
-
if (objectIs(prevSnapshot, nextSnapshot)) {
|
|
67
|
-
return prevSelection;
|
|
68
|
-
}
|
|
69
|
-
var nextSelection = selector(nextSnapshot);
|
|
70
|
-
if (isEqual !== void 0 && isEqual(prevSelection, nextSelection)) {
|
|
71
|
-
return prevSelection;
|
|
72
|
-
}
|
|
73
|
-
memoizedSnapshot = nextSnapshot;
|
|
74
|
-
memoizedSelection = nextSelection;
|
|
75
|
-
return nextSelection;
|
|
76
|
-
};
|
|
77
|
-
var maybeGetServerSnapshot = getServerSnapshot === void 0 ? null : getServerSnapshot;
|
|
78
|
-
var getSnapshotWithSelector = function() {
|
|
79
|
-
return memoizedSelector(getSnapshot());
|
|
80
|
-
};
|
|
81
|
-
var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? void 0 : function() {
|
|
82
|
-
return memoizedSelector(maybeGetServerSnapshot());
|
|
83
|
-
};
|
|
84
|
-
return [getSnapshotWithSelector, getServerSnapshotWithSelector];
|
|
85
|
-
}, [getSnapshot, getServerSnapshot, selector, isEqual]), getSelection = _useMemo[0], getServerSelection = _useMemo[1];
|
|
86
|
-
var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
|
|
87
|
-
useEffect(function() {
|
|
88
|
-
inst.hasValue = true;
|
|
89
|
-
inst.value = value;
|
|
90
|
-
}, [value]);
|
|
91
|
-
useDebugValue(value);
|
|
92
|
-
return value;
|
|
93
|
-
}
|
|
94
|
-
useSyncExternalStoreWithSelector_development.__exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;
|
|
95
|
-
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function") {
|
|
96
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
97
|
-
}
|
|
98
|
-
})();
|
|
99
|
-
}
|
|
100
|
-
return useSyncExternalStoreWithSelector_development.__exports;
|
|
101
|
-
}
|
|
102
|
-
exports.__require = requireUseSyncExternalStoreWithSelector_development;
|
|
103
|
-
//# sourceMappingURL=use-sync-external-store-with-selector.development.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-sync-external-store-with-selector.development.cjs","sources":["../../../node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.development.js"],"sourcesContent":["/**\n * @license React\n * use-sync-external-store-with-selector.development.js\n *\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n'use strict';\n\nif (process.env.NODE_ENV !== \"production\") {\n (function() {\n\n 'use strict';\n\n/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */\nif (\n typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&\n typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===\n 'function'\n) {\n __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());\n}\n var React = require('react');\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\nfunction is(x, y) {\n return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare\n ;\n}\n\nvar objectIs = typeof Object.is === 'function' ? Object.is : is;\n\nvar useSyncExternalStore = React.useSyncExternalStore;\n\n// for CommonJS interop.\n\nvar useRef = React.useRef,\n useEffect = React.useEffect,\n useMemo = React.useMemo,\n useDebugValue = React.useDebugValue; // Same as useSyncExternalStore, but supports selector and isEqual arguments.\n\nfunction useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {\n // Use this to track the rendered snapshot.\n var instRef = useRef(null);\n var inst;\n\n if (instRef.current === null) {\n inst = {\n hasValue: false,\n value: null\n };\n instRef.current = inst;\n } else {\n inst = instRef.current;\n }\n\n var _useMemo = useMemo(function () {\n // Track the memoized state using closure variables that are local to this\n // memoized instance of a getSnapshot function. Intentionally not using a\n // useRef hook, because that state would be shared across all concurrent\n // copies of the hook/component.\n var hasMemo = false;\n var memoizedSnapshot;\n var memoizedSelection;\n\n var memoizedSelector = function (nextSnapshot) {\n if (!hasMemo) {\n // The first time the hook is called, there is no memoized result.\n hasMemo = true;\n memoizedSnapshot = nextSnapshot;\n\n var _nextSelection = selector(nextSnapshot);\n\n if (isEqual !== undefined) {\n // Even if the selector has changed, the currently rendered selection\n // may be equal to the new selection. We should attempt to reuse the\n // current value if possible, to preserve downstream memoizations.\n if (inst.hasValue) {\n var currentSelection = inst.value;\n\n if (isEqual(currentSelection, _nextSelection)) {\n memoizedSelection = currentSelection;\n return currentSelection;\n }\n }\n }\n\n memoizedSelection = _nextSelection;\n return _nextSelection;\n } // We may be able to reuse the previous invocation's result.\n\n\n // We may be able to reuse the previous invocation's result.\n var prevSnapshot = memoizedSnapshot;\n var prevSelection = memoizedSelection;\n\n if (objectIs(prevSnapshot, nextSnapshot)) {\n // The snapshot is the same as last time. Reuse the previous selection.\n return prevSelection;\n } // The snapshot has changed, so we need to compute a new selection.\n\n\n // The snapshot has changed, so we need to compute a new selection.\n var nextSelection = selector(nextSnapshot); // If a custom isEqual function is provided, use that to check if the data\n // has changed. If it hasn't, return the previous selection. That signals\n // to React that the selections are conceptually equal, and we can bail\n // out of rendering.\n\n // If a custom isEqual function is provided, use that to check if the data\n // has changed. If it hasn't, return the previous selection. That signals\n // to React that the selections are conceptually equal, and we can bail\n // out of rendering.\n if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) {\n return prevSelection;\n }\n\n memoizedSnapshot = nextSnapshot;\n memoizedSelection = nextSelection;\n return nextSelection;\n }; // Assigning this to a constant so that Flow knows it can't change.\n\n\n // Assigning this to a constant so that Flow knows it can't change.\n var maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot;\n\n var getSnapshotWithSelector = function () {\n return memoizedSelector(getSnapshot());\n };\n\n var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : function () {\n return memoizedSelector(maybeGetServerSnapshot());\n };\n return [getSnapshotWithSelector, getServerSnapshotWithSelector];\n }, [getSnapshot, getServerSnapshot, selector, isEqual]),\n getSelection = _useMemo[0],\n getServerSelection = _useMemo[1];\n\n var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);\n useEffect(function () {\n inst.hasValue = true;\n inst.value = value;\n }, [value]);\n useDebugValue(value);\n return value;\n}\n\nexports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;\n /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */\nif (\n typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&\n typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===\n 'function'\n) {\n __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());\n}\n \n })();\n}\n"],"names":["useSyncExternalStoreWithSelector_development"],"mappings":";;;;;;;;;;;;;;;;;;AAYA,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,KAAC,WAAW;AAKd,UACE,OAAO,mCAAmC,eAC1C,OAAO,+BAA+B,gCACpC,YACF;AACA,uCAA+B,4BAA4B,IAAI,MAAK,CAAE;AAAA,MACvE;AACS,UAAI,QAAQ;AAMtB,eAAS,GAAG,GAAG,GAAG;AAChB,eAAO,MAAM,MAAM,MAAM,KAAK,I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,iBAAiB,YAAW,CAAE;AAAA,UAC3C;AAEI,cAAI,gCAAgC,2BAA2B,OAAO,SAAY,WAAY;AAC5F,mBAAO,iBAAiB,uBAAsB,CAAE;AAAA,UACtD;AACI,iBAAO,CAAC,yBAAyB,6BAA6B;AAAA,QAC/D,GAAE,CAAC,aAAa,mBAAmB,UAAU,OAAO,CAAC,GAClD,eAAe,SAAS,CAAC,GACzB,qBAAqB,SAAS,CAAC;AAEnC,YAAI,QAAQ,qBAAqB,WAAW,cAAc,kBAAkB;AAC5E,kBAAU,WAAY;AACpB,eAAK,WAAW;AAChB,eAAK,QAAQ;AAAA,QACjB,GAAK,CAAC,KAAK,CAAC;AACV,sBAAc,KAAK;AACnB,eAAO;AAAA,MACR;AAEuCA,mDAAA,UAAA,mCAAG;AAE3C,UACE,OAAO,mCAAmC,eAC1C,OAAO,+BAA+B,+BACpC,YACF;AACA,uCAA+B,2BAA2B,IAAI,MAAK,CAAE;AAAA,MACtE;AAAA,IAED;EACA;;;;"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
var useSyncExternalStoreWithSelector_development = {};
|
|
4
|
-
exports.__exports = useSyncExternalStoreWithSelector_development;
|
|
5
|
-
//# sourceMappingURL=use-sync-external-store-with-selector.development2.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-sync-external-store-with-selector.development2.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const useSyncExternalStoreWithSelector_production_min = require("./use-sync-external-store-with-selector.production.min2.cjs");
|
|
4
|
-
const require$$0 = require("react");
|
|
5
|
-
/**
|
|
6
|
-
* @license React
|
|
7
|
-
* use-sync-external-store-with-selector.production.min.js
|
|
8
|
-
*
|
|
9
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
10
|
-
*
|
|
11
|
-
* This source code is licensed under the MIT license found in the
|
|
12
|
-
* LICENSE file in the root directory of this source tree.
|
|
13
|
-
*/
|
|
14
|
-
var hasRequiredUseSyncExternalStoreWithSelector_production_min;
|
|
15
|
-
function requireUseSyncExternalStoreWithSelector_production_min() {
|
|
16
|
-
if (hasRequiredUseSyncExternalStoreWithSelector_production_min)
|
|
17
|
-
return useSyncExternalStoreWithSelector_production_min.__exports;
|
|
18
|
-
hasRequiredUseSyncExternalStoreWithSelector_production_min = 1;
|
|
19
|
-
var g = require$$0;
|
|
20
|
-
function n(a, b) {
|
|
21
|
-
return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
|
|
22
|
-
}
|
|
23
|
-
var p = "function" === typeof Object.is ? Object.is : n, q = g.useSyncExternalStore, r = g.useRef, t = g.useEffect, u = g.useMemo, v = g.useDebugValue;
|
|
24
|
-
useSyncExternalStoreWithSelector_production_min.__exports.useSyncExternalStoreWithSelector = function(a, b, e, l, h) {
|
|
25
|
-
var c = r(null);
|
|
26
|
-
if (null === c.current) {
|
|
27
|
-
var f = { hasValue: false, value: null };
|
|
28
|
-
c.current = f;
|
|
29
|
-
} else
|
|
30
|
-
f = c.current;
|
|
31
|
-
c = u(function() {
|
|
32
|
-
function a2(a3) {
|
|
33
|
-
if (!c2) {
|
|
34
|
-
c2 = true;
|
|
35
|
-
d2 = a3;
|
|
36
|
-
a3 = l(a3);
|
|
37
|
-
if (void 0 !== h && f.hasValue) {
|
|
38
|
-
var b2 = f.value;
|
|
39
|
-
if (h(b2, a3))
|
|
40
|
-
return k = b2;
|
|
41
|
-
}
|
|
42
|
-
return k = a3;
|
|
43
|
-
}
|
|
44
|
-
b2 = k;
|
|
45
|
-
if (p(d2, a3))
|
|
46
|
-
return b2;
|
|
47
|
-
var e2 = l(a3);
|
|
48
|
-
if (void 0 !== h && h(b2, e2))
|
|
49
|
-
return b2;
|
|
50
|
-
d2 = a3;
|
|
51
|
-
return k = e2;
|
|
52
|
-
}
|
|
53
|
-
var c2 = false, d2, k, m = void 0 === e ? null : e;
|
|
54
|
-
return [function() {
|
|
55
|
-
return a2(b());
|
|
56
|
-
}, null === m ? void 0 : function() {
|
|
57
|
-
return a2(m());
|
|
58
|
-
}];
|
|
59
|
-
}, [b, e, l, h]);
|
|
60
|
-
var d = q(a, c[0], c[1]);
|
|
61
|
-
t(function() {
|
|
62
|
-
f.hasValue = true;
|
|
63
|
-
f.value = d;
|
|
64
|
-
}, [d]);
|
|
65
|
-
v(d);
|
|
66
|
-
return d;
|
|
67
|
-
};
|
|
68
|
-
return useSyncExternalStoreWithSelector_production_min.__exports;
|
|
69
|
-
}
|
|
70
|
-
exports.__require = requireUseSyncExternalStoreWithSelector_production_min;
|
|
71
|
-
//# sourceMappingURL=use-sync-external-store-with-selector.production.min.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-sync-external-store-with-selector.production.min.cjs","sources":["../../../node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.production.min.js"],"sourcesContent":["/**\n * @license React\n * use-sync-external-store-with-selector.production.min.js\n *\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n'use strict';var g=require(\"react\");function n(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var p=\"function\"===typeof Object.is?Object.is:n,q=g.useSyncExternalStore,r=g.useRef,t=g.useEffect,u=g.useMemo,v=g.useDebugValue;\nexports.useSyncExternalStoreWithSelector=function(a,b,e,l,h){var c=r(null);if(null===c.current){var f={hasValue:!1,value:null};c.current=f}else f=c.current;c=u(function(){function a(a){if(!c){c=!0;d=a;a=l(a);if(void 0!==h&&f.hasValue){var b=f.value;if(h(b,a))return k=b}return k=a}b=k;if(p(d,a))return b;var e=l(a);if(void 0!==h&&h(b,e))return b;d=a;return k=e}var c=!1,d,k,m=void 0===e?null:e;return[function(){return a(b())},null===m?void 0:function(){return a(m())}]},[b,e,l,h]);var d=q(a,c[0],c[1]);\nt(function(){f.hasValue=!0;f.value=d},[d]);v(d);return d};\n"],"names":["useSyncExternalStoreWithSelector_production_min","a","c","d","b","e"],"mappings":";;;;;;;;;;;;;;;;;;AASa,MAAI,IAAE;AAAiB,WAAS,EAAE,GAAE,GAAE;AAAC,WAAO,MAAI,MAAI,MAAI,KAAG,IAAE,MAAI,IAAE,MAAI,MAAI,KAAG,MAAI;AAAA,EAAC;AAAC,MAAI,IAAE,eAAa,OAAO,OAAO,KAAG,OAAO,KAAG,GAAE,IAAE,EAAE,sBAAqB,IAAE,EAAE,QAAO,IAAE,EAAE,WAAU,IAAE,EAAE,SAAQ,IAAE,EAAE;AACrNA,kDAAA,UAAA,mCAAyC,SAAS,GAAE,GAAE,GAAE,GAAE,GAAE;AAAC,QAAI,IAAE,EAAE,IAAI;AAAE,QAAG,SAAO,EAAE,SAAQ;AAAC,UAAI,IAAE,EAAC,UAAS,OAAG,OAAM,KAAI;AAAE,QAAE,UAAQ;AAAA,IAAC;AAAM,UAAE,EAAE;AAAQ,QAAE,EAAE,WAAU;AAAC,eAASC,GAAEA,IAAE;AAAC,YAAG,CAACC,IAAE;AAAC,UAAAA,KAAE;AAAG,UAAAC,KAAEF;AAAE,UAAAA,KAAE,EAAEA,EAAC;AAAE,cAAG,WAAS,KAAG,EAAE,UAAS;AAAC,gBAAIG,KAAE,EAAE;AAAM,gBAAG,EAAEA,IAAEH,EAAC;AAAE,qBAAO,IAAEG;AAAA,UAAC;AAAC,iBAAO,IAAEH;AAAA,QAAC;AAAC,QAAAG,KAAE;AAAE,YAAG,EAAED,IAAEF,EAAC;AAAE,iBAAOG;AAAE,YAAIC,KAAE,EAAEJ,EAAC;AAAE,YAAG,WAAS,KAAG,EAAEG,IAAEC,EAAC;AAAE,iBAAOD;AAAE,QAAAD,KAAEF;AAAE,eAAO,IAAEI;AAAA,MAAC;AAAC,UAAIH,KAAE,OAAGC,IAAE,GAAE,IAAE,WAAS,IAAE,OAAK;AAAE,aAAM,CAAC,WAAU;AAAC,eAAOF,GAAE,EAAG,CAAA;AAAA,MAAC,GAAE,SAAO,IAAE,SAAO,WAAU;AAAC,eAAOA,GAAE,EAAC,CAAE;AAAA,MAAC,CAAC;AAAA,IAAC,GAAE,CAAC,GAAE,GAAE,GAAE,CAAC,CAAC;AAAE,QAAI,IAAE,EAAE,GAAE,EAAE,CAAC,GAAE,EAAE,CAAC,CAAC;AACrf,MAAE,WAAU;AAAC,QAAE,WAAS;AAAG,QAAE,QAAM;AAAA,IAAC,GAAE,CAAC,CAAC,CAAC;AAAE,MAAE,CAAC;AAAE,WAAO;AAAA,EAAC;;;;"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
var useSyncExternalStoreWithSelector_production_min = {};
|
|
4
|
-
exports.__exports = useSyncExternalStoreWithSelector_production_min;
|
|
5
|
-
//# sourceMappingURL=use-sync-external-store-with-selector.production.min2.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-sync-external-store-with-selector.production.min2.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const withSelector = require("./with-selector2.cjs");
|
|
3
|
-
const useSyncExternalStoreWithSelector_production_min = require("./use-sync-external-store-with-selector.production.min.cjs");
|
|
4
|
-
const useSyncExternalStoreWithSelector_development = require("./use-sync-external-store-with-selector.development.cjs");
|
|
5
|
-
(function(module2) {
|
|
6
|
-
if (process.env.NODE_ENV === "production") {
|
|
7
|
-
module2.exports = useSyncExternalStoreWithSelector_production_min.__require();
|
|
8
|
-
} else {
|
|
9
|
-
module2.exports = useSyncExternalStoreWithSelector_development.__require();
|
|
10
|
-
}
|
|
11
|
-
})(withSelector.__module);
|
|
12
|
-
//# sourceMappingURL=with-selector.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"with-selector.cjs","sources":["../../../node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/with-selector.js"],"sourcesContent":["'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/use-sync-external-store-with-selector.production.min.js');\n} else {\n module.exports = require('./cjs/use-sync-external-store-with-selector.development.js');\n}\n"],"names":["module","require$$0","require$$1"],"mappings":";;;;;AAEA,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,IAAAA,QAAA,UAAiBC,gDAAAA;EACnB,OAAO;AACL,IAAAD,QAAA,UAAiBE,6CAAAA;EACnB;;"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
exports.exports = {};
|
|
4
|
-
var withSelector = {
|
|
5
|
-
get exports() {
|
|
6
|
-
return exports.exports;
|
|
7
|
-
},
|
|
8
|
-
set exports(v) {
|
|
9
|
-
exports.exports = v;
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
exports.__module = withSelector;
|
|
13
|
-
//# sourceMappingURL=with-selector2.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"with-selector2.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
|
package/dist/cjs/core/cache.cjs
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const resourceGroup = require("./resourceGroup.cjs");
|
|
4
|
-
const store = require("./store.cjs");
|
|
5
|
-
const calcDuration = require("../lib/calcDuration.cjs");
|
|
6
|
-
const instanceCache = require("../lib/instanceCache.cjs");
|
|
7
|
-
const makeSelector = require("../lib/makeSelector.cjs");
|
|
8
|
-
class Cache extends store.Store {
|
|
9
|
-
constructor(getter, options = {}, derivedFromCache, _call) {
|
|
10
|
-
super(getter, options, void 0, _call);
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.derivedFromCache = derivedFromCache;
|
|
13
|
-
this.state = store.createStore({
|
|
14
|
-
status: "pending",
|
|
15
|
-
isStale: true,
|
|
16
|
-
isUpdating: false
|
|
17
|
-
});
|
|
18
|
-
this.invalidate = this.invalidate.bind(this);
|
|
19
|
-
this.clear = this.clear.bind(this);
|
|
20
|
-
this.mapValue = this.mapValue.bind(this);
|
|
21
|
-
this.watchPromise();
|
|
22
|
-
this.watchFocus();
|
|
23
|
-
}
|
|
24
|
-
get({ update = "whenStale", backgroundUpdate = false } = {}) {
|
|
25
|
-
var _a;
|
|
26
|
-
const promise = (_a = this._value) == null ? void 0 : _a.v;
|
|
27
|
-
const stalePromise = this.stalePromise;
|
|
28
|
-
if (update === "whenMissing" && !promise && !stalePromise || update === "whenStale" && !promise || update === "force") {
|
|
29
|
-
this.calculationHelper.execute();
|
|
30
|
-
if (!promise && !stalePromise || !backgroundUpdate) {
|
|
31
|
-
return super.get();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if (!promise || stalePromise && backgroundUpdate) {
|
|
35
|
-
return stalePromise;
|
|
36
|
-
}
|
|
37
|
-
return promise;
|
|
38
|
-
}
|
|
39
|
-
invalidate({ invalidateDependencies = true } = {}) {
|
|
40
|
-
var _a;
|
|
41
|
-
const { clearOnInvalidate: clearOnInvalidation = defaultOptions.clearOnInvalidate } = this.options;
|
|
42
|
-
if (clearOnInvalidation) {
|
|
43
|
-
return this.clear({ invalidateDependencies });
|
|
44
|
-
}
|
|
45
|
-
if (invalidateDependencies) {
|
|
46
|
-
this.calculationHelper.invalidateDependencies();
|
|
47
|
-
}
|
|
48
|
-
const { status, isStale, isUpdating } = this.state.get();
|
|
49
|
-
if (status !== "pending" && !isStale && !isUpdating) {
|
|
50
|
-
this.stalePromise = (_a = this._value) == null ? void 0 : _a.v;
|
|
51
|
-
}
|
|
52
|
-
this.state.set((state) => ({
|
|
53
|
-
...state,
|
|
54
|
-
isStale: true,
|
|
55
|
-
isUpdating: false
|
|
56
|
-
}));
|
|
57
|
-
super.reset();
|
|
58
|
-
}
|
|
59
|
-
clear({ invalidateDependencies = true } = {}) {
|
|
60
|
-
if (invalidateDependencies) {
|
|
61
|
-
this.calculationHelper.invalidateDependencies();
|
|
62
|
-
}
|
|
63
|
-
this.state.set({
|
|
64
|
-
status: "pending",
|
|
65
|
-
isStale: true,
|
|
66
|
-
isUpdating: false
|
|
67
|
-
});
|
|
68
|
-
delete this.stalePromise;
|
|
69
|
-
super.reset();
|
|
70
|
-
}
|
|
71
|
-
mapValue(_selector) {
|
|
72
|
-
const selector = makeSelector.makeSelector(_selector);
|
|
73
|
-
const derivedFromCache = {
|
|
74
|
-
cache: this.derivedFromCache ? this.derivedFromCache.cache : this,
|
|
75
|
-
selectors: this.derivedFromCache ? [...this.derivedFromCache.selectors, _selector] : [_selector]
|
|
76
|
-
};
|
|
77
|
-
const that = this;
|
|
78
|
-
return new Cache(
|
|
79
|
-
async function() {
|
|
80
|
-
const value = await this.use(that);
|
|
81
|
-
return selector(value);
|
|
82
|
-
},
|
|
83
|
-
{},
|
|
84
|
-
derivedFromCache
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
watchPromise() {
|
|
88
|
-
this.sub(
|
|
89
|
-
async (promise) => {
|
|
90
|
-
var _a, _b;
|
|
91
|
-
this.state.set((state) => ({
|
|
92
|
-
...state,
|
|
93
|
-
isUpdating: true
|
|
94
|
-
}));
|
|
95
|
-
this.setTimers();
|
|
96
|
-
try {
|
|
97
|
-
const value = await promise;
|
|
98
|
-
if (promise !== ((_a = this._value) == null ? void 0 : _a.v)) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
this.state.set({
|
|
102
|
-
status: "value",
|
|
103
|
-
value,
|
|
104
|
-
isStale: false,
|
|
105
|
-
isUpdating: false
|
|
106
|
-
});
|
|
107
|
-
delete this.stalePromise;
|
|
108
|
-
this.setTimers();
|
|
109
|
-
} catch (error) {
|
|
110
|
-
if (promise !== ((_b = this._value) == null ? void 0 : _b.v)) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
this.state.set({
|
|
114
|
-
status: "error",
|
|
115
|
-
error,
|
|
116
|
-
isStale: false,
|
|
117
|
-
isUpdating: false
|
|
118
|
-
});
|
|
119
|
-
delete this.stalePromise;
|
|
120
|
-
this.setTimers();
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
{ passive: true }
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
setTimers() {
|
|
127
|
-
if (this.invalidationTimer) {
|
|
128
|
-
clearTimeout(this.invalidationTimer);
|
|
129
|
-
}
|
|
130
|
-
this.invalidationTimer = void 0;
|
|
131
|
-
const state = this.state.get();
|
|
132
|
-
let { invalidateAfter = defaultOptions.invalidateAfter } = this.options;
|
|
133
|
-
const ref = new WeakRef(this);
|
|
134
|
-
if (state.status === "pending") {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if (invalidateAfter instanceof Function) {
|
|
138
|
-
invalidateAfter = invalidateAfter(state);
|
|
139
|
-
}
|
|
140
|
-
if (invalidateAfter !== null && invalidateAfter !== void 0) {
|
|
141
|
-
this.invalidationTimer = setTimeout(
|
|
142
|
-
() => {
|
|
143
|
-
var _a;
|
|
144
|
-
return (_a = ref == null ? void 0 : ref.deref()) == null ? void 0 : _a.invalidate();
|
|
145
|
-
},
|
|
146
|
-
calcDuration.calcDuration(invalidateAfter)
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
watchFocus() {
|
|
151
|
-
const { invalidateOnWindowFocus = defaultOptions.invalidateOnWindowFocus } = this.options;
|
|
152
|
-
if (!invalidateOnWindowFocus || typeof document === "undefined" || typeof document.addEventListener === "undefined") {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
const ref = new WeakRef(this);
|
|
156
|
-
const onFocus = () => {
|
|
157
|
-
const that = ref == null ? void 0 : ref.deref();
|
|
158
|
-
if (!that) {
|
|
159
|
-
document.removeEventListener("visibilitychange", onFocus);
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
if (!document.hidden) {
|
|
163
|
-
that.invalidate();
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
document.addEventListener("visibilitychange", onFocus);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
const defaultOptions = {
|
|
170
|
-
invalidateOnWindowFocus: true,
|
|
171
|
-
invalidateOnActivation: true,
|
|
172
|
-
clearUnusedAfter: { days: 1 }
|
|
173
|
-
};
|
|
174
|
-
function create(cacheFunction, options) {
|
|
175
|
-
const { clearUnusedAfter = defaultOptions.clearUnusedAfter, resourceGroup: resourceGroup$1 } = options ?? {};
|
|
176
|
-
let baseInstance;
|
|
177
|
-
const instanceCache$1 = new instanceCache.InstanceCache(
|
|
178
|
-
(...args) => {
|
|
179
|
-
if (args.length === 0 && baseInstance) {
|
|
180
|
-
return baseInstance;
|
|
181
|
-
}
|
|
182
|
-
return new Cache(function() {
|
|
183
|
-
return cacheFunction.apply(this, args);
|
|
184
|
-
}, options);
|
|
185
|
-
},
|
|
186
|
-
clearUnusedAfter ? calcDuration.calcDuration(clearUnusedAfter) : void 0
|
|
187
|
-
);
|
|
188
|
-
const get = (...args) => {
|
|
189
|
-
return instanceCache$1.get(...args);
|
|
190
|
-
};
|
|
191
|
-
const invalidateAll = () => {
|
|
192
|
-
for (const instance of instanceCache$1.values()) {
|
|
193
|
-
instance.invalidate();
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
const clearAll = () => {
|
|
197
|
-
for (const instance of instanceCache$1.values()) {
|
|
198
|
-
instance.clear();
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
const groups = Array.isArray(resourceGroup$1) ? resourceGroup$1 : resourceGroup$1 ? [resourceGroup$1] : [];
|
|
202
|
-
for (const group of groups.concat(resourceGroup.allResources)) {
|
|
203
|
-
group.add({ invalidate: invalidateAll, clear: clearAll });
|
|
204
|
-
}
|
|
205
|
-
baseInstance = Object.assign(
|
|
206
|
-
new Cache(
|
|
207
|
-
function() {
|
|
208
|
-
return cacheFunction.apply(this);
|
|
209
|
-
},
|
|
210
|
-
options,
|
|
211
|
-
void 0,
|
|
212
|
-
get
|
|
213
|
-
),
|
|
214
|
-
{
|
|
215
|
-
invalidateAll,
|
|
216
|
-
clearAll
|
|
217
|
-
}
|
|
218
|
-
);
|
|
219
|
-
get(...[]);
|
|
220
|
-
return baseInstance;
|
|
221
|
-
}
|
|
222
|
-
const createCache = Object.assign(create, {
|
|
223
|
-
defaultOptions
|
|
224
|
-
});
|
|
225
|
-
exports.Cache = Cache;
|
|
226
|
-
exports.createCache = createCache;
|
|
227
|
-
//# sourceMappingURL=cache.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache.cjs","sources":["../../../src/core/cache.ts"],"sourcesContent":["import type { Duration, Selector, Use } from './commonTypes';\nimport { allResources, type ResourceGroup } from './resourceGroup';\nimport { createStore, Store } from './store';\nimport type { CacheState, ErrorState, ValueState } from '@lib/cacheState';\nimport { calcDuration } from '@lib/calcDuration';\nimport { InstanceCache } from '@lib/instanceCache';\nimport { makeSelector } from '@lib/makeSelector';\nimport type { Path, Value } from '@lib/path';\n\nexport interface CacheGetOptions {\n update?: 'whenMissing' | 'whenStale' | 'force';\n backgroundUpdate?: boolean;\n}\n\nexport interface CacheFunction<T, Args extends any[] = []> {\n (this: { use: Use }, ...args: Args): Promise<T>;\n}\n\nexport interface CacheOptions<T> {\n invalidateAfter?: Duration | ((state: ValueState<T> | ErrorState) => Duration | null) | null;\n invalidateOnWindowFocus?: boolean;\n invalidateOnActivation?: boolean;\n clearOnInvalidate?: boolean;\n clearUnusedAfter?: Duration | null;\n resourceGroup?: ResourceGroup | ResourceGroup[];\n retain?: number;\n}\n\nexport class Cache<T> extends Store<Promise<T>> {\n readonly state = createStore<CacheState<T>>({\n status: 'pending',\n isStale: true,\n isUpdating: false,\n });\n\n protected stalePromise?: Promise<T>;\n\n protected invalidationTimer?: ReturnType<typeof setTimeout>;\n\n constructor(\n getter: CacheFunction<T>,\n public readonly options: CacheOptions<T> = {},\n public readonly derivedFromCache?: {\n cache: Cache<any>;\n selectors: (Selector<any, any> | Path<any>)[];\n },\n _call?: (...args: any[]) => any,\n ) {\n super(getter, options, undefined, _call);\n this.invalidate = this.invalidate.bind(this);\n this.clear = this.clear.bind(this);\n this.mapValue = this.mapValue.bind(this);\n\n this.watchPromise();\n this.watchFocus();\n }\n\n get({ update = 'whenStale', backgroundUpdate = false }: CacheGetOptions = {}) {\n const promise = this._value?.v;\n const stalePromise = this.stalePromise;\n\n if (\n (update === 'whenMissing' && !promise && !stalePromise) ||\n (update === 'whenStale' && !promise) ||\n update === 'force'\n ) {\n this.calculationHelper.execute();\n\n if ((!promise && !stalePromise) || !backgroundUpdate) {\n return super.get();\n }\n }\n\n if (!promise || (stalePromise && backgroundUpdate)) {\n return stalePromise!;\n }\n\n return promise;\n }\n\n invalidate({ invalidateDependencies = true }: { invalidateDependencies?: boolean } = {}) {\n const { clearOnInvalidate: clearOnInvalidation = defaultOptions.clearOnInvalidate } =\n this.options;\n\n if (clearOnInvalidation) {\n return this.clear({ invalidateDependencies });\n }\n\n if (invalidateDependencies) {\n this.calculationHelper.invalidateDependencies();\n }\n\n const { status, isStale, isUpdating } = this.state.get();\n if (status !== 'pending' && !isStale && !isUpdating) {\n this.stalePromise = this._value?.v;\n }\n\n this.state.set((state) => ({\n ...state,\n isStale: true,\n isUpdating: false,\n }));\n\n super.reset();\n }\n\n clear({ invalidateDependencies = true }: { invalidateDependencies?: boolean } = {}): void {\n if (invalidateDependencies) {\n this.calculationHelper.invalidateDependencies();\n }\n\n this.state.set({\n status: 'pending',\n isStale: true,\n isUpdating: false,\n });\n delete this.stalePromise;\n super.reset();\n }\n\n mapValue<S>(selector: Selector<T, S>): Cache<S>;\n\n mapValue<P extends Path<T>>(selector: P): Cache<Value<T, P>>;\n\n mapValue<S>(_selector: Selector<T, S> | Path<any>): Cache<S> {\n const selector = makeSelector(_selector);\n const derivedFromCache = {\n cache: this.derivedFromCache ? this.derivedFromCache.cache : this,\n selectors: this.derivedFromCache\n ? [...this.derivedFromCache.selectors, _selector]\n : [_selector],\n };\n const that = this;\n\n return new Cache(\n async function () {\n const value = await this.use(that);\n return selector(value);\n },\n {},\n derivedFromCache,\n );\n }\n\n protected watchPromise() {\n this.sub(\n async (promise) => {\n this.state.set((state) => ({\n ...state,\n isUpdating: true,\n }));\n\n this.setTimers();\n\n try {\n const value = await promise;\n\n if (promise !== this._value?.v) {\n return;\n }\n\n this.state.set({\n status: 'value',\n value,\n isStale: false,\n isUpdating: false,\n });\n delete this.stalePromise;\n this.setTimers();\n } catch (error) {\n if (promise !== this._value?.v) {\n return;\n }\n\n this.state.set({\n status: 'error',\n error,\n isStale: false,\n isUpdating: false,\n });\n delete this.stalePromise;\n this.setTimers();\n }\n },\n { passive: true },\n );\n }\n\n protected setTimers() {\n if (this.invalidationTimer) {\n clearTimeout(this.invalidationTimer);\n }\n this.invalidationTimer = undefined;\n\n const state = this.state.get();\n let { invalidateAfter = defaultOptions.invalidateAfter } = this.options;\n const ref = new WeakRef(this);\n\n if (state.status === 'pending') {\n return;\n }\n\n if (invalidateAfter instanceof Function) {\n invalidateAfter = invalidateAfter(state);\n }\n\n if (invalidateAfter !== null && invalidateAfter !== undefined) {\n this.invalidationTimer = setTimeout(\n () => ref?.deref()?.invalidate(),\n calcDuration(invalidateAfter),\n );\n }\n }\n\n protected watchFocus() {\n const { invalidateOnWindowFocus = defaultOptions.invalidateOnWindowFocus } = this.options;\n\n if (\n !invalidateOnWindowFocus ||\n typeof document === 'undefined' ||\n typeof document.addEventListener === 'undefined'\n ) {\n return;\n }\n\n const ref = new WeakRef(this);\n\n const onFocus = () => {\n const that = ref?.deref();\n if (!that) {\n document.removeEventListener('visibilitychange', onFocus);\n return;\n }\n\n if (!document.hidden) {\n that.invalidate();\n }\n };\n\n document.addEventListener('visibilitychange', onFocus);\n }\n}\n\nconst defaultOptions: CacheOptions<unknown> = {\n invalidateOnWindowFocus: true,\n invalidateOnActivation: true,\n clearUnusedAfter: { days: 1 },\n};\n\ntype CreateReturnType<T, Args extends any[]> = {\n (...args: Args): Cache<T>;\n invalidateAll: () => void;\n clearAll: () => void;\n} & ([] extends Args ? Cache<T> : {});\n\nfunction create<T, Args extends any[]>(\n cacheFunction: CacheFunction<T, Args>,\n options?: CacheOptions<T>,\n): CreateReturnType<T, Args> {\n const { clearUnusedAfter = defaultOptions.clearUnusedAfter, resourceGroup } = options ?? {};\n\n let baseInstance: CreateReturnType<T, Args> & Cache<T>;\n\n const instanceCache = new InstanceCache<Args, Cache<T>>(\n (...args: Args): Cache<T> => {\n if (args.length === 0 && baseInstance) {\n return baseInstance;\n }\n\n return new Cache(function () {\n return cacheFunction.apply(this, args);\n }, options);\n },\n clearUnusedAfter ? calcDuration(clearUnusedAfter) : undefined,\n );\n\n const get = (...args: Args) => {\n return instanceCache.get(...args);\n };\n\n const invalidateAll = () => {\n for (const instance of instanceCache.values()) {\n instance.invalidate();\n }\n };\n\n const clearAll = () => {\n for (const instance of instanceCache.values()) {\n instance.clear();\n }\n };\n\n const groups = Array.isArray(resourceGroup)\n ? resourceGroup\n : resourceGroup\n ? [resourceGroup]\n : [];\n for (const group of groups.concat(allResources)) {\n group.add({ invalidate: invalidateAll, clear: clearAll });\n }\n\n baseInstance = Object.assign(\n new Cache(\n function () {\n return cacheFunction.apply(this);\n },\n options,\n undefined,\n get,\n ),\n {\n invalidateAll,\n clearAll,\n },\n ) as CreateReturnType<T, Args> & Cache<T>;\n\n get(...([] as any));\n\n return baseInstance;\n}\n\nexport const createCache = Object.assign(create, {\n defaultOptions,\n});\n"],"names":["Store","createStore","makeSelector","calcDuration","resourceGroup","instanceCache","InstanceCache","allResources"],"mappings":";;;;;;;AA4BO,MAAM,cAAiBA,MAAAA,MAAkB;AAAA,EAW9C,YACE,QACgB,UAA2B,CAAA,GAC3B,kBAIhB,OACA;AACM,UAAA,QAAQ,SAAS,QAAW,KAAK;AAPvB,SAAA,UAAA;AACA,SAAA,mBAAA;AAblB,SAAS,QAAQC,kBAA2B;AAAA,MAC1C,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,YAAY;AAAA,IAAA,CACb;AAgBC,SAAK,aAAa,KAAK,WAAW,KAAK,IAAI;AAC3C,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AACjC,SAAK,WAAW,KAAK,SAAS,KAAK,IAAI;AAEvC,SAAK,aAAa;AAClB,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,IAAI,EAAE,SAAS,aAAa,mBAAmB,MAAM,IAAqB,IAAI;;AACtE,UAAA,WAAU,UAAK,WAAL,mBAAa;AAC7B,UAAM,eAAe,KAAK;AAGvB,QAAA,WAAW,iBAAiB,CAAC,WAAW,CAAC,gBACzC,WAAW,eAAe,CAAC,WAC5B,WAAW,SACX;AACA,WAAK,kBAAkB;AAEvB,UAAK,CAAC,WAAW,CAAC,gBAAiB,CAAC,kBAAkB;AACpD,eAAO,MAAM;MACf;AAAA,IACF;AAEI,QAAA,CAAC,WAAY,gBAAgB,kBAAmB;AAC3C,aAAA;AAAA,IACT;AAEO,WAAA;AAAA,EACT;AAAA,EAEA,WAAW,EAAE,yBAAyB,KAAK,IAA0C,CAAA,GAAI;;AACvF,UAAM,EAAE,mBAAmB,sBAAsB,eAAe,sBAC9D,KAAK;AAEP,QAAI,qBAAqB;AACvB,aAAO,KAAK,MAAM,EAAE,uBAAwB,CAAA;AAAA,IAC9C;AAEA,QAAI,wBAAwB;AAC1B,WAAK,kBAAkB;IACzB;AAEA,UAAM,EAAE,QAAQ,SAAS,WAAe,IAAA,KAAK,MAA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A,MACA;AAAA,IACF;AAAA,EAAA;AAGE,MAAA,GAAI,CAAA,CAAU;AAEX,SAAA;AACT;AAEa,MAAA,cAAc,OAAO,OAAO,QAAQ;AAAA,EAC/C;AACF,CAAC;;;"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
class ResourceGroup {
|
|
4
|
-
constructor(name) {
|
|
5
|
-
this.name = name;
|
|
6
|
-
this.refMap = /* @__PURE__ */ new WeakMap();
|
|
7
|
-
this.refSet = /* @__PURE__ */ new Set();
|
|
8
|
-
this.add = this.add.bind(this);
|
|
9
|
-
this.delete = this.delete.bind(this);
|
|
10
|
-
this.invalidateAll = this.invalidateAll.bind(this);
|
|
11
|
-
this.clearAll = this.clearAll.bind(this);
|
|
12
|
-
}
|
|
13
|
-
add(resource) {
|
|
14
|
-
const ref = new WeakRef(resource);
|
|
15
|
-
this.refMap.set(resource, ref);
|
|
16
|
-
this.refSet.add(ref);
|
|
17
|
-
}
|
|
18
|
-
delete(resource) {
|
|
19
|
-
const ref = this.refMap.get(resource);
|
|
20
|
-
if (ref) {
|
|
21
|
-
this.refMap.delete(resource);
|
|
22
|
-
this.refSet.delete(ref);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
invalidateAll() {
|
|
26
|
-
for (const ref of this.refSet) {
|
|
27
|
-
const resource = ref.deref();
|
|
28
|
-
if (resource) {
|
|
29
|
-
resource.invalidate();
|
|
30
|
-
} else {
|
|
31
|
-
this.refSet.delete(ref);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
clearAll() {
|
|
36
|
-
for (const ref of this.refSet) {
|
|
37
|
-
const resource = ref.deref();
|
|
38
|
-
if (resource) {
|
|
39
|
-
resource.clear();
|
|
40
|
-
} else {
|
|
41
|
-
this.refSet.delete(ref);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const allResources = new ResourceGroup();
|
|
47
|
-
function createResourceGroup(name) {
|
|
48
|
-
return new ResourceGroup(name);
|
|
49
|
-
}
|
|
50
|
-
exports.ResourceGroup = ResourceGroup;
|
|
51
|
-
exports.allResources = allResources;
|
|
52
|
-
exports.createResourceGroup = createResourceGroup;
|
|
53
|
-
//# sourceMappingURL=resourceGroup.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resourceGroup.cjs","sources":["../../../src/core/resourceGroup.ts"],"sourcesContent":["export interface Resource {\n invalidate(): void;\n clear(): void;\n}\n\nexport class ResourceGroup {\n private refMap = new WeakMap<Resource, WeakRef<Resource>>();\n\n private refSet = new Set<WeakRef<Resource>>();\n\n constructor(public readonly name?: string) {\n this.add = this.add.bind(this);\n this.delete = this.delete.bind(this);\n this.invalidateAll = this.invalidateAll.bind(this);\n this.clearAll = this.clearAll.bind(this);\n }\n\n add(resource: Resource) {\n const ref = new WeakRef(resource);\n this.refMap.set(resource, ref);\n this.refSet.add(ref);\n }\n\n delete(resource: Resource) {\n const ref = this.refMap.get(resource);\n if (ref) {\n this.refMap.delete(resource);\n this.refSet.delete(ref);\n }\n }\n\n invalidateAll() {\n for (const ref of this.refSet) {\n const resource = ref.deref();\n if (resource) {\n resource.invalidate();\n } else {\n this.refSet.delete(ref);\n }\n }\n }\n\n clearAll() {\n for (const ref of this.refSet) {\n const resource = ref.deref();\n if (resource) {\n resource.clear();\n } else {\n this.refSet.delete(ref);\n }\n }\n }\n}\n\nexport const allResources = new ResourceGroup();\n\nexport function createResourceGroup(name?: string) {\n return new ResourceGroup(name);\n}\n"],"names":[],"mappings":";;AAKO,MAAM,cAAc;AAAA,EAKzB,YAA4B,MAAe;AAAf,SAAA,OAAA;AAJpB,SAAA,6BAAa;AAEb,SAAA,6BAAa;AAGnB,SAAK,MAAM,KAAK,IAAI,KAAK,IAAI;AAC7B,SAAK,SAAS,KAAK,OAAO,KAAK,IAAI;AACnC,SAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;AACjD,SAAK,WAAW,KAAK,SAAS,KAAK,IAAI;AAAA,EACzC;AAAA,EAEA,IAAI,UAAoB;AAChB,UAAA,MAAM,IAAI,QAAQ,QAAQ;AAC3B,SAAA,OAAO,IAAI,UAAU,GAAG;AACxB,SAAA,OAAO,IAAI,GAAG;AAAA,EACrB;AAAA,EAEA,OAAO,UAAoB;AACzB,UAAM,MAAM,KAAK,OAAO,IAAI,QAAQ;AACpC,QAAI,KAAK;AACF,WAAA,OAAO,OAAO,QAAQ;AACtB,WAAA,OAAO,OAAO,GAAG;AAAA,IACxB;AAAA,EACF;AAAA,EAEA,gBAAgB;AACH,eAAA,OAAO,KAAK,QAAQ;AACvB,YAAA,WAAW,IAAI;AACrB,UAAI,UAAU;AACZ,iBAAS,WAAW;AAAA,MAAA,OACf;AACA,aAAA,OAAO,OAAO,GAAG;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,WAAW;AACE,eAAA,OAAO,KAAK,QAAQ;AACvB,YAAA,WAAW,IAAI;AACrB,UAAI,UAAU;AACZ,iBAAS,MAAM;AAAA,MAAA,OACV;AACA,aAAA,OAAO,OAAO,GAAG;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AACF;AAEa,MAAA,eAAe,IAAI,cAAc;AAEvC,SAAS,oBAAoB,MAAe;AAC1C,SAAA,IAAI,cAAc,IAAI;AAC/B;;;;"}
|