@legendapp/state 3.0.0-alpha.1 → 3.0.0-alpha.3
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/.DS_Store +0 -0
- package/CHANGELOG.md +1 -831
- package/LICENSE +1 -21
- package/README.md +1 -141
- package/as/arrayAsRecord.d.mts +5 -0
- package/as/arrayAsRecord.d.ts +5 -0
- package/as/arrayAsRecord.js +28 -0
- package/as/arrayAsRecord.mjs +26 -0
- package/as/arrayAsSet.d.mts +5 -0
- package/as/arrayAsSet.d.ts +5 -0
- package/as/arrayAsSet.js +13 -0
- package/as/arrayAsSet.mjs +11 -0
- package/as/arrayAsString.d.mts +5 -0
- package/as/arrayAsString.d.ts +5 -0
- package/as/arrayAsString.js +13 -0
- package/as/arrayAsString.mjs +11 -0
- package/as/numberAsString.d.mts +5 -0
- package/as/numberAsString.d.ts +5 -0
- package/as/numberAsString.js +13 -0
- package/as/numberAsString.mjs +11 -0
- package/as/recordAsArray.d.mts +5 -0
- package/as/recordAsArray.d.ts +5 -0
- package/as/recordAsArray.js +25 -0
- package/as/recordAsArray.mjs +23 -0
- package/as/recordAsString.d.mts +5 -0
- package/as/recordAsString.d.ts +5 -0
- package/as/recordAsString.js +13 -0
- package/as/recordAsString.mjs +11 -0
- package/as/setAsArray.d.mts +5 -0
- package/as/setAsArray.d.ts +5 -0
- package/as/setAsArray.js +13 -0
- package/as/setAsArray.mjs +11 -0
- package/as/setAsString.d.mts +5 -0
- package/as/setAsString.d.ts +5 -0
- package/as/setAsString.js +13 -0
- package/as/setAsString.mjs +11 -0
- package/as/stringAsArray.d.mts +5 -0
- package/as/stringAsArray.d.ts +5 -0
- package/as/stringAsArray.js +13 -0
- package/as/stringAsArray.mjs +11 -0
- package/as/stringAsNumber.d.mts +5 -0
- package/as/stringAsNumber.d.ts +5 -0
- package/as/stringAsNumber.js +16 -0
- package/as/stringAsNumber.mjs +14 -0
- package/as/stringAsRecord.d.mts +5 -0
- package/as/stringAsRecord.d.ts +5 -0
- package/as/stringAsRecord.js +15 -0
- package/as/stringAsRecord.mjs +13 -0
- package/as/stringAsSet.d.mts +5 -0
- package/as/stringAsSet.d.ts +5 -0
- package/as/stringAsSet.js +13 -0
- package/as/stringAsSet.mjs +11 -0
- package/babel.d.mts +21 -0
- package/babel.d.ts +21 -2
- package/babel.js +57 -53
- package/babel.mjs +65 -0
- package/config/enable$GetSet.js +13 -14
- package/config/enable$GetSet.mjs +13 -14
- package/config/enableReactComponents.d.mts +9 -0
- package/config/enableReactComponents.d.ts +4 -2
- package/config/enableReactComponents.js +13 -10
- package/config/enableReactComponents.mjs +13 -10
- package/config/enableReactNativeComponents.d.mts +22 -0
- package/config/enableReactNativeComponents.d.ts +6 -4
- package/config/enableReactNativeComponents.js +43 -47
- package/config/enableReactNativeComponents.mjs +43 -47
- package/config/enableReactTracking.d.mts +7 -0
- package/config/enableReactTracking.d.ts +3 -2
- package/config/enableReactTracking.js +33 -38
- package/config/enableReactTracking.mjs +33 -38
- package/config/enableReactUse.d.mts +10 -0
- package/config/enableReactUse.d.ts +4 -1
- package/config/enableReactUse.js +15 -14
- package/config/enableReactUse.mjs +15 -14
- package/config/{enable$GetSet.d.ts → enable_GetSet.d.mts} +4 -2
- package/config/enable_GetSet.d.ts +10 -0
- package/config/enable_PeekAssign.d.mts +10 -0
- package/config/enable_PeekAssign.d.ts +4 -2
- package/config/enable_PeekAssign.js +13 -14
- package/config/enable_PeekAssign.mjs +13 -14
- package/helpers/pageHash.d.mts +9 -0
- package/helpers/pageHash.d.ts +2 -0
- package/helpers/pageHash.js +25 -30
- package/helpers/pageHash.mjs +25 -30
- package/helpers/pageHashParams.d.mts +9 -0
- package/helpers/pageHashParams.d.ts +2 -0
- package/helpers/pageHashParams.js +34 -37
- package/helpers/pageHashParams.mjs +34 -37
- package/helpers/time.d.mts +6 -0
- package/helpers/time.d.ts +6 -3
- package/helpers/time.js +17 -17
- package/helpers/time.mjs +17 -17
- package/helpers/trackHistory.d.mts +6 -0
- package/helpers/trackHistory.d.ts +4 -2
- package/helpers/trackHistory.js +13 -16
- package/helpers/trackHistory.mjs +13 -16
- package/helpers/undoRedo.d.mts +37 -0
- package/helpers/undoRedo.d.ts +5 -3
- package/helpers/undoRedo.js +59 -94
- package/helpers/undoRedo.mjs +59 -94
- package/index.d.mts +404 -0
- package/index.d.ts +371 -28
- package/index.js +2015 -2166
- package/index.mjs +2015 -2166
- package/package.json +254 -195
- package/persist-plugins/async-storage.d.mts +18 -0
- package/persist-plugins/async-storage.d.ts +6 -3
- package/persist-plugins/async-storage.js +79 -86
- package/persist-plugins/async-storage.mjs +79 -86
- package/persist-plugins/indexeddb.d.mts +29 -0
- package/persist-plugins/indexeddb.d.ts +6 -3
- package/persist-plugins/indexeddb.js +331 -352
- package/persist-plugins/indexeddb.mjs +331 -352
- package/persist-plugins/local-storage.d.mts +23 -0
- package/persist-plugins/local-storage.d.ts +8 -5
- package/persist-plugins/local-storage.js +74 -76
- package/persist-plugins/local-storage.mjs +74 -76
- package/persist-plugins/mmkv.d.mts +18 -0
- package/persist-plugins/mmkv.d.ts +6 -3
- package/persist-plugins/mmkv.js +82 -86
- package/persist-plugins/mmkv.mjs +82 -86
- package/react-hooks/createObservableHook.d.mts +5 -0
- package/react-hooks/createObservableHook.d.ts +4 -1
- package/react-hooks/createObservableHook.js +29 -30
- package/react-hooks/createObservableHook.mjs +25 -30
- package/react-hooks/useHover.d.mts +5 -0
- package/react-hooks/useHover.d.ts +5 -3
- package/react-hooks/useHover.js +29 -29
- package/react-hooks/useHover.mjs +29 -29
- package/react-hooks/useMeasure.d.mts +9 -0
- package/react-hooks/useMeasure.d.ts +5 -2
- package/react-hooks/useMeasure.js +30 -32
- package/react-hooks/useMeasure.mjs +30 -32
- package/react-hooks/useObservableNextRouter.d.mts +35 -0
- package/react-hooks/useObservableNextRouter.d.ts +9 -7
- package/react-hooks/useObservableNextRouter.js +64 -77
- package/react-hooks/useObservableNextRouter.mjs +60 -77
- package/react.d.mts +157 -0
- package/react.d.ts +157 -21
- package/react.js +458 -749
- package/react.mjs +457 -752
- package/sync-plugins/crud.d.mts +54 -0
- package/sync-plugins/crud.d.ts +12 -10
- package/sync-plugins/crud.js +253 -270
- package/sync-plugins/crud.mjs +253 -270
- package/sync-plugins/fetch.d.mts +21 -0
- package/sync-plugins/fetch.d.ts +7 -4
- package/sync-plugins/fetch.js +50 -37
- package/sync-plugins/fetch.mjs +50 -37
- package/sync-plugins/keel.d.mts +108 -0
- package/sync-plugins/keel.d.ts +17 -15
- package/sync-plugins/keel.js +229 -462
- package/sync-plugins/keel.mjs +227 -464
- package/sync-plugins/supabase.d.mts +39 -0
- package/sync-plugins/supabase.d.ts +16 -14
- package/sync-plugins/supabase.js +128 -128
- package/sync-plugins/supabase.mjs +128 -128
- package/sync-plugins/tanstack-query.d.mts +14 -0
- package/sync-plugins/tanstack-query.d.ts +7 -4
- package/sync-plugins/tanstack-query.js +51 -57
- package/sync-plugins/tanstack-query.mjs +51 -57
- package/sync-plugins/tanstack-react-query.d.mts +8 -0
- package/sync-plugins/tanstack-react-query.d.ts +6 -1
- package/sync-plugins/tanstack-react-query.js +2 -2
- package/sync-plugins/tanstack-react-query.mjs +2 -2
- package/sync.d.mts +351 -0
- package/sync.d.ts +349 -9
- package/sync.js +910 -964
- package/sync.mjs +920 -974
- package/trace.d.mts +9 -0
- package/trace.d.ts +9 -4
- package/trace.js +72 -62
- package/trace.mjs +72 -62
- package/types/babel.d.ts +1 -12
- package/babel.js.map +0 -1
- package/config/enable$GetSet.js.map +0 -1
- package/config/enable$GetSet.mjs.map +0 -1
- package/config/enableReactComponents.js.map +0 -1
- package/config/enableReactComponents.mjs.map +0 -1
- package/config/enableReactNativeComponents.js.map +0 -1
- package/config/enableReactNativeComponents.mjs.map +0 -1
- package/config/enableReactTracking.js.map +0 -1
- package/config/enableReactTracking.mjs.map +0 -1
- package/config/enableReactUse.js.map +0 -1
- package/config/enableReactUse.mjs.map +0 -1
- package/config/enable_PeekAssign.js.map +0 -1
- package/config/enable_PeekAssign.mjs.map +0 -1
- package/helpers/pageHash.js.map +0 -1
- package/helpers/pageHash.mjs.map +0 -1
- package/helpers/pageHashParams.js.map +0 -1
- package/helpers/pageHashParams.mjs.map +0 -1
- package/helpers/time.js.map +0 -1
- package/helpers/time.mjs.map +0 -1
- package/helpers/trackHistory.js.map +0 -1
- package/helpers/trackHistory.mjs.map +0 -1
- package/helpers/undoRedo.js.map +0 -1
- package/helpers/undoRedo.mjs.map +0 -1
- package/history.d.ts +0 -1
- package/history.js +0 -24
- package/history.js.map +0 -1
- package/history.mjs +0 -22
- package/history.mjs.map +0 -1
- package/index.js.map +0 -1
- package/index.mjs.map +0 -1
- package/persist-plugins/async-storage.js.map +0 -1
- package/persist-plugins/async-storage.mjs.map +0 -1
- package/persist-plugins/indexeddb.js.map +0 -1
- package/persist-plugins/indexeddb.mjs.map +0 -1
- package/persist-plugins/local-storage.js.map +0 -1
- package/persist-plugins/local-storage.mjs.map +0 -1
- package/persist-plugins/mmkv.js.map +0 -1
- package/persist-plugins/mmkv.mjs.map +0 -1
- package/react-hooks/createObservableHook.js.map +0 -1
- package/react-hooks/createObservableHook.mjs.map +0 -1
- package/react-hooks/useHover.js.map +0 -1
- package/react-hooks/useHover.mjs.map +0 -1
- package/react-hooks/useMeasure.js.map +0 -1
- package/react-hooks/useMeasure.mjs.map +0 -1
- package/react-hooks/useObservableNextRouter.js.map +0 -1
- package/react-hooks/useObservableNextRouter.mjs.map +0 -1
- package/react.js.map +0 -1
- package/react.mjs.map +0 -1
- package/src/ObservableObject.ts +0 -1350
- package/src/ObservablePrimitive.ts +0 -62
- package/src/babel/index.ts +0 -83
- package/src/batching.ts +0 -357
- package/src/computed.ts +0 -18
- package/src/config/enable$GetSet.ts +0 -30
- package/src/config/enableReactComponents.ts +0 -26
- package/src/config/enableReactNativeComponents.ts +0 -102
- package/src/config/enableReactTracking.ts +0 -62
- package/src/config/enableReactUse.ts +0 -32
- package/src/config/enable_PeekAssign.ts +0 -31
- package/src/config.ts +0 -47
- package/src/createObservable.ts +0 -47
- package/src/event.ts +0 -26
- package/src/globals.ts +0 -235
- package/src/helpers/pageHash.ts +0 -41
- package/src/helpers/pageHashParams.ts +0 -55
- package/src/helpers/time.ts +0 -30
- package/src/helpers/trackHistory.ts +0 -29
- package/src/helpers/undoRedo.ts +0 -111
- package/src/helpers.ts +0 -231
- package/src/is.ts +0 -63
- package/src/linked.ts +0 -17
- package/src/observable.ts +0 -32
- package/src/observableInterfaces.ts +0 -151
- package/src/observableTypes.ts +0 -232
- package/src/observe.ts +0 -89
- package/src/old-plugins/firebase.ts +0 -1053
- package/src/onChange.ts +0 -146
- package/src/persist/configureObservablePersistence.ts +0 -7
- package/src/persist/fieldTransformer.ts +0 -149
- package/src/persist/observablePersistRemoteFunctionsAdapter.ts +0 -39
- package/src/persist/persistObservable.ts +0 -1034
- package/src/persist-plugins/async-storage.ts +0 -99
- package/src/persist-plugins/indexeddb.ts +0 -439
- package/src/persist-plugins/local-storage.ts +0 -86
- package/src/persist-plugins/mmkv.ts +0 -91
- package/src/proxy.ts +0 -28
- package/src/react/Computed.tsx +0 -8
- package/src/react/For.tsx +0 -116
- package/src/react/Memo.tsx +0 -4
- package/src/react/Reactive.tsx +0 -53
- package/src/react/Show.tsx +0 -33
- package/src/react/Switch.tsx +0 -43
- package/src/react/react-globals.ts +0 -3
- package/src/react/reactInterfaces.ts +0 -32
- package/src/react/reactive-observer.tsx +0 -210
- package/src/react/useComputed.ts +0 -36
- package/src/react/useEffectOnce.ts +0 -41
- package/src/react/useIsMounted.ts +0 -16
- package/src/react/useMount.ts +0 -15
- package/src/react/useObservable.ts +0 -24
- package/src/react/useObservableReducer.ts +0 -52
- package/src/react/useObservableState.ts +0 -30
- package/src/react/useObserve.ts +0 -54
- package/src/react/useObserveEffect.ts +0 -40
- package/src/react/usePauseProvider.tsx +0 -16
- package/src/react/useSelector.ts +0 -167
- package/src/react/useUnmount.ts +0 -8
- package/src/react/useWhen.ts +0 -9
- package/src/react-hooks/createObservableHook.ts +0 -53
- package/src/react-hooks/useHover.ts +0 -40
- package/src/react-hooks/useMeasure.ts +0 -48
- package/src/react-hooks/useObservableNextRouter.ts +0 -137
- package/src/retry.ts +0 -71
- package/src/setupTracking.ts +0 -26
- package/src/sync/activateSyncedNode.ts +0 -128
- package/src/sync/configureObservableSync.ts +0 -7
- package/src/sync/persistTypes.ts +0 -216
- package/src/sync/syncHelpers.ts +0 -180
- package/src/sync/syncObservable.ts +0 -1056
- package/src/sync/syncObservableAdapter.ts +0 -31
- package/src/sync/syncTypes.ts +0 -189
- package/src/sync/synced.ts +0 -21
- package/src/sync-plugins/crud.ts +0 -412
- package/src/sync-plugins/fetch.ts +0 -80
- package/src/sync-plugins/keel.ts +0 -495
- package/src/sync-plugins/supabase.ts +0 -249
- package/src/sync-plugins/tanstack-query.ts +0 -113
- package/src/sync-plugins/tanstack-react-query.ts +0 -12
- package/src/trace/traceHelpers.ts +0 -11
- package/src/trace/useTraceListeners.ts +0 -34
- package/src/trace/useTraceUpdates.ts +0 -24
- package/src/trace/useVerifyNotTracking.ts +0 -33
- package/src/trace/useVerifyOneRender.ts +0 -10
- package/src/trackSelector.ts +0 -52
- package/src/tracking.ts +0 -43
- package/src/types/babel.d.ts +0 -12
- package/src/when.ts +0 -75
- package/sync-plugins/crud.js.map +0 -1
- package/sync-plugins/crud.mjs.map +0 -1
- package/sync-plugins/fetch.js.map +0 -1
- package/sync-plugins/fetch.mjs.map +0 -1
- package/sync-plugins/keel.js.map +0 -1
- package/sync-plugins/keel.mjs.map +0 -1
- package/sync-plugins/supabase.js.map +0 -1
- package/sync-plugins/supabase.mjs.map +0 -1
- package/sync-plugins/tanstack-query.js.map +0 -1
- package/sync-plugins/tanstack-query.mjs.map +0 -1
- package/sync-plugins/tanstack-react-query.js.map +0 -1
- package/sync-plugins/tanstack-react-query.mjs.map +0 -1
- package/sync.js.map +0 -1
- package/sync.mjs.map +0 -1
- package/trace.js.map +0 -1
- package/trace.mjs.map +0 -1
package/react.mjs
CHANGED
|
@@ -1,825 +1,530 @@
|
|
|
1
|
-
import { observable, isPromise, isObservable, syncState,
|
|
2
|
-
import
|
|
1
|
+
import { isFunction, isEmpty, observable, isPromise, isObservable, syncState, computeSelector, isArray, isMap, isObservableValueReady, computed, observe, when, whenReady, internal, trackSelector, isPrimitive } from '@legendapp/state';
|
|
2
|
+
import React, { memo, forwardRef, createElement, useState, useContext, useMemo, useRef, useEffect, createContext, useCallback } from 'react';
|
|
3
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
// src/react/Computed.tsx
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* @license React
|
|
10
|
-
* use-sync-external-store-shim.production.min.js
|
|
11
|
-
*
|
|
12
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the MIT license found in the
|
|
15
|
-
* LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
var hasRequiredUseSyncExternalStoreShim_production_min;
|
|
19
|
-
|
|
20
|
-
function requireUseSyncExternalStoreShim_production_min () {
|
|
21
|
-
if (hasRequiredUseSyncExternalStoreShim_production_min) return useSyncExternalStoreShim_production_min;
|
|
22
|
-
hasRequiredUseSyncExternalStoreShim_production_min = 1;
|
|
23
|
-
var e=require$$0;function h(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var k="function"===typeof Object.is?Object.is:h,l=e.useState,m=e.useEffect,n=e.useLayoutEffect,p=e.useDebugValue;function q(a,b){var d=b(),f=l({inst:{value:d,getSnapshot:b}}),c=f[0].inst,g=f[1];n(function(){c.value=d;c.getSnapshot=b;r(c)&&g({inst:c});},[a,d,b]);m(function(){r(c)&&g({inst:c});return a(function(){r(c)&&g({inst:c});})},[a]);p(d);return d}
|
|
24
|
-
function r(a){var b=a.getSnapshot;a=a.value;try{var d=b();return !k(a,d)}catch(f){return !0}}function t(a,b){return b()}var u="undefined"===typeof window||"undefined"===typeof window.document||"undefined"===typeof window.document.createElement?t:q;useSyncExternalStoreShim_production_min.useSyncExternalStore=void 0!==e.useSyncExternalStore?e.useSyncExternalStore:u;
|
|
25
|
-
return useSyncExternalStoreShim_production_min;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
var useSyncExternalStoreShim_development = {};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @license React
|
|
32
|
-
* use-sync-external-store-shim.development.js
|
|
33
|
-
*
|
|
34
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
35
|
-
*
|
|
36
|
-
* This source code is licensed under the MIT license found in the
|
|
37
|
-
* LICENSE file in the root directory of this source tree.
|
|
38
|
-
*/
|
|
39
|
-
|
|
40
|
-
var hasRequiredUseSyncExternalStoreShim_development;
|
|
41
|
-
|
|
42
|
-
function requireUseSyncExternalStoreShim_development () {
|
|
43
|
-
if (hasRequiredUseSyncExternalStoreShim_development) return useSyncExternalStoreShim_development;
|
|
44
|
-
hasRequiredUseSyncExternalStoreShim_development = 1;
|
|
45
|
-
|
|
46
|
-
if (process.env.NODE_ENV !== "production") {
|
|
47
|
-
(function() {
|
|
48
|
-
|
|
49
|
-
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
|
50
|
-
if (
|
|
51
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
52
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
|
|
53
|
-
'function'
|
|
54
|
-
) {
|
|
55
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
56
|
-
}
|
|
57
|
-
var React = require$$0;
|
|
58
|
-
|
|
59
|
-
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
60
|
-
|
|
61
|
-
function error(format) {
|
|
62
|
-
{
|
|
63
|
-
{
|
|
64
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
65
|
-
args[_key2 - 1] = arguments[_key2];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
printWarning('error', format, args);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function printWarning(level, format, args) {
|
|
74
|
-
// When changing this logic, you might want to also
|
|
75
|
-
// update consoleWithStackDev.www.js as well.
|
|
76
|
-
{
|
|
77
|
-
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
|
78
|
-
var stack = ReactDebugCurrentFrame.getStackAddendum();
|
|
79
|
-
|
|
80
|
-
if (stack !== '') {
|
|
81
|
-
format += '%s';
|
|
82
|
-
args = args.concat([stack]);
|
|
83
|
-
} // eslint-disable-next-line react-internal/safe-string-coercion
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
var argsWithFormat = args.map(function (item) {
|
|
87
|
-
return String(item);
|
|
88
|
-
}); // Careful: RN currently depends on this prefix
|
|
89
|
-
|
|
90
|
-
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
|
|
91
|
-
// breaks IE9: https://github.com/facebook/react/issues/13610
|
|
92
|
-
// eslint-disable-next-line react-internal/no-production-logging
|
|
93
|
-
|
|
94
|
-
Function.prototype.apply.call(console[level], console, argsWithFormat);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
100
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
101
|
-
*/
|
|
102
|
-
function is(x, y) {
|
|
103
|
-
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
|
|
104
|
-
;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
var objectIs = typeof Object.is === 'function' ? Object.is : is;
|
|
108
|
-
|
|
109
|
-
// dispatch for CommonJS interop named imports.
|
|
110
|
-
|
|
111
|
-
var useState = React.useState,
|
|
112
|
-
useEffect = React.useEffect,
|
|
113
|
-
useLayoutEffect = React.useLayoutEffect,
|
|
114
|
-
useDebugValue = React.useDebugValue;
|
|
115
|
-
var didWarnOld18Alpha = false;
|
|
116
|
-
var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works
|
|
117
|
-
// because of a very particular set of implementation details and assumptions
|
|
118
|
-
// -- change any one of them and it will break. The most important assumption
|
|
119
|
-
// is that updates are always synchronous, because concurrent rendering is
|
|
120
|
-
// only available in versions of React that also have a built-in
|
|
121
|
-
// useSyncExternalStore API. And we only use this shim when the built-in API
|
|
122
|
-
// does not exist.
|
|
123
|
-
//
|
|
124
|
-
// Do not assume that the clever hacks used by this hook also work in general.
|
|
125
|
-
// The point of this shim is to replace the need for hacks by other libraries.
|
|
126
|
-
|
|
127
|
-
function useSyncExternalStore(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of
|
|
128
|
-
// React do not expose a way to check if we're hydrating. So users of the shim
|
|
129
|
-
// will need to track that themselves and return the correct value
|
|
130
|
-
// from `getSnapshot`.
|
|
131
|
-
getServerSnapshot) {
|
|
132
|
-
{
|
|
133
|
-
if (!didWarnOld18Alpha) {
|
|
134
|
-
if (React.startTransition !== undefined) {
|
|
135
|
-
didWarnOld18Alpha = true;
|
|
136
|
-
|
|
137
|
-
error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.');
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
} // Read the current snapshot from the store on every render. Again, this
|
|
141
|
-
// breaks the rules of React, and only works here because of specific
|
|
142
|
-
// implementation details, most importantly that updates are
|
|
143
|
-
// always synchronous.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
var value = getSnapshot();
|
|
147
|
-
|
|
148
|
-
{
|
|
149
|
-
if (!didWarnUncachedGetSnapshot) {
|
|
150
|
-
var cachedValue = getSnapshot();
|
|
151
|
-
|
|
152
|
-
if (!objectIs(value, cachedValue)) {
|
|
153
|
-
error('The result of getSnapshot should be cached to avoid an infinite loop');
|
|
154
|
-
|
|
155
|
-
didWarnUncachedGetSnapshot = true;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
} // Because updates are synchronous, we don't queue them. Instead we force a
|
|
159
|
-
// re-render whenever the subscribed state changes by updating an some
|
|
160
|
-
// arbitrary useState hook. Then, during render, we call getSnapshot to read
|
|
161
|
-
// the current value.
|
|
162
|
-
//
|
|
163
|
-
// Because we don't actually use the state returned by the useState hook, we
|
|
164
|
-
// can save a bit of memory by storing other stuff in that slot.
|
|
165
|
-
//
|
|
166
|
-
// To implement the early bailout, we need to track some things on a mutable
|
|
167
|
-
// object. Usually, we would put that in a useRef hook, but we can stash it in
|
|
168
|
-
// our useState hook instead.
|
|
169
|
-
//
|
|
170
|
-
// To force a re-render, we call forceUpdate({inst}). That works because the
|
|
171
|
-
// new object always fails an equality check.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
var _useState = useState({
|
|
175
|
-
inst: {
|
|
176
|
-
value: value,
|
|
177
|
-
getSnapshot: getSnapshot
|
|
178
|
-
}
|
|
179
|
-
}),
|
|
180
|
-
inst = _useState[0].inst,
|
|
181
|
-
forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated
|
|
182
|
-
// in the layout phase so we can access it during the tearing check that
|
|
183
|
-
// happens on subscribe.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
useLayoutEffect(function () {
|
|
187
|
-
inst.value = value;
|
|
188
|
-
inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the
|
|
189
|
-
// commit phase if there was an interleaved mutation. In concurrent mode
|
|
190
|
-
// this can happen all the time, but even in synchronous mode, an earlier
|
|
191
|
-
// effect may have mutated the store.
|
|
192
|
-
|
|
193
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
194
|
-
// Force a re-render.
|
|
195
|
-
forceUpdate({
|
|
196
|
-
inst: inst
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}, [subscribe, value, getSnapshot]);
|
|
200
|
-
useEffect(function () {
|
|
201
|
-
// Check for changes right before subscribing. Subsequent changes will be
|
|
202
|
-
// detected in the subscription handler.
|
|
203
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
204
|
-
// Force a re-render.
|
|
205
|
-
forceUpdate({
|
|
206
|
-
inst: inst
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
var handleStoreChange = function () {
|
|
211
|
-
// TODO: Because there is no cross-renderer API for batching updates, it's
|
|
212
|
-
// up to the consumer of this library to wrap their subscription event
|
|
213
|
-
// with unstable_batchedUpdates. Should we try to detect when this isn't
|
|
214
|
-
// the case and print a warning in development?
|
|
215
|
-
// The store changed. Check if the snapshot changed since the last time we
|
|
216
|
-
// read from the store.
|
|
217
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
218
|
-
// Force a re-render.
|
|
219
|
-
forceUpdate({
|
|
220
|
-
inst: inst
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
}; // Subscribe to the store and return a clean-up function.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
return subscribe(handleStoreChange);
|
|
227
|
-
}, [subscribe]);
|
|
228
|
-
useDebugValue(value);
|
|
229
|
-
return value;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function checkIfSnapshotChanged(inst) {
|
|
233
|
-
var latestGetSnapshot = inst.getSnapshot;
|
|
234
|
-
var prevValue = inst.value;
|
|
235
|
-
|
|
236
|
-
try {
|
|
237
|
-
var nextValue = latestGetSnapshot();
|
|
238
|
-
return !objectIs(prevValue, nextValue);
|
|
239
|
-
} catch (error) {
|
|
240
|
-
return true;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
|
|
245
|
-
// Note: The shim does not use getServerSnapshot, because pre-18 versions of
|
|
246
|
-
// React do not expose a way to check if we're hydrating. So users of the shim
|
|
247
|
-
// will need to track that themselves and return the correct value
|
|
248
|
-
// from `getSnapshot`.
|
|
249
|
-
return getSnapshot();
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
|
|
253
|
-
|
|
254
|
-
var isServerEnvironment = !canUseDOM;
|
|
255
|
-
|
|
256
|
-
var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
|
|
257
|
-
var useSyncExternalStore$2 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim;
|
|
258
|
-
|
|
259
|
-
useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2;
|
|
260
|
-
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
|
261
|
-
if (
|
|
262
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
263
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
|
|
264
|
-
'function'
|
|
265
|
-
) {
|
|
266
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
})();
|
|
270
|
-
}
|
|
271
|
-
return useSyncExternalStoreShim_development;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
(function (module) {
|
|
275
|
-
|
|
276
|
-
if (process.env.NODE_ENV === 'production') {
|
|
277
|
-
module.exports = requireUseSyncExternalStoreShim_production_min();
|
|
278
|
-
} else {
|
|
279
|
-
module.exports = requireUseSyncExternalStoreShim_development();
|
|
280
|
-
}
|
|
281
|
-
} (shim));
|
|
282
|
-
|
|
283
|
-
const reactGlobals = {
|
|
284
|
-
inObserver: false,
|
|
7
|
+
// src/react/react-globals.ts
|
|
8
|
+
var reactGlobals = {
|
|
9
|
+
inObserver: false
|
|
285
10
|
};
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return (pauseContext || (pauseContext = createContext(null)));
|
|
11
|
+
var pauseContext = void 0;
|
|
12
|
+
var getPauseContext = () => {
|
|
13
|
+
return pauseContext || (pauseContext = createContext(null));
|
|
290
14
|
};
|
|
291
15
|
function usePauseProvider() {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
16
|
+
const [value] = useState(() => observable(false));
|
|
17
|
+
return {
|
|
18
|
+
PauseProvider: ({ children }) => createElement(getPauseContext().Provider, { value }, children),
|
|
19
|
+
isPaused$: value
|
|
20
|
+
};
|
|
297
21
|
}
|
|
298
22
|
|
|
23
|
+
// src/react/useSelector.ts
|
|
299
24
|
function createSelectorFunctions(options, isPaused$) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
25
|
+
let version = 0;
|
|
26
|
+
let notify;
|
|
27
|
+
let dispose;
|
|
28
|
+
let resubscribe;
|
|
29
|
+
let _selector;
|
|
30
|
+
let prev;
|
|
31
|
+
let pendingUpdate = void 0;
|
|
32
|
+
const run = () => {
|
|
33
|
+
dispose == null ? void 0 : dispose();
|
|
34
|
+
const {
|
|
35
|
+
value,
|
|
36
|
+
dispose: _dispose,
|
|
37
|
+
resubscribe: _resubscribe
|
|
38
|
+
} = trackSelector(
|
|
39
|
+
_selector,
|
|
40
|
+
_update,
|
|
41
|
+
void 0,
|
|
42
|
+
void 0,
|
|
43
|
+
/*createResubscribe*/
|
|
44
|
+
true
|
|
45
|
+
);
|
|
46
|
+
dispose = _dispose;
|
|
47
|
+
resubscribe = _resubscribe;
|
|
48
|
+
return value;
|
|
49
|
+
};
|
|
50
|
+
const _update = ({ value }) => {
|
|
51
|
+
if (isPaused$ == null ? void 0 : isPaused$.peek()) {
|
|
52
|
+
const next = pendingUpdate;
|
|
53
|
+
pendingUpdate = value;
|
|
54
|
+
if (next === void 0) {
|
|
55
|
+
when(
|
|
56
|
+
() => !isPaused$.get(),
|
|
57
|
+
() => {
|
|
58
|
+
const latest = pendingUpdate;
|
|
59
|
+
pendingUpdate = void 0;
|
|
60
|
+
_update({ value: latest });
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
let changed = options == null ? void 0 : options.skipCheck;
|
|
66
|
+
if (!changed) {
|
|
67
|
+
const newValue = run();
|
|
68
|
+
if (newValue !== prev || !isPrimitive(newValue) && newValue === value) {
|
|
69
|
+
changed = true;
|
|
343
70
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
71
|
+
}
|
|
72
|
+
if (changed) {
|
|
73
|
+
version++;
|
|
74
|
+
notify == null ? void 0 : notify();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
subscribe: (onStoreChange) => {
|
|
80
|
+
notify = onStoreChange;
|
|
81
|
+
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && !dispose && resubscribe) {
|
|
82
|
+
dispose = resubscribe();
|
|
83
|
+
}
|
|
84
|
+
return () => {
|
|
85
|
+
dispose == null ? void 0 : dispose();
|
|
86
|
+
dispose = void 0;
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
getVersion: () => version,
|
|
90
|
+
run: (selector) => {
|
|
91
|
+
_selector = selector;
|
|
92
|
+
return prev = run();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
366
95
|
}
|
|
367
96
|
function useSelector(selector, options) {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
if (options === null || options === void 0 ? void 0 : options.suspense) {
|
|
386
|
-
// Note: Although it's not possible for an observable to be a promise, the selector may be a
|
|
387
|
-
// function that returns a Promise, so we handle that case too.
|
|
388
|
-
if (isPromise(value) ||
|
|
389
|
-
(!value && isObservable(selector) && syncState(selector).isLoaded.get() === false)) {
|
|
390
|
-
if (require$$0.use) {
|
|
391
|
-
require$$0.use(value);
|
|
392
|
-
}
|
|
393
|
-
else {
|
|
394
|
-
throw value;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
97
|
+
var _a;
|
|
98
|
+
if (reactGlobals.inObserver && isObservable(selector) && !(options == null ? void 0 : options.suspense)) {
|
|
99
|
+
return computeSelector(selector);
|
|
100
|
+
}
|
|
101
|
+
let value;
|
|
102
|
+
try {
|
|
103
|
+
const isPaused$ = useContext(getPauseContext());
|
|
104
|
+
const selectorFn = useMemo(() => createSelectorFunctions(options, isPaused$), []);
|
|
105
|
+
const { subscribe, getVersion, run } = selectorFn;
|
|
106
|
+
value = run(selector);
|
|
107
|
+
useSyncExternalStore(subscribe, getVersion, getVersion);
|
|
108
|
+
if (options == null ? void 0 : options.suspense) {
|
|
109
|
+
if (isPromise(value) || !value && isObservable(selector) && syncState(selector).isLoaded.get() === false) {
|
|
110
|
+
if (React.use) {
|
|
111
|
+
React.use(value);
|
|
112
|
+
} else {
|
|
113
|
+
throw value;
|
|
397
114
|
}
|
|
115
|
+
}
|
|
398
116
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
throw err;
|
|
117
|
+
} catch (err) {
|
|
118
|
+
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && ((_a = err == null ? void 0 : err.message) == null ? void 0 : _a.includes("Rendered more"))) {
|
|
119
|
+
console.warn(
|
|
120
|
+
`[legend-state]: You may want to wrap this component in \`observer\` to fix the error of ${err.message}`
|
|
121
|
+
);
|
|
405
122
|
}
|
|
406
|
-
|
|
123
|
+
throw err;
|
|
124
|
+
}
|
|
125
|
+
return value;
|
|
407
126
|
}
|
|
408
127
|
|
|
128
|
+
// src/react/Computed.tsx
|
|
409
129
|
function Computed({ children }) {
|
|
410
|
-
|
|
130
|
+
return useSelector(() => computeSelector(computeSelector(children)), { skipCheck: true });
|
|
411
131
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
//
|
|
417
|
-
function
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
438
|
-
// Unwrap forwardRef on the component
|
|
439
|
-
if (ReactForwardRefSymbol && render['$$typeof'] === ReactForwardRefSymbol) {
|
|
440
|
-
useForwardRef = true;
|
|
441
|
-
render = render['render'];
|
|
442
|
-
if (process.env.NODE_ENV === 'development' && typeof render !== 'function') {
|
|
443
|
-
throw new Error(`[legend-state] \`render\` property of ForwardRef was not a function`);
|
|
444
|
-
}
|
|
132
|
+
var hasSymbol = typeof Symbol === "function" && Symbol.for;
|
|
133
|
+
var didWarnProps = false;
|
|
134
|
+
function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
135
|
+
const ReactForwardRefSymbol = hasSymbol ? Symbol.for("react.forward_ref") : (
|
|
136
|
+
// eslint-disable-next-line react/display-name, @typescript-eslint/no-unused-vars
|
|
137
|
+
typeof forwardRef === "function" && forwardRef((props) => null)["$$typeof"]
|
|
138
|
+
);
|
|
139
|
+
const ReactMemoSymbol = hasSymbol ? Symbol.for("react.memo") : (
|
|
140
|
+
// eslint-disable-next-line react/display-name, @typescript-eslint/no-unused-vars
|
|
141
|
+
typeof forwardRef === "function" && memo((props) => null)["$$typeof"]
|
|
142
|
+
);
|
|
143
|
+
if (component["__legend_proxied"])
|
|
144
|
+
return component;
|
|
145
|
+
let useForwardRef = false;
|
|
146
|
+
let useMemo5 = false;
|
|
147
|
+
let render = component;
|
|
148
|
+
if (ReactMemoSymbol && render["$$typeof"] === ReactMemoSymbol && render["type"]) {
|
|
149
|
+
useMemo5 = true;
|
|
150
|
+
render = render["type"];
|
|
151
|
+
}
|
|
152
|
+
if (ReactForwardRefSymbol && render["$$typeof"] === ReactForwardRefSymbol) {
|
|
153
|
+
useForwardRef = true;
|
|
154
|
+
render = render["render"];
|
|
155
|
+
if (process.env.NODE_ENV === "development" && typeof render !== "function") {
|
|
156
|
+
throw new Error(`[legend-state] \`render\` property of ForwardRef was not a function`);
|
|
445
157
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
console.warn(`[legend-state] Reactive props were changed to start with $ instead of end with $ in version 2.0. So please change ${key} to $${key.replace('$', '')}. See https://legendapp.com/open-source/state/migrating for more details.`);
|
|
468
|
-
}
|
|
469
|
-
const k = key.endsWith('$') ? key.slice(0, -1) : key.slice(1);
|
|
470
|
-
// Return raw value and listen to the selector for changes
|
|
471
|
-
const bind = bindKeys === null || bindKeys === void 0 ? void 0 : bindKeys[k];
|
|
472
|
-
const shouldBind = bind && isObservable(p);
|
|
473
|
-
propsOut[k] = shouldBind && (bind === null || bind === void 0 ? void 0 : bind.selector) ? bind.selector(propsOut, p) : useSelector(p);
|
|
474
|
-
// If this key is one of the bind keys set up a two-way binding
|
|
475
|
-
if (shouldBind) {
|
|
476
|
-
// Use the bind's defaultValue if value is undefined
|
|
477
|
-
if (bind.defaultValue !== undefined && propsOut[k] === undefined) {
|
|
478
|
-
propsOut[k] = bind.defaultValue;
|
|
479
|
-
}
|
|
480
|
-
if (bind.handler && bind.getValue) {
|
|
481
|
-
// Hook up the change lander
|
|
482
|
-
const handlerFn = (e) => {
|
|
483
|
-
var _a;
|
|
484
|
-
p.set(bind.getValue(e));
|
|
485
|
-
(_a = props[bind.handler]) === null || _a === void 0 ? void 0 : _a.call(props, e);
|
|
486
|
-
};
|
|
487
|
-
propsOut[bind.handler] =
|
|
488
|
-
// If in development mode, don't memoize the handler. fix fast refresh bug
|
|
489
|
-
process.env.NODE_ENV === 'development'
|
|
490
|
-
? handlerFn
|
|
491
|
-
: useCallback(handlerFn, [props[bind.handler], bindKeys]);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
// Delete the reactive key
|
|
495
|
-
delete propsOut[key];
|
|
496
|
-
}
|
|
497
|
-
else if (propsOut[key] === undefined) {
|
|
498
|
-
propsOut[key] = p;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
argArray[0] = propsOut;
|
|
158
|
+
}
|
|
159
|
+
const proxyHandler = {
|
|
160
|
+
apply(target, thisArg, argArray) {
|
|
161
|
+
if (reactive2) {
|
|
162
|
+
const props = argArray[0];
|
|
163
|
+
const propsOut = {};
|
|
164
|
+
const keys = Object.keys(props);
|
|
165
|
+
for (let i = 0; i < keys.length; i++) {
|
|
166
|
+
const key = keys[i];
|
|
167
|
+
const p = props[key];
|
|
168
|
+
if (key === "children" && (isFunction(p) || isObservable(p))) {
|
|
169
|
+
props[key] = useSelector(p, { skipCheck: true });
|
|
170
|
+
} else if (key.startsWith("$") || key.endsWith("$")) {
|
|
171
|
+
if (process.env.NODE_ENV === "development" && !didWarnProps && key.endsWith("$")) {
|
|
172
|
+
didWarnProps = true;
|
|
173
|
+
console.warn(
|
|
174
|
+
`[legend-state] Reactive props were changed to start with $ instead of end with $ in version 2.0. So please change ${key} to $${key.replace(
|
|
175
|
+
"$",
|
|
176
|
+
""
|
|
177
|
+
)}. See https://legendapp.com/open-source/state/migrating for more details.`
|
|
178
|
+
);
|
|
502
179
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
180
|
+
const k = key.endsWith("$") ? key.slice(0, -1) : key.slice(1);
|
|
181
|
+
const bind = bindKeys == null ? void 0 : bindKeys[k];
|
|
182
|
+
const shouldBind = bind && isObservable(p);
|
|
183
|
+
propsOut[k] = shouldBind && (bind == null ? void 0 : bind.selector) ? bind.selector(propsOut, p) : useSelector(p);
|
|
184
|
+
if (shouldBind) {
|
|
185
|
+
if (bind.defaultValue !== void 0 && propsOut[k] === void 0) {
|
|
186
|
+
propsOut[k] = bind.defaultValue;
|
|
187
|
+
}
|
|
188
|
+
if (bind.handler && bind.getValue) {
|
|
189
|
+
const handlerFn = (e) => {
|
|
190
|
+
var _a;
|
|
191
|
+
p.set(bind.getValue(e));
|
|
192
|
+
(_a = props[bind.handler]) == null ? void 0 : _a.call(props, e);
|
|
193
|
+
};
|
|
194
|
+
propsOut[bind.handler] = // If in development mode, don't memoize the handler. fix fast refresh bug
|
|
195
|
+
process.env.NODE_ENV === "development" ? handlerFn : useCallback(handlerFn, [props[bind.handler], bindKeys]);
|
|
196
|
+
}
|
|
514
197
|
}
|
|
515
|
-
|
|
516
|
-
|
|
198
|
+
delete propsOut[key];
|
|
199
|
+
} else if (propsOut[key] === void 0) {
|
|
200
|
+
propsOut[key] = p;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
argArray[0] = propsOut;
|
|
204
|
+
}
|
|
205
|
+
if (observe3) {
|
|
206
|
+
return useSelector(
|
|
207
|
+
() => {
|
|
208
|
+
reactGlobals.inObserver = true;
|
|
209
|
+
try {
|
|
210
|
+
return Reflect.apply(target, thisArg, argArray);
|
|
211
|
+
} finally {
|
|
212
|
+
reactGlobals.inObserver = false;
|
|
517
213
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
ret['__legend_proxied'] = true;
|
|
214
|
+
},
|
|
215
|
+
{ skipCheck: true }
|
|
216
|
+
);
|
|
217
|
+
} else {
|
|
218
|
+
return Reflect.apply(target, thisArg, argArray);
|
|
219
|
+
}
|
|
525
220
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
221
|
+
};
|
|
222
|
+
const proxy = new Proxy(render, proxyHandler);
|
|
223
|
+
let ret;
|
|
224
|
+
if (useForwardRef) {
|
|
225
|
+
ret = forwardRef(proxy);
|
|
226
|
+
ret["__legend_proxied"] = true;
|
|
227
|
+
} else {
|
|
228
|
+
ret = proxy;
|
|
229
|
+
}
|
|
230
|
+
return observe3 || useMemo5 ? memo(ret) : ret;
|
|
530
231
|
}
|
|
531
232
|
function observer(component) {
|
|
532
|
-
|
|
233
|
+
return createReactiveComponent(component, true);
|
|
533
234
|
}
|
|
534
235
|
function reactive(component, bindKeys) {
|
|
535
|
-
|
|
236
|
+
return createReactiveComponent(component, false, true, bindKeys);
|
|
536
237
|
}
|
|
537
238
|
function reactiveObserver(component, bindKeys) {
|
|
538
|
-
|
|
239
|
+
return createReactiveComponent(component, true, true, bindKeys);
|
|
539
240
|
}
|
|
540
241
|
function reactiveComponents(components) {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
}
|
|
548
|
-
|
|
242
|
+
return new Proxy(
|
|
243
|
+
{},
|
|
244
|
+
{
|
|
245
|
+
get(target, p) {
|
|
246
|
+
if (!target[p] && components[p]) {
|
|
247
|
+
target[p] = createReactiveComponent(components[p], false, true);
|
|
248
|
+
}
|
|
249
|
+
return target[p];
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
);
|
|
549
253
|
}
|
|
550
254
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
255
|
+
// src/react/For.tsx
|
|
256
|
+
var { findIDKey, getNode, optimized } = internal;
|
|
257
|
+
var autoMemoCache = /* @__PURE__ */ new Map();
|
|
258
|
+
function For({
|
|
259
|
+
each,
|
|
260
|
+
optimized: isOptimized,
|
|
261
|
+
item,
|
|
262
|
+
itemProps,
|
|
263
|
+
sortValues,
|
|
264
|
+
children
|
|
265
|
+
}) {
|
|
266
|
+
var _a;
|
|
267
|
+
if (!each)
|
|
268
|
+
return null;
|
|
269
|
+
const value = useSelector(() => each.get(isOptimized ? optimized : true));
|
|
270
|
+
if (!item && children) {
|
|
271
|
+
const refChildren = useRef();
|
|
272
|
+
refChildren.current = children;
|
|
273
|
+
item = useMemo(() => observer(({ item$, id }) => refChildren.current(item$, id)), []);
|
|
274
|
+
} else {
|
|
275
|
+
if (item.$$typeof !== Symbol.for("react.memo")) {
|
|
276
|
+
let memod = autoMemoCache.get(item);
|
|
277
|
+
if (!memod) {
|
|
278
|
+
memod = memo(item);
|
|
279
|
+
autoMemoCache.set(item, memod);
|
|
280
|
+
}
|
|
281
|
+
item = memod;
|
|
566
282
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
283
|
+
}
|
|
284
|
+
if (!value)
|
|
285
|
+
return null;
|
|
286
|
+
const out = [];
|
|
287
|
+
const isArr = isArray(value);
|
|
288
|
+
if (isArr) {
|
|
289
|
+
const v0 = value[0];
|
|
290
|
+
const node = getNode(each);
|
|
291
|
+
const length = value.length;
|
|
292
|
+
const idField = length > 0 ? node && findIDKey(v0, node) || (v0.id !== void 0 ? "id" : v0.key !== void 0 ? "key" : void 0) : void 0;
|
|
293
|
+
const isIdFieldFunction = isFunction(idField);
|
|
294
|
+
for (let i = 0; i < length; i++) {
|
|
295
|
+
if (value[i]) {
|
|
296
|
+
const val = value[i];
|
|
297
|
+
const key = (_a = isIdFieldFunction ? idField(val) : val[idField]) != null ? _a : i;
|
|
298
|
+
const item$ = each[i];
|
|
299
|
+
const props = {
|
|
300
|
+
key,
|
|
301
|
+
id: key,
|
|
302
|
+
item$,
|
|
303
|
+
item: item$
|
|
304
|
+
};
|
|
305
|
+
out.push(createElement(item, itemProps ? Object.assign(props, itemProps) : props));
|
|
306
|
+
}
|
|
577
307
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
const isArr = isArray(value);
|
|
584
|
-
if (isArr) {
|
|
585
|
-
// Get the appropriate id field
|
|
586
|
-
const v0 = value[0];
|
|
587
|
-
const node = getNode(each);
|
|
588
|
-
const length = value.length;
|
|
589
|
-
const idField = length > 0
|
|
590
|
-
? (node && findIDKey(v0, node)) ||
|
|
591
|
-
(v0.id !== undefined ? 'id' : v0.key !== undefined ? 'key' : undefined)
|
|
592
|
-
: undefined;
|
|
593
|
-
const isIdFieldFunction = isFunction(idField);
|
|
594
|
-
for (let i = 0; i < length; i++) {
|
|
595
|
-
if (value[i]) {
|
|
596
|
-
const val = value[i];
|
|
597
|
-
const key = (_a = (isIdFieldFunction ? idField(val) : val[idField])) !== null && _a !== void 0 ? _a : i;
|
|
598
|
-
const item$ = each[i];
|
|
599
|
-
// TODOV3 Remove item
|
|
600
|
-
const props = {
|
|
601
|
-
key,
|
|
602
|
-
id: key,
|
|
603
|
-
item$,
|
|
604
|
-
item: item$,
|
|
605
|
-
};
|
|
606
|
-
out.push(createElement(item, itemProps ? Object.assign(props, itemProps) : props));
|
|
607
|
-
}
|
|
608
|
-
}
|
|
308
|
+
} else {
|
|
309
|
+
const asMap = isMap(value);
|
|
310
|
+
const keys = asMap ? Array.from(value.keys()) : Object.keys(value);
|
|
311
|
+
if (sortValues) {
|
|
312
|
+
keys.sort((A, B) => sortValues(asMap ? value.get(A) : value[A], asMap ? value.get(B) : value[B], A, B));
|
|
609
313
|
}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
key,
|
|
623
|
-
id: key,
|
|
624
|
-
item$,
|
|
625
|
-
item: item$,
|
|
626
|
-
};
|
|
627
|
-
out.push(createElement(item, itemProps ? Object.assign(props, itemProps) : props));
|
|
628
|
-
}
|
|
629
|
-
}
|
|
314
|
+
for (let i = 0; i < keys.length; i++) {
|
|
315
|
+
const key = keys[i];
|
|
316
|
+
if (asMap ? value.get(key) : value[key]) {
|
|
317
|
+
const item$ = asMap ? each.get(key) : each[key];
|
|
318
|
+
const props = {
|
|
319
|
+
key,
|
|
320
|
+
id: key,
|
|
321
|
+
item$,
|
|
322
|
+
item: item$
|
|
323
|
+
};
|
|
324
|
+
out.push(createElement(item, itemProps ? Object.assign(props, itemProps) : props));
|
|
325
|
+
}
|
|
630
326
|
}
|
|
631
|
-
|
|
327
|
+
}
|
|
328
|
+
return out;
|
|
632
329
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
330
|
+
var Memo = memo(Computed, () => true);
|
|
331
|
+
var ReactiveFns = /* @__PURE__ */ new Map();
|
|
332
|
+
var ReactiveFnBinders = /* @__PURE__ */ new Map();
|
|
333
|
+
var Reactive = new Proxy(
|
|
334
|
+
{},
|
|
335
|
+
{
|
|
639
336
|
get(target, p) {
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
}
|
|
653
|
-
return target[p];
|
|
654
|
-
},
|
|
655
|
-
});
|
|
656
|
-
function configureReactive({ components, binders, }) {
|
|
657
|
-
if (components) {
|
|
658
|
-
for (const key in components) {
|
|
659
|
-
ReactiveFns.set(key, components[key]);
|
|
660
|
-
}
|
|
337
|
+
if (!target[p]) {
|
|
338
|
+
const Component = ReactiveFns.get(p) || p;
|
|
339
|
+
const render = forwardRef((props, ref) => {
|
|
340
|
+
const propsOut = { ...props };
|
|
341
|
+
if (ref && (isFunction(ref) || !isEmpty(ref))) {
|
|
342
|
+
propsOut.ref = ref;
|
|
343
|
+
}
|
|
344
|
+
return createElement(Component, propsOut);
|
|
345
|
+
});
|
|
346
|
+
target[p] = reactive(render, ReactiveFnBinders.get(p));
|
|
347
|
+
}
|
|
348
|
+
return target[p];
|
|
661
349
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
350
|
+
}
|
|
351
|
+
);
|
|
352
|
+
function configureReactive({
|
|
353
|
+
components,
|
|
354
|
+
binders
|
|
355
|
+
}) {
|
|
356
|
+
if (components) {
|
|
357
|
+
for (const key in components) {
|
|
358
|
+
ReactiveFns.set(key, components[key]);
|
|
666
359
|
}
|
|
360
|
+
}
|
|
361
|
+
if (binders) {
|
|
362
|
+
for (const key in binders) {
|
|
363
|
+
ReactiveFnBinders.set(key, binders[key]);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
667
366
|
}
|
|
668
|
-
|
|
669
367
|
function Show({ if: if_, ifReady, else: else_, wrap, children }) {
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
368
|
+
const value = useSelector(if_ != null ? if_ : ifReady);
|
|
369
|
+
const show = ifReady !== void 0 ? isObservableValueReady(value) : value;
|
|
370
|
+
const child = useSelector(
|
|
371
|
+
show ? isFunction(children) ? () => children(value) : children : else_ != null ? else_ : null,
|
|
372
|
+
{ skipCheck: true }
|
|
373
|
+
);
|
|
374
|
+
return wrap ? createElement(wrap, void 0, child) : child;
|
|
674
375
|
}
|
|
675
376
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
377
|
+
// src/react/Switch.tsx
|
|
378
|
+
function Switch({
|
|
379
|
+
value,
|
|
380
|
+
children
|
|
381
|
+
}) {
|
|
382
|
+
var _a, _b;
|
|
383
|
+
const child = children[useSelector(value)];
|
|
384
|
+
return (_b = child ? child() : (_a = children["default"]) == null ? void 0 : _a.call(children)) != null ? _b : null;
|
|
681
385
|
}
|
|
682
|
-
|
|
683
386
|
function useComputed(compute, set, deps) {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
387
|
+
if (!deps && isArray(set)) {
|
|
388
|
+
deps = set;
|
|
389
|
+
set = void 0;
|
|
390
|
+
}
|
|
391
|
+
const ref = useRef({});
|
|
392
|
+
ref.current.compute = compute;
|
|
393
|
+
ref.current.set = set;
|
|
394
|
+
return useMemo(
|
|
395
|
+
() => computed(
|
|
396
|
+
() => isFunction(ref.current.compute) ? ref.current.compute() : ref.current.compute,
|
|
397
|
+
set ? (value) => ref.current.set(value) : void 0
|
|
398
|
+
),
|
|
399
|
+
deps || []
|
|
400
|
+
);
|
|
692
401
|
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
if (ret && isFunction(ret)) {
|
|
721
|
-
current.dispose = ret;
|
|
722
|
-
return () => queueMicrotask(dispose);
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
else {
|
|
726
|
-
return dispose;
|
|
727
|
-
}
|
|
728
|
-
}, deps);
|
|
729
|
-
}
|
|
730
|
-
else {
|
|
731
|
-
useEffect(effect, deps);
|
|
732
|
-
}
|
|
402
|
+
var useEffectOnce = (effect, deps) => {
|
|
403
|
+
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
404
|
+
const refDispose = useRef({ num: 0 });
|
|
405
|
+
useEffect(() => {
|
|
406
|
+
var _a;
|
|
407
|
+
const { current } = refDispose;
|
|
408
|
+
current.num++;
|
|
409
|
+
const dispose = () => {
|
|
410
|
+
if (current.dispose && current.num < 2) {
|
|
411
|
+
current.dispose();
|
|
412
|
+
current.dispose = void 0;
|
|
413
|
+
}
|
|
414
|
+
current.num--;
|
|
415
|
+
};
|
|
416
|
+
if (current.dispose === void 0) {
|
|
417
|
+
const ret = (_a = effect()) != null ? _a : null;
|
|
418
|
+
if (ret && isFunction(ret)) {
|
|
419
|
+
current.dispose = ret;
|
|
420
|
+
return () => queueMicrotask(dispose);
|
|
421
|
+
}
|
|
422
|
+
} else {
|
|
423
|
+
return dispose;
|
|
424
|
+
}
|
|
425
|
+
}, deps);
|
|
426
|
+
} else {
|
|
427
|
+
useEffect(effect, deps);
|
|
428
|
+
}
|
|
733
429
|
};
|
|
734
|
-
|
|
735
430
|
function useMount(fn) {
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
}, []);
|
|
431
|
+
return useEffectOnce(() => {
|
|
432
|
+
const ret = fn();
|
|
433
|
+
if (!isPromise(ret)) {
|
|
434
|
+
return ret;
|
|
435
|
+
}
|
|
436
|
+
}, []);
|
|
743
437
|
}
|
|
744
|
-
|
|
745
|
-
const useMountOnce = useMount;
|
|
746
|
-
|
|
438
|
+
var useMountOnce = useMount;
|
|
747
439
|
function useObservable(initialValue) {
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
return ref.current;
|
|
440
|
+
const ref = useRef();
|
|
441
|
+
if (!ref.current) {
|
|
442
|
+
ref.current = observable(initialValue);
|
|
443
|
+
}
|
|
444
|
+
return ref.current;
|
|
754
445
|
}
|
|
755
446
|
|
|
447
|
+
// src/react/useIsMounted.ts
|
|
756
448
|
function useIsMounted() {
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
449
|
+
const obs = useObservable(false);
|
|
450
|
+
const { set } = obs;
|
|
451
|
+
useMountOnce(() => {
|
|
452
|
+
set(true);
|
|
453
|
+
return () => set(false);
|
|
454
|
+
});
|
|
455
|
+
return obs;
|
|
764
456
|
}
|
|
765
|
-
|
|
766
457
|
function useObservableReducer(reducer, initializerArg, initializer) {
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
458
|
+
const obs = useObservable(
|
|
459
|
+
() => initializerArg !== void 0 && isFunction(initializerArg) ? initializer(initializerArg) : initializerArg
|
|
460
|
+
);
|
|
461
|
+
const dispatch = (action) => {
|
|
462
|
+
obs.set(reducer(obs.get(), action));
|
|
463
|
+
};
|
|
464
|
+
return [obs, dispatch];
|
|
772
465
|
}
|
|
773
466
|
|
|
467
|
+
// src/react/useUnmount.ts
|
|
774
468
|
function useUnmount(fn) {
|
|
775
|
-
|
|
469
|
+
return useMount(() => fn);
|
|
776
470
|
}
|
|
777
|
-
|
|
778
|
-
const useUnmountOnce = useUnmount;
|
|
471
|
+
var useUnmountOnce = useUnmount;
|
|
779
472
|
|
|
473
|
+
// src/react/useObserve.ts
|
|
780
474
|
function useObserve(selector, reactionOrOptions, options) {
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
useUnmountOnce(() => {
|
|
475
|
+
let reaction;
|
|
476
|
+
if (isFunction(reactionOrOptions)) {
|
|
477
|
+
reaction = reactionOrOptions;
|
|
478
|
+
} else {
|
|
479
|
+
options = reactionOrOptions;
|
|
480
|
+
}
|
|
481
|
+
const ref = useRef({});
|
|
482
|
+
ref.current.selector = selector;
|
|
483
|
+
ref.current.reaction = reaction;
|
|
484
|
+
if (!ref.current.dispose) {
|
|
485
|
+
ref.current.dispose = observe(
|
|
486
|
+
(e) => computeSelector(ref.current.selector, e),
|
|
487
|
+
(e) => {
|
|
795
488
|
var _a, _b;
|
|
796
|
-
(_b = (_a = ref.current)
|
|
797
|
-
|
|
798
|
-
|
|
489
|
+
return (_b = (_a = ref.current).reaction) == null ? void 0 : _b.call(_a, e);
|
|
490
|
+
},
|
|
491
|
+
options
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
useUnmountOnce(() => {
|
|
495
|
+
var _a, _b;
|
|
496
|
+
(_b = (_a = ref.current) == null ? void 0 : _a.dispose) == null ? void 0 : _b.call(_a);
|
|
497
|
+
});
|
|
498
|
+
return ref.current.dispose;
|
|
799
499
|
}
|
|
800
|
-
|
|
801
500
|
function useObserveEffect(selector, reactionOrOptions, options) {
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
501
|
+
let reaction;
|
|
502
|
+
if (isFunction(reactionOrOptions)) {
|
|
503
|
+
reaction = reactionOrOptions;
|
|
504
|
+
} else {
|
|
505
|
+
options = reactionOrOptions;
|
|
506
|
+
}
|
|
507
|
+
const ref = useRef({ selector });
|
|
508
|
+
ref.current = { selector, reaction };
|
|
509
|
+
useMountOnce(
|
|
510
|
+
() => observe(
|
|
511
|
+
(e) => {
|
|
512
|
+
const { selector: selector2 } = ref.current;
|
|
513
|
+
return isFunction(selector2) ? selector2(e) : selector2;
|
|
514
|
+
},
|
|
515
|
+
(e) => {
|
|
516
|
+
var _a, _b;
|
|
517
|
+
return (_b = (_a = ref.current).reaction) == null ? void 0 : _b.call(_a, e);
|
|
518
|
+
},
|
|
519
|
+
options
|
|
520
|
+
)
|
|
521
|
+
);
|
|
815
522
|
}
|
|
816
|
-
|
|
817
523
|
function useWhen(predicate, effect) {
|
|
818
|
-
|
|
524
|
+
return useMemo(() => when(predicate, effect), []);
|
|
819
525
|
}
|
|
820
526
|
function useWhenReady(predicate, effect) {
|
|
821
|
-
|
|
527
|
+
return useMemo(() => whenReady(predicate, effect), []);
|
|
822
528
|
}
|
|
823
529
|
|
|
824
530
|
export { Computed, For, Memo, Reactive, Show, Switch, configureReactive, hasSymbol, observer, reactive, reactiveComponents, reactiveObserver, useComputed, useEffectOnce, useIsMounted, useMount, useMountOnce, useObservable, useObservableReducer, useObserve, useObserveEffect, usePauseProvider, useSelector, useUnmount, useUnmountOnce, useWhen, useWhenReady };
|
|
825
|
-
//# sourceMappingURL=react.mjs.map
|