cross-state 0.6.7 → 0.6.8

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 (141) hide show
  1. package/dist/cjs/hash.cjs +712 -0
  2. package/dist/cjs/hash.cjs.map +1 -0
  3. package/dist/cjs/immer.cjs +7 -2
  4. package/dist/cjs/immer.cjs.map +1 -1
  5. package/dist/cjs/index.cjs +341 -19
  6. package/dist/cjs/index.cjs.map +1 -1
  7. package/dist/cjs/react.cjs +289 -11
  8. package/dist/cjs/react.cjs.map +1 -1
  9. package/dist/es/hash.mjs +713 -0
  10. package/dist/es/hash.mjs.map +1 -0
  11. package/dist/es/{immer/immerActions.js → immer.mjs} +1 -1
  12. package/dist/es/immer.mjs.map +1 -0
  13. package/dist/es/{core/cache.js → index.mjs} +126 -8
  14. package/dist/es/index.mjs.map +1 -0
  15. package/dist/es/react.mjs +292 -0
  16. package/dist/es/react.mjs.map +1 -0
  17. package/package.json +1 -1
  18. package/dist/cjs/_virtual/use-sync-external-store-with-selector.development.cjs +0 -103
  19. package/dist/cjs/_virtual/use-sync-external-store-with-selector.development.cjs.map +0 -1
  20. package/dist/cjs/_virtual/use-sync-external-store-with-selector.development2.cjs +0 -5
  21. package/dist/cjs/_virtual/use-sync-external-store-with-selector.development2.cjs.map +0 -1
  22. package/dist/cjs/_virtual/use-sync-external-store-with-selector.production.min.cjs +0 -71
  23. package/dist/cjs/_virtual/use-sync-external-store-with-selector.production.min.cjs.map +0 -1
  24. package/dist/cjs/_virtual/use-sync-external-store-with-selector.production.min2.cjs +0 -5
  25. package/dist/cjs/_virtual/use-sync-external-store-with-selector.production.min2.cjs.map +0 -1
  26. package/dist/cjs/_virtual/with-selector.cjs +0 -12
  27. package/dist/cjs/_virtual/with-selector.cjs.map +0 -1
  28. package/dist/cjs/_virtual/with-selector2.cjs +0 -13
  29. package/dist/cjs/_virtual/with-selector2.cjs.map +0 -1
  30. package/dist/cjs/core/cache.cjs +0 -227
  31. package/dist/cjs/core/cache.cjs.map +0 -1
  32. package/dist/cjs/core/resourceGroup.cjs +0 -53
  33. package/dist/cjs/core/resourceGroup.cjs.map +0 -1
  34. package/dist/cjs/core/store.cjs +0 -259
  35. package/dist/cjs/core/store.cjs.map +0 -1
  36. package/dist/cjs/immer/immerActions.cjs +0 -10
  37. package/dist/cjs/immer/immerActions.cjs.map +0 -1
  38. package/dist/cjs/lib/calcDuration.cjs +0 -9
  39. package/dist/cjs/lib/calcDuration.cjs.map +0 -1
  40. package/dist/cjs/lib/calculationHelper.cjs +0 -140
  41. package/dist/cjs/lib/calculationHelper.cjs.map +0 -1
  42. package/dist/cjs/lib/callable.cjs +0 -11
  43. package/dist/cjs/lib/callable.cjs.map +0 -1
  44. package/dist/cjs/lib/clone.cjs +0 -19
  45. package/dist/cjs/lib/clone.cjs.map +0 -1
  46. package/dist/cjs/lib/debounce.cjs +0 -28
  47. package/dist/cjs/lib/debounce.cjs.map +0 -1
  48. package/dist/cjs/lib/equals.cjs +0 -5
  49. package/dist/cjs/lib/equals.cjs.map +0 -1
  50. package/dist/cjs/lib/forwardError.cjs +0 -9
  51. package/dist/cjs/lib/forwardError.cjs.map +0 -1
  52. package/dist/cjs/lib/hash.cjs +0 -19
  53. package/dist/cjs/lib/hash.cjs.map +0 -1
  54. package/dist/cjs/lib/instanceCache.cjs +0 -68
  55. package/dist/cjs/lib/instanceCache.cjs.map +0 -1
  56. package/dist/cjs/lib/makeSelector.cjs +0 -14
  57. package/dist/cjs/lib/makeSelector.cjs.map +0 -1
  58. package/dist/cjs/lib/propAccess.cjs +0 -66
  59. package/dist/cjs/lib/propAccess.cjs.map +0 -1
  60. package/dist/cjs/lib/queue.cjs +0 -61
  61. package/dist/cjs/lib/queue.cjs.map +0 -1
  62. package/dist/cjs/lib/standardMethods.cjs +0 -78
  63. package/dist/cjs/lib/standardMethods.cjs.map +0 -1
  64. package/dist/cjs/lib/throttle.cjs +0 -25
  65. package/dist/cjs/lib/throttle.cjs.map +0 -1
  66. package/dist/cjs/lib/trackingProxy.cjs +0 -39
  67. package/dist/cjs/lib/trackingProxy.cjs.map +0 -1
  68. package/dist/cjs/react/read.cjs +0 -15
  69. package/dist/cjs/react/read.cjs.map +0 -1
  70. package/dist/cjs/react/storeScope.cjs +0 -31
  71. package/dist/cjs/react/storeScope.cjs.map +0 -1
  72. package/dist/cjs/react/useCache.cjs +0 -31
  73. package/dist/cjs/react/useCache.cjs.map +0 -1
  74. package/dist/cjs/react/useProp.cjs +0 -9
  75. package/dist/cjs/react/useProp.cjs.map +0 -1
  76. package/dist/cjs/react/useStore.cjs +0 -51
  77. package/dist/cjs/react/useStore.cjs.map +0 -1
  78. package/dist/es/_virtual/use-sync-external-store-with-selector.development.js +0 -103
  79. package/dist/es/_virtual/use-sync-external-store-with-selector.development.js.map +0 -1
  80. package/dist/es/_virtual/use-sync-external-store-with-selector.development2.js +0 -5
  81. package/dist/es/_virtual/use-sync-external-store-with-selector.development2.js.map +0 -1
  82. package/dist/es/_virtual/use-sync-external-store-with-selector.production.min.js +0 -71
  83. package/dist/es/_virtual/use-sync-external-store-with-selector.production.min.js.map +0 -1
  84. package/dist/es/_virtual/use-sync-external-store-with-selector.production.min2.js +0 -5
  85. package/dist/es/_virtual/use-sync-external-store-with-selector.production.min2.js.map +0 -1
  86. package/dist/es/_virtual/with-selector.js +0 -11
  87. package/dist/es/_virtual/with-selector.js.map +0 -1
  88. package/dist/es/_virtual/with-selector2.js +0 -14
  89. package/dist/es/_virtual/with-selector2.js.map +0 -1
  90. package/dist/es/core/cache.js.map +0 -1
  91. package/dist/es/core/resourceGroup.js +0 -53
  92. package/dist/es/core/resourceGroup.js.map +0 -1
  93. package/dist/es/core/store.js +0 -259
  94. package/dist/es/core/store.js.map +0 -1
  95. package/dist/es/immer/immerActions.js.map +0 -1
  96. package/dist/es/immer.js +0 -5
  97. package/dist/es/immer.js.map +0 -1
  98. package/dist/es/index.js +0 -22
  99. package/dist/es/index.js.map +0 -1
  100. package/dist/es/lib/calcDuration.js +0 -9
  101. package/dist/es/lib/calcDuration.js.map +0 -1
  102. package/dist/es/lib/calculationHelper.js +0 -140
  103. package/dist/es/lib/calculationHelper.js.map +0 -1
  104. package/dist/es/lib/callable.js +0 -11
  105. package/dist/es/lib/callable.js.map +0 -1
  106. package/dist/es/lib/clone.js +0 -19
  107. package/dist/es/lib/clone.js.map +0 -1
  108. package/dist/es/lib/debounce.js +0 -28
  109. package/dist/es/lib/debounce.js.map +0 -1
  110. package/dist/es/lib/equals.js +0 -5
  111. package/dist/es/lib/equals.js.map +0 -1
  112. package/dist/es/lib/forwardError.js +0 -9
  113. package/dist/es/lib/forwardError.js.map +0 -1
  114. package/dist/es/lib/hash.js +0 -19
  115. package/dist/es/lib/hash.js.map +0 -1
  116. package/dist/es/lib/instanceCache.js +0 -68
  117. package/dist/es/lib/instanceCache.js.map +0 -1
  118. package/dist/es/lib/makeSelector.js +0 -14
  119. package/dist/es/lib/makeSelector.js.map +0 -1
  120. package/dist/es/lib/propAccess.js +0 -66
  121. package/dist/es/lib/propAccess.js.map +0 -1
  122. package/dist/es/lib/queue.js +0 -61
  123. package/dist/es/lib/queue.js.map +0 -1
  124. package/dist/es/lib/standardMethods.js +0 -78
  125. package/dist/es/lib/standardMethods.js.map +0 -1
  126. package/dist/es/lib/throttle.js +0 -25
  127. package/dist/es/lib/throttle.js.map +0 -1
  128. package/dist/es/lib/trackingProxy.js +0 -39
  129. package/dist/es/lib/trackingProxy.js.map +0 -1
  130. package/dist/es/react/read.js +0 -15
  131. package/dist/es/react/read.js.map +0 -1
  132. package/dist/es/react/storeScope.js +0 -31
  133. package/dist/es/react/storeScope.js.map +0 -1
  134. package/dist/es/react/useCache.js +0 -31
  135. package/dist/es/react/useCache.js.map +0 -1
  136. package/dist/es/react/useProp.js +0 -9
  137. package/dist/es/react/useProp.js.map +0 -1
  138. package/dist/es/react/useStore.js +0 -51
  139. package/dist/es/react/useStore.js.map +0 -1
  140. package/dist/es/react.js +0 -14
  141. package/dist/es/react.js.map +0 -1
@@ -1,103 +0,0 @@
1
- import { __exports as useSyncExternalStoreWithSelector_development } from "./use-sync-external-store-with-selector.development2.js";
2
- import require$$0 from "react";
3
- /**
4
- * @license React
5
- * use-sync-external-store-with-selector.development.js
6
- *
7
- * Copyright (c) Facebook, Inc. and its affiliates.
8
- *
9
- * This source code is licensed under the MIT license found in the
10
- * LICENSE file in the root directory of this source tree.
11
- */
12
- var hasRequiredUseSyncExternalStoreWithSelector_development;
13
- function requireUseSyncExternalStoreWithSelector_development() {
14
- if (hasRequiredUseSyncExternalStoreWithSelector_development)
15
- return useSyncExternalStoreWithSelector_development;
16
- hasRequiredUseSyncExternalStoreWithSelector_development = 1;
17
- if (process.env.NODE_ENV !== "production") {
18
- (function() {
19
- if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
20
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
21
- }
22
- var React = require$$0;
23
- function is(x, y) {
24
- return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
25
- }
26
- var objectIs = typeof Object.is === "function" ? Object.is : is;
27
- var useSyncExternalStore = React.useSyncExternalStore;
28
- var useRef = React.useRef, useEffect = React.useEffect, useMemo = React.useMemo, useDebugValue = React.useDebugValue;
29
- function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
30
- var instRef = useRef(null);
31
- var inst;
32
- if (instRef.current === null) {
33
- inst = {
34
- hasValue: false,
35
- value: null
36
- };
37
- instRef.current = inst;
38
- } else {
39
- inst = instRef.current;
40
- }
41
- var _useMemo = useMemo(function() {
42
- var hasMemo = false;
43
- var memoizedSnapshot;
44
- var memoizedSelection;
45
- var memoizedSelector = function(nextSnapshot) {
46
- if (!hasMemo) {
47
- hasMemo = true;
48
- memoizedSnapshot = nextSnapshot;
49
- var _nextSelection = selector(nextSnapshot);
50
- if (isEqual !== void 0) {
51
- if (inst.hasValue) {
52
- var currentSelection = inst.value;
53
- if (isEqual(currentSelection, _nextSelection)) {
54
- memoizedSelection = currentSelection;
55
- return currentSelection;
56
- }
57
- }
58
- }
59
- memoizedSelection = _nextSelection;
60
- return _nextSelection;
61
- }
62
- var prevSnapshot = memoizedSnapshot;
63
- var prevSelection = memoizedSelection;
64
- if (objectIs(prevSnapshot, nextSnapshot)) {
65
- return prevSelection;
66
- }
67
- var nextSelection = selector(nextSnapshot);
68
- if (isEqual !== void 0 && isEqual(prevSelection, nextSelection)) {
69
- return prevSelection;
70
- }
71
- memoizedSnapshot = nextSnapshot;
72
- memoizedSelection = nextSelection;
73
- return nextSelection;
74
- };
75
- var maybeGetServerSnapshot = getServerSnapshot === void 0 ? null : getServerSnapshot;
76
- var getSnapshotWithSelector = function() {
77
- return memoizedSelector(getSnapshot());
78
- };
79
- var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? void 0 : function() {
80
- return memoizedSelector(maybeGetServerSnapshot());
81
- };
82
- return [getSnapshotWithSelector, getServerSnapshotWithSelector];
83
- }, [getSnapshot, getServerSnapshot, selector, isEqual]), getSelection = _useMemo[0], getServerSelection = _useMemo[1];
84
- var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
85
- useEffect(function() {
86
- inst.hasValue = true;
87
- inst.value = value;
88
- }, [value]);
89
- useDebugValue(value);
90
- return value;
91
- }
92
- useSyncExternalStoreWithSelector_development.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;
93
- if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function") {
94
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
95
- }
96
- })();
97
- }
98
- return useSyncExternalStoreWithSelector_development;
99
- }
100
- export {
101
- requireUseSyncExternalStoreWithSelector_development as __require
102
- };
103
- //# sourceMappingURL=use-sync-external-store-with-selector.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-sync-external-store-with-selector.development.js","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":[],"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,IAAI,MAAM,IAAI,MAAM,MAAM,KAAK,MAAM;AAAA,MAEpE;AAED,UAAI,WAAW,OAAO,OAAO,OAAO,aAAa,OAAO,KAAK;AAE7D,UAAI,uBAAuB,MAAM;AAIjC,UAAI,SAAS,MAAM,QACf,YAAY,MAAM,WAClB,UAAU,MAAM,SAChB,gBAAgB,MAAM;AAE1B,eAAS,iCAAiC,WAAW,aAAa,mBAAmB,UAAU,SAAS;AAEtG,YAAI,UAAU,OAAO,IAAI;AACzB,YAAI;AAEJ,YAAI,QAAQ,YAAY,MAAM;AAC5B,iBAAO;AAAA,YACL,UAAU;AAAA,YACV,OAAO;AAAA,UACb;AACI,kBA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AAC;AACV,sBAAc,KAAK;AACnB,eAAO;AAAA,MACR;AAEuC,mDAAA,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
- var useSyncExternalStoreWithSelector_development = {};
2
- export {
3
- useSyncExternalStoreWithSelector_development as __exports
4
- };
5
- //# sourceMappingURL=use-sync-external-store-with-selector.development2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-sync-external-store-with-selector.development2.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1,71 +0,0 @@
1
- import { __exports as useSyncExternalStoreWithSelector_production_min } from "./use-sync-external-store-with-selector.production.min2.js";
2
- import require$$0 from "react";
3
- /**
4
- * @license React
5
- * use-sync-external-store-with-selector.production.min.js
6
- *
7
- * Copyright (c) Facebook, Inc. and its affiliates.
8
- *
9
- * This source code is licensed under the MIT license found in the
10
- * LICENSE file in the root directory of this source tree.
11
- */
12
- var hasRequiredUseSyncExternalStoreWithSelector_production_min;
13
- function requireUseSyncExternalStoreWithSelector_production_min() {
14
- if (hasRequiredUseSyncExternalStoreWithSelector_production_min)
15
- return useSyncExternalStoreWithSelector_production_min;
16
- hasRequiredUseSyncExternalStoreWithSelector_production_min = 1;
17
- var g = require$$0;
18
- function n(a, b) {
19
- return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
20
- }
21
- var p = "function" === typeof Object.is ? Object.is : n, q = g.useSyncExternalStore, r = g.useRef, t = g.useEffect, u = g.useMemo, v = g.useDebugValue;
22
- useSyncExternalStoreWithSelector_production_min.useSyncExternalStoreWithSelector = function(a, b, e, l, h) {
23
- var c = r(null);
24
- if (null === c.current) {
25
- var f = { hasValue: false, value: null };
26
- c.current = f;
27
- } else
28
- f = c.current;
29
- c = u(function() {
30
- function a2(a3) {
31
- if (!c2) {
32
- c2 = true;
33
- d2 = a3;
34
- a3 = l(a3);
35
- if (void 0 !== h && f.hasValue) {
36
- var b2 = f.value;
37
- if (h(b2, a3))
38
- return k = b2;
39
- }
40
- return k = a3;
41
- }
42
- b2 = k;
43
- if (p(d2, a3))
44
- return b2;
45
- var e2 = l(a3);
46
- if (void 0 !== h && h(b2, e2))
47
- return b2;
48
- d2 = a3;
49
- return k = e2;
50
- }
51
- var c2 = false, d2, k, m = void 0 === e ? null : e;
52
- return [function() {
53
- return a2(b());
54
- }, null === m ? void 0 : function() {
55
- return a2(m());
56
- }];
57
- }, [b, e, l, h]);
58
- var d = q(a, c[0], c[1]);
59
- t(function() {
60
- f.hasValue = true;
61
- f.value = d;
62
- }, [d]);
63
- v(d);
64
- return d;
65
- };
66
- return useSyncExternalStoreWithSelector_production_min;
67
- }
68
- export {
69
- requireUseSyncExternalStoreWithSelector_production_min as __require
70
- };
71
- //# sourceMappingURL=use-sync-external-store-with-selector.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-sync-external-store-with-selector.production.min.js","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":["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;AACrN,kDAAA,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,eAASA,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
- var useSyncExternalStoreWithSelector_production_min = {};
2
- export {
3
- useSyncExternalStoreWithSelector_production_min as __exports
4
- };
5
- //# sourceMappingURL=use-sync-external-store-with-selector.production.min2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-sync-external-store-with-selector.production.min2.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1,11 +0,0 @@
1
- import { __module as withSelector, exports as withSelectorExports } from "./with-selector2.js";
2
- import { __require as requireUseSyncExternalStoreWithSelector_production_min } from "./use-sync-external-store-with-selector.production.min.js";
3
- import { __require as requireUseSyncExternalStoreWithSelector_development } from "./use-sync-external-store-with-selector.development.js";
4
- (function(module) {
5
- if (process.env.NODE_ENV === "production") {
6
- module.exports = requireUseSyncExternalStoreWithSelector_production_min();
7
- } else {
8
- module.exports = requireUseSyncExternalStoreWithSelector_development();
9
- }
10
- })(withSelector);
11
- //# sourceMappingURL=with-selector.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"with-selector.js","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":["require$$0","require$$1"],"mappings":";;;;AAEA,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,WAAA,UAAiBA;EACnB,OAAO;AACL,WAAA,UAAiBC;EACnB;;"}
@@ -1,14 +0,0 @@
1
- var withSelectorExports = {};
2
- var withSelector = {
3
- get exports() {
4
- return withSelectorExports;
5
- },
6
- set exports(v) {
7
- withSelectorExports = v;
8
- }
9
- };
10
- export {
11
- withSelector as __module,
12
- withSelectorExports as exports
13
- };
14
- //# sourceMappingURL=with-selector2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"with-selector2.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"cache.js","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":[],"mappings":";;;;;AA4BO,MAAM,cAAiB,MAAkB;AAAA,EAW9C,YACE,QACgB,UAA2B,CAAA,GAC3B,kBAIhB,OACA;AACM,UAAA,QAA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et = /* @__PURE__ */ new Set();
6
- this.add = this.add.bind(this);
7
- this.delete = this.delete.bind(this);
8
- this.invalidateAll = this.invalidateAll.bind(this);
9
- this.clearAll = this.clearAll.bind(this);
10
- }
11
- add(resource) {
12
- const ref = new WeakRef(resource);
13
- this.refMap.set(resource, ref);
14
- this.refSet.add(ref);
15
- }
16
- delete(resource) {
17
- const ref = this.refMap.get(resource);
18
- if (ref) {
19
- this.refMap.delete(resource);
20
- this.refSet.delete(ref);
21
- }
22
- }
23
- invalidateAll() {
24
- for (const ref of this.refSet) {
25
- const resource = ref.deref();
26
- if (resource) {
27
- resource.invalidate();
28
- } else {
29
- this.refSet.delete(ref);
30
- }
31
- }
32
- }
33
- clearAll() {
34
- for (const ref of this.refSet) {
35
- const resource = ref.deref();
36
- if (resource) {
37
- resource.clear();
38
- } else {
39
- this.refSet.delete(ref);
40
- }
41
- }
42
- }
43
- }
44
- const allResources = new ResourceGroup();
45
- function createResourceGroup(name) {
46
- return new ResourceGroup(name);
47
- }
48
- export {
49
- ResourceGroup,
50
- allResources,
51
- createResourceGroup
52
- };
53
- //# sourceMappingURL=resourceGroup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resourceGroup.js","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;"}
@@ -1,259 +0,0 @@
1
- import { calcDuration } from "../lib/calcDuration.js";
2
- import { CalculationHelper } from "../lib/calculationHelper.js";
3
- import { Callable } from "../lib/callable.js";
4
- import { debounce } from "../lib/debounce.js";
5
- import { defaultEquals } from "../lib/equals.js";
6
- import { forwardError } from "../lib/forwardError.js";
7
- import { makeSelector } from "../lib/makeSelector.js";
8
- import { get, set } from "../lib/propAccess.js";
9
- import { mapMethods, setMethods, arrayMethods, recordMethods } from "../lib/standardMethods.js";
10
- import { throttle } from "../lib/throttle.js";
11
- const noop = () => void 0;
12
- class Store extends Callable {
13
- constructor(getter, options = {}, derivedFrom, _call = () => void 0) {
14
- super(_call);
15
- this.getter = getter;
16
- this.options = options;
17
- this.derivedFrom = derivedFrom;
18
- this._call = _call;
19
- this.listeners = /* @__PURE__ */ new Map();
20
- this.effects = /* @__PURE__ */ new Map();
21
- this.notifyId = {};
22
- this.calculationHelper = new CalculationHelper({
23
- calculate: ({ use }) => {
24
- if (this.getter instanceof Function) {
25
- const value = this.getter.apply({ use }, [{ use }]);
26
- this._value = { v: value };
27
- this.notify();
28
- }
29
- },
30
- addEffect: this.addEffect.bind(this),
31
- onInvalidate: this.reset.bind(this)
32
- });
33
- this.get = this.get.bind(this);
34
- this.set = this.set.bind(this);
35
- this.sub = this.sub.bind(this);
36
- this.once = this.once.bind(this);
37
- this.map = this.map.bind(this);
38
- this.addEffect = this.addEffect.bind(this);
39
- this.isActive = this.isActive.bind(this);
40
- if (!(getter instanceof Function)) {
41
- this._value = { v: getter };
42
- }
43
- }
44
- get() {
45
- this.calculationHelper.check();
46
- if (!this._value) {
47
- this.calculationHelper.execute();
48
- return this.get();
49
- }
50
- return this._value.v;
51
- }
52
- set(...args) {
53
- const path = args.length > 1 ? args[0] : [];
54
- let update = args.length > 1 ? args[1] : args[0];
55
- if (update instanceof Function) {
56
- const before = this.get();
57
- const valueBefore = get(before, path);
58
- const valueAfter = update(valueBefore);
59
- update = set(before, path, valueAfter);
60
- } else if (path.length > 0) {
61
- update = set(this.get(), path, update);
62
- }
63
- if (this.derivedFrom && this.derivedFrom.selectors.every((selector) => typeof selector === "string")) {
64
- const derivationPath = this.derivedFrom.selectors.join(".");
65
- this.derivedFrom.store.set((before) => set(before, derivationPath, update));
66
- return;
67
- }
68
- if (this.derivedFrom) {
69
- throw new TypeError(
70
- "Can only updated computed stores that are derived from other stores using string selectors"
71
- );
72
- }
73
- this._value = { v: update };
74
- this.notify();
75
- }
76
- reset() {
77
- this._value = void 0;
78
- if (this.isActive()) {
79
- this.calculationHelper.execute();
80
- }
81
- }
82
- sub(listener, options) {
83
- var _a;
84
- const {
85
- passive,
86
- runNow = true,
87
- throttle: throttleOption,
88
- debounce: debounceOption,
89
- equals = defaultEquals
90
- } = options ?? {};
91
- let compareToValue = (_a = this._value) == null ? void 0 : _a.v;
92
- let previousValue;
93
- let hasRun = false;
94
- let innerListener = (force) => {
95
- if (!this._value) {
96
- return;
97
- }
98
- const value = this._value.v;
99
- if (!force && equals(value, compareToValue)) {
100
- return;
101
- }
102
- compareToValue = value;
103
- const _previousValue = previousValue;
104
- previousValue = value;
105
- hasRun = true;
106
- try {
107
- listener(value, _previousValue);
108
- } catch (error) {
109
- forwardError(error);
110
- }
111
- };
112
- if (throttleOption) {
113
- innerListener = throttle(innerListener, throttleOption);
114
- } else if (debounceOption) {
115
- innerListener = debounce(innerListener, debounceOption);
116
- }
117
- this.listeners.set(innerListener, !passive);
118
- if (!passive) {
119
- this.onSubscribe();
120
- }
121
- if (runNow && !hasRun) {
122
- innerListener(true);
123
- }
124
- return () => {
125
- this.listeners.delete(innerListener);
126
- if (!passive) {
127
- this.onUnsubscribe();
128
- }
129
- };
130
- }
131
- once(condition = (value) => !!value) {
132
- return new Promise((resolve) => {
133
- let stopped = false;
134
- const cancel = this.sub(
135
- (value) => {
136
- if (stopped || condition && !condition(value)) {
137
- return;
138
- }
139
- resolve(value);
140
- stopped = true;
141
- setTimeout(() => cancel());
142
- },
143
- {
144
- runNow: !!condition
145
- }
146
- );
147
- });
148
- }
149
- map(_selector, options) {
150
- const selector = makeSelector(_selector);
151
- const derivedFrom = {
152
- store: this.derivedFrom ? this.derivedFrom.store : this,
153
- selectors: this.derivedFrom ? [...this.derivedFrom.selectors, _selector] : [_selector]
154
- };
155
- return new Store(
156
- ({ use }) => {
157
- return selector(use(this, options));
158
- },
159
- this.options,
160
- derivedFrom
161
- );
162
- }
163
- /** Add an effect that will be executed when the store becomes active, which means when it has at least one subscriber.
164
- * @param effect
165
- * If there is already a subscriber, the effect will be executed immediately.
166
- * Otherweise it will be executed as soon as the first subscription is created.
167
- * Every time all subscriptions are removed and the first is created again, the effect will be executed again.
168
- * @param retain
169
- * If provided, delay tearing down effects when the last subscriber is removed. This is useful if a short gap in subscriber coverage is supposed to be ignored. E.g. when switching pages, the old page might unsubscribe, while the new page subscribes immediately after.
170
- * @returns
171
- * The effect can return a teardown callback, which will be executed when the last subscription is removed and potentially the ratain time has passed.
172
- */
173
- addEffect(effect, retain) {
174
- this.effects.set(effect, {
175
- handle: this.isActive() ? effect() ?? noop : void 0,
176
- retain: retain !== void 0 ? calcDuration(retain) : void 0
177
- });
178
- return () => {
179
- const { handle, timeout } = this.effects.get(effect) ?? {};
180
- handle == null ? void 0 : handle();
181
- if (timeout !== void 0) {
182
- clearTimeout(timeout);
183
- }
184
- this.effects.delete(effect);
185
- };
186
- }
187
- /** Return whether the store is currently active, which means whether it has at least one subscriber. */
188
- isActive() {
189
- return [...this.listeners.values()].some(Boolean);
190
- }
191
- onSubscribe() {
192
- if ([...this.listeners.values()].filter(Boolean).length > 1)
193
- return;
194
- for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {
195
- if (timeout !== void 0) {
196
- clearTimeout(timeout);
197
- }
198
- this.effects.set(effect, {
199
- handle: handle ?? effect() ?? noop,
200
- retain,
201
- timeout: void 0
202
- });
203
- }
204
- }
205
- onUnsubscribe() {
206
- if ([...this.listeners.values()].some(Boolean))
207
- return;
208
- for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {
209
- if (!retain) {
210
- handle == null ? void 0 : handle();
211
- }
212
- if (timeout !== void 0) {
213
- clearTimeout(timeout);
214
- }
215
- this.effects.set(effect, {
216
- handle: retain ? handle : void 0,
217
- retain,
218
- timeout: retain && handle ? setTimeout(handle, retain) : void 0
219
- });
220
- }
221
- }
222
- notify() {
223
- const n = {};
224
- this.notifyId = n;
225
- const snapshot = [...this.listeners.keys()];
226
- for (const listener of snapshot) {
227
- listener();
228
- if (n !== this.notifyId)
229
- break;
230
- }
231
- }
232
- }
233
- const defaultOptions = {};
234
- function create(initialState, options) {
235
- const store = new Store(initialState, options);
236
- if (initialState instanceof Function) {
237
- return store;
238
- }
239
- let methods = options == null ? void 0 : options.methods;
240
- if (initialState instanceof Map) {
241
- methods = { ...mapMethods, ...methods };
242
- } else if (initialState instanceof Set) {
243
- methods = { ...setMethods, ...methods };
244
- } else if (Array.isArray(initialState)) {
245
- methods = { ...arrayMethods, ...methods };
246
- } else if (initialState instanceof Object) {
247
- methods = { ...recordMethods, ...methods };
248
- }
249
- const boundMethods = Object.fromEntries(
250
- Object.entries(methods ?? {}).filter(([name]) => !(name in store)).map(([name, action]) => [name, action.bind(store)])
251
- );
252
- return Object.assign(store, boundMethods);
253
- }
254
- const createStore = Object.assign(create, { defaultOptions });
255
- export {
256
- Store,
257
- createStore
258
- };
259
- //# sourceMappingURL=store.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"store.js","sources":["../../../src/core/store.ts"],"sourcesContent":["import type {\n Cancel,\n Duration,\n Effect,\n Listener,\n Selector,\n SubscribeOptions,\n Update,\n Use,\n UseOptions,\n} from './commonTypes';\nimport { calcDuration } from '@lib/calcDuration';\nimport { CalculationHelper } from '@lib/calculationHelper';\nimport { Callable } from '@lib/callable';\nimport { debounce } from '@lib/debounce';\nimport { defaultEquals } from '@lib/equals';\nimport { forwardError } from '@lib/forwardError';\nimport { makeSelector } from '@lib/makeSelector';\nimport type { Path, Value } from '@lib/path';\nimport { get, set } from '@lib/propAccess';\nimport { arrayMethods, mapMethods, recordMethods, setMethods } from '@lib/standardMethods';\nimport { throttle } from '@lib/throttle';\n\nexport type StoreMethods = Record<string, (...args: any[]) => any>;\n\nexport type BoundStoreMethods<T, Methods extends StoreMethods> = Methods &\n ThisType<Store<T> & Methods>;\n\nexport interface StoreOptions {\n retain?: number;\n}\n\nexport interface StoreOptionsWithMethods<T, Methods extends StoreMethods> extends StoreOptions {\n methods?: Methods & ThisType<Store<T> & Methods & StandardMethods<T>>;\n}\n\nexport type Calculate<T> = (this: { use: Use }, fns: { use: Use }) => T;\n\ntype StandardMethods<T> = T extends Map<any, any>\n ? typeof mapMethods\n : T extends Set<any>\n ? typeof setMethods\n : T extends Array<any>\n ? typeof arrayMethods\n : T extends Record<any, any>\n ? typeof recordMethods\n : Record<string, never>;\n\ntype StoreWithMethods<T, Methods extends StoreMethods> = Store<T> &\n Omit<BoundStoreMethods<T, Methods>, keyof Store<T>> &\n StandardMethods<T>;\n\nconst noop = () => undefined;\n\nexport class Store<T> extends Callable<any, any> {\n protected _value?: { v: T };\n\n protected listeners = new Map<Listener, boolean>();\n\n protected effects = new Map<\n Effect,\n { handle?: Cancel; retain?: number; timeout?: ReturnType<typeof setTimeout> }\n >();\n\n protected notifyId = {};\n\n protected calculationHelper = new CalculationHelper({\n calculate: ({ use }) => {\n if (this.getter instanceof Function) {\n const value = this.getter.apply({ use }, [{ use }]);\n this._value = { v: value };\n this.notify();\n }\n },\n\n addEffect: this.addEffect.bind(this),\n onInvalidate: this.reset.bind(this),\n });\n\n constructor(\n public readonly getter: T | Calculate<T>,\n public readonly options: StoreOptions = {},\n public readonly derivedFrom?: {\n store: Store<any>;\n selectors: (Selector<any, any> | Path<any>)[];\n },\n protected readonly _call: (...args: any[]) => any = () => undefined,\n ) {\n super(_call);\n this.get = this.get.bind(this);\n this.set = this.set.bind(this);\n this.sub = this.sub.bind(this);\n this.once = this.once.bind(this);\n this.map = this.map.bind(this);\n this.addEffect = this.addEffect.bind(this);\n this.isActive = this.isActive.bind(this);\n\n if (!(getter instanceof Function)) {\n this._value = { v: getter };\n }\n }\n\n get(): T {\n this.calculationHelper.check();\n\n if (!this._value) {\n this.calculationHelper.execute();\n return this.get();\n }\n\n return this._value.v;\n }\n\n set(update: Update<T>): void;\n\n set<P extends Path<T>>(path: P, update: Update<Value<T, P>>): void;\n\n set(...args: any[]): void {\n const path: any = args.length > 1 ? args[0] : [];\n let update: Update<any> = args.length > 1 ? args[1] : args[0];\n\n if (update instanceof Function) {\n const before = this.get();\n const valueBefore = get(before, path);\n const valueAfter = update(valueBefore);\n update = set(before, path, valueAfter);\n } else if (path.length > 0) {\n update = set(this.get(), path, update);\n }\n\n if (\n this.derivedFrom &&\n this.derivedFrom.selectors.every((selector) => typeof selector === 'string')\n ) {\n const derivationPath = this.derivedFrom.selectors.join('.');\n this.derivedFrom.store.set((before: any) => set<any, any>(before, derivationPath, update));\n return;\n }\n\n if (this.derivedFrom) {\n throw new TypeError(\n 'Can only updated computed stores that are derived from other stores using string selectors',\n );\n }\n\n this._value = { v: update };\n this.notify();\n }\n\n protected reset() {\n this._value = undefined;\n\n if (this.isActive()) {\n this.calculationHelper.execute();\n }\n }\n\n sub(listener: Listener<T>, options?: SubscribeOptions): Cancel {\n const {\n passive,\n runNow = true,\n throttle: throttleOption,\n debounce: debounceOption,\n equals = defaultEquals,\n } = options ?? {};\n\n let compareToValue = this._value?.v;\n let previousValue: T | undefined;\n let hasRun = false;\n\n let innerListener = (force?: boolean | void) => {\n if (!this._value) {\n return;\n }\n\n const value = this._value.v;\n\n if (!force && equals(value, compareToValue)) {\n return;\n }\n\n compareToValue = value;\n const _previousValue = previousValue;\n previousValue = value;\n hasRun = true;\n\n try {\n listener(value, _previousValue);\n } catch (error) {\n forwardError(error);\n }\n };\n\n if (throttleOption) {\n innerListener = throttle(innerListener, throttleOption);\n } else if (debounceOption) {\n innerListener = debounce(innerListener, debounceOption);\n }\n\n this.listeners.set(innerListener, !passive);\n if (!passive) {\n this.onSubscribe();\n }\n\n if (runNow && !hasRun) {\n innerListener(true);\n }\n\n return () => {\n this.listeners.delete(innerListener);\n if (!passive) {\n this.onUnsubscribe();\n }\n };\n }\n\n once<S extends T>(condition: (value: T) => value is S): Promise<S>;\n\n once(condition?: (value: T) => boolean): Promise<T>;\n\n once(condition: (value: T) => boolean = (value) => !!value): Promise<any> {\n return new Promise<T>((resolve) => {\n let stopped = false;\n const cancel = this.sub(\n (value) => {\n if (stopped || (condition && !condition(value))) {\n return;\n }\n\n resolve(value);\n stopped = true;\n setTimeout(() => cancel());\n },\n {\n runNow: !!condition,\n },\n );\n });\n }\n\n map<S>(selector: Selector<T, S>, options?: UseOptions): Store<S>;\n\n map<P extends Path<T>>(selector: P, options?: UseOptions): Store<Value<T, P>>;\n\n map(_selector: Selector<T, any> | Path<any>, options?: UseOptions): Store<any> {\n const selector = makeSelector(_selector);\n const derivedFrom = {\n store: this.derivedFrom ? this.derivedFrom.store : this,\n selectors: this.derivedFrom ? [...this.derivedFrom.selectors, _selector] : [_selector],\n };\n\n return new Store(\n ({ use }) => {\n return selector(use(this, options));\n },\n this.options,\n derivedFrom,\n );\n }\n\n /** Add an effect that will be executed when the store becomes active, which means when it has at least one subscriber.\n * @param effect\n * If there is already a subscriber, the effect will be executed immediately.\n * Otherweise it will be executed as soon as the first subscription is created.\n * Every time all subscriptions are removed and the first is created again, the effect will be executed again.\n * @param retain\n * If provided, delay tearing down effects when the last subscriber is removed. This is useful if a short gap in subscriber coverage is supposed to be ignored. E.g. when switching pages, the old page might unsubscribe, while the new page subscribes immediately after.\n * @returns\n * The effect can return a teardown callback, which will be executed when the last subscription is removed and potentially the ratain time has passed.\n */\n addEffect(effect: Effect, retain?: Duration) {\n this.effects.set(effect, {\n handle: this.isActive() ? effect() ?? noop : undefined,\n retain: retain !== undefined ? calcDuration(retain) : undefined,\n });\n\n return () => {\n const { handle, timeout } = this.effects.get(effect) ?? {};\n handle?.();\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.delete(effect);\n };\n }\n\n /** Return whether the store is currently active, which means whether it has at least one subscriber. */\n isActive() {\n return [...this.listeners.values()].some(Boolean);\n }\n\n protected onSubscribe() {\n if ([...this.listeners.values()].filter(Boolean).length > 1) return;\n\n for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.set(effect, {\n handle: handle ?? effect() ?? noop,\n retain,\n timeout: undefined,\n });\n }\n }\n\n protected onUnsubscribe() {\n if ([...this.listeners.values()].some(Boolean)) return;\n\n for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {\n if (!retain) {\n handle?.();\n }\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.set(effect, {\n handle: retain ? handle : undefined,\n retain,\n timeout: retain && handle ? setTimeout(handle, retain) : undefined,\n });\n }\n }\n\n protected notify() {\n const n = {};\n this.notifyId = n;\n\n const snapshot = [...this.listeners.keys()];\n for (const listener of snapshot) {\n listener();\n if (n !== this.notifyId) break;\n }\n }\n}\n\nconst defaultOptions: StoreOptions = {};\n\nfunction create<T>(\n calculate: (this: { use: Use }, fns: { use: Use }) => T,\n options?: StoreOptions,\n): Store<T>;\nfunction create<T, Methods extends StoreMethods = {}>(\n initialState: T,\n options?: StoreOptionsWithMethods<T, Methods>,\n): StoreWithMethods<T, Methods>;\nfunction create<T, Methods extends StoreMethods>(\n initialState: T | ((this: { use: Use }, fns: { use: Use }) => T),\n options?: StoreOptionsWithMethods<T, Methods>,\n): StoreWithMethods<T, Methods> | Store<T> {\n const store = new Store(initialState, options);\n\n if (initialState instanceof Function) {\n return store;\n }\n\n let methods: StoreMethods | undefined = options?.methods;\n\n if (initialState instanceof Map) {\n methods = { ...mapMethods, ...methods };\n } else if (initialState instanceof Set) {\n methods = { ...setMethods, ...methods };\n } else if (Array.isArray(initialState)) {\n methods = { ...arrayMethods, ...methods };\n } else if (initialState instanceof Object) {\n methods = { ...recordMethods, ...methods };\n }\n\n const boundMethods = Object.fromEntries(\n Object.entries(methods ?? ({} as BoundStoreMethods<T, any>))\n .filter(([name]) => !(name in store))\n .map(([name, action]) => [name, (action as any).bind(store)]),\n ) as BoundStoreMethods<T, any>;\n\n return Object.assign(store, boundMethods);\n}\n\nexport const createStore = Object.assign(create, { defaultOptions });\n"],"names":[],"mappings":";;;;;;;;;;AAoDA,MAAM,OAAO,MAAM;AAEZ,MAAM,cAAiB,SAAmB;AAAA,EAyB/C,YACkB,QACA,UAAwB,CAAA,GACxB,aAIG,QAAiC,MAAM,QAC1D;AACA,UAAM,KAAK;AARK,SAAA,SAAA;AACA,SAAA,UAAA;AACA,SAAA,cAAA;AAIG,SAAA,QAAA;AA7BX,SAAA,gCAAgB;AAEhB,SAAA,8BAAc;AAKxB,SAAU,WAAW;AAEX,SAAA,oBAAoB,IAAI,kBAAkB;AAAA,MAClD,WAAW,CAAC,EAAE,UAAU;AAClB,YAAA,KAAK,kBAAkB,UAAU;AAC7B,gBAAA,QAAQ,KAAK,OAAO,MAAM,EAAE,IAAI,GAAG,CAAC,EAAE,IAAK,CAAA,CAAC;AAC7C,eAAA,SAAS,EAAE,GAAG,MAAM;AACzB,eAAK,OAAO;AAAA,QACd;AAAA,MACF;AAAA,MAEA,WAAW,KAAK,UAAU,KAAK,IAAI;AAAA,MACnC,cAAc,KAAK,MAAM,KAAK,IAAI;AAAA,IAAA,CACnC;AAYC,SAAK,MAAM,KAAK,IAAI,KAAK,IAAI;AAC7B,SAAK,MAAM,KAAK,IAAI,KAAK,IAAI;AAC7B,SAAK,MAAM,KAAK,IAAI,KAAK,IAAI;AAC7B,SAAK,OAAO,KAAK,KAAK,KAAK,IAAI;AAC/B,SAAK,MAAM,KAAK,IAAI,KAAK,IAAI;AAC7B,SAAK,YAAY,KAAK,UAAU,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AAG,eAAe,GAAG,QAAQ;AAAA,EAC3C;AAEA,QAAM,eAAe,OAAO;AAAA,IAC1B,OAAO,QAAQ,WAAY,EAAgC,EACxD,OAAO,CAAC,CAAC,IAAI,MAAM,EAAE,QAAQ,MAAM,EACnC,IAAI,CAAC,CAAC,MAAM,MAAM,MAAM,CAAC,MAAO,OAAe,KAAK,KAAK,CAAC,CAAC;AAAA,EAAA;AAGzD,SAAA,OAAO,OAAO,OAAO,YAAY;AAC1C;AAEO,MAAM,cAAc,OAAO,OAAO,QAAQ,EAAE,eAAgB,CAAA;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"immerActions.js","sources":["../../../src/immer/immerActions.ts"],"sourcesContent":["import type { Draft, nothing } from 'immer';\nimport { produce } from 'immer';\nimport type { Store } from '@core/store';\n\nexport const immerActions = {\n immerUpdate<T>(\n this: Store<T>,\n recipe: (\n draft: Draft<T>,\n ) => void | Draft<T> | (Draft<T> extends undefined ? typeof nothing : never) | undefined,\n ) {\n this.set(produce(recipe));\n },\n};\n"],"names":[],"mappings":";AAIO,MAAM,eAAe;AAAA,EAC1B,YAEE,QAGA;AACK,SAAA,IAAI,QAAQ,MAAM,CAAC;AAAA,EAC1B;AACF;"}