@legendapp/state 3.0.0-beta.0 → 3.0.0-beta.11

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 (39) hide show
  1. package/index.d.mts +2 -0
  2. package/index.d.ts +2 -0
  3. package/index.js +9 -3
  4. package/index.mjs +9 -3
  5. package/package.json +7 -1
  6. package/persist-plugins/async-storage.js +17 -9
  7. package/persist-plugins/async-storage.mjs +17 -9
  8. package/react-reactive/enableReactComponents.d.mts +3 -2
  9. package/react-reactive/enableReactComponents.d.ts +3 -2
  10. package/react-reactive/enableReactComponents.js +7 -2
  11. package/react-reactive/enableReactComponents.mjs +7 -2
  12. package/react-reactive/enableReactNativeComponents.d.mts +3 -20
  13. package/react-reactive/enableReactNativeComponents.d.ts +3 -20
  14. package/react-reactive/enableReactNativeComponents.js +8 -3
  15. package/react-reactive/enableReactNativeComponents.mjs +8 -3
  16. package/react-reactive/enableReactive.js +7 -2
  17. package/react-reactive/enableReactive.mjs +7 -2
  18. package/react-reactive/enableReactive.native.js +8 -3
  19. package/react-reactive/enableReactive.native.mjs +8 -3
  20. package/react-reactive/enableReactive.web.js +8 -3
  21. package/react-reactive/enableReactive.web.mjs +8 -3
  22. package/react.d.mts +9 -7
  23. package/react.d.ts +9 -7
  24. package/sync-plugins/crud.js +22 -24
  25. package/sync-plugins/crud.mjs +22 -24
  26. package/sync-plugins/supabase.js +14 -6
  27. package/sync-plugins/supabase.mjs +14 -6
  28. package/sync-plugins/tanstack-query.d.mts +5 -5
  29. package/sync-plugins/tanstack-query.d.ts +5 -5
  30. package/sync-plugins/tanstack-query.js +17 -2
  31. package/sync-plugins/tanstack-query.mjs +17 -2
  32. package/sync-plugins/tanstack-react-query.d.mts +4 -2
  33. package/sync-plugins/tanstack-react-query.d.ts +4 -2
  34. package/sync.js +118 -92
  35. package/sync.mjs +118 -92
  36. package/trace.js +5 -6
  37. package/trace.mjs +5 -6
  38. package/types/reactive-native.d.ts +19 -0
  39. package/types/reactive-web.d.ts +7 -0
package/index.d.mts CHANGED
@@ -187,6 +187,7 @@ interface BaseNodeInfo {
187
187
  numListenersRecursive: number;
188
188
  state?: Observable<ObservableSyncState>;
189
189
  activated?: boolean;
190
+ isPlain?: boolean;
190
191
  recursivelyAutoActivated?: boolean;
191
192
  activationState?: LinkedOptions & {
192
193
  onError?: () => void;
@@ -288,6 +289,7 @@ interface RetryOptions {
288
289
  declare const ObservableHint: {
289
290
  opaque: <T extends object>(value: T) => OpaqueObject<T>;
290
291
  plain: <T extends object>(value: T) => PlainObject<T>;
292
+ function: <T extends object>(value: T) => PlainObject<T>;
291
293
  };
292
294
 
293
295
  declare function getProxy(node: NodeInfo, p?: string, asFunction?: Function): Observable;
package/index.d.ts CHANGED
@@ -187,6 +187,7 @@ interface BaseNodeInfo {
187
187
  numListenersRecursive: number;
188
188
  state?: Observable<ObservableSyncState>;
189
189
  activated?: boolean;
190
+ isPlain?: boolean;
190
191
  recursivelyAutoActivated?: boolean;
191
192
  activationState?: LinkedOptions & {
192
193
  onError?: () => void;
@@ -288,6 +289,7 @@ interface RetryOptions {
288
289
  declare const ObservableHint: {
289
290
  opaque: <T extends object>(value: T) => OpaqueObject<T>;
290
291
  plain: <T extends object>(value: T) => PlainObject<T>;
292
+ function: <T extends object>(value: T) => PlainObject<T>;
291
293
  };
292
294
 
293
295
  declare function getProxy(node: NodeInfo, p?: string, asFunction?: Function): Observable;
package/index.js CHANGED
@@ -276,6 +276,9 @@ var ObservableHint = {
276
276
  },
277
277
  plain: function plainObject(value) {
278
278
  return addSymbol(value, symbolPlain);
279
+ },
280
+ function: function plainObject2(value) {
281
+ return addSymbol(value, symbolPlain);
279
282
  }
280
283
  };
281
284
 
@@ -384,7 +387,7 @@ function _mergeIntoObservable(target, source, levelsDeep) {
384
387
  const isSourceSet = isSet(source);
385
388
  if (isSourceSet && isSet(targetValue)) {
386
389
  target.set(/* @__PURE__ */ new Set([...source, ...targetValue]));
387
- } else if (isTargetObj && isObject(source) && !isEmpty(targetValue) || isTargetArr && targetValue.length > 0) {
390
+ } else if (isTargetObj && isObject(source) || isTargetArr && targetValue.length > 0) {
388
391
  const keys = isSourceMap || isSourceSet ? Array.from(source.keys()) : Object.keys(source);
389
392
  for (let i = 0; i < keys.length; i++) {
390
393
  const key = keys[i];
@@ -1788,7 +1791,7 @@ function peek(node) {
1788
1791
  }
1789
1792
  var isFlushing = false;
1790
1793
  function peekInternal(node, activateRecursive) {
1791
- var _a;
1794
+ var _a, _b;
1792
1795
  isFlushing = true;
1793
1796
  if (activateRecursive && ((_a = node.dirtyChildren) == null ? void 0 : _a.size)) {
1794
1797
  const dirty = Array.from(node.dirtyChildren);
@@ -1803,7 +1806,10 @@ function peekInternal(node, activateRecursive) {
1803
1806
  }
1804
1807
  isFlushing = false;
1805
1808
  let value = getNodeValue(node);
1806
- if (!globalState.isLoadingLocal) {
1809
+ if (((_b = node.parent) == null ? void 0 : _b.isPlain) || isHintPlain(value)) {
1810
+ node.isPlain = true;
1811
+ }
1812
+ if (!globalState.isLoadingLocal && !node.isPlain) {
1807
1813
  value = checkLazy(node, value, !!activateRecursive);
1808
1814
  }
1809
1815
  return value;
package/index.mjs CHANGED
@@ -274,6 +274,9 @@ var ObservableHint = {
274
274
  },
275
275
  plain: function plainObject(value) {
276
276
  return addSymbol(value, symbolPlain);
277
+ },
278
+ function: function plainObject2(value) {
279
+ return addSymbol(value, symbolPlain);
277
280
  }
278
281
  };
279
282
 
@@ -382,7 +385,7 @@ function _mergeIntoObservable(target, source, levelsDeep) {
382
385
  const isSourceSet = isSet(source);
383
386
  if (isSourceSet && isSet(targetValue)) {
384
387
  target.set(/* @__PURE__ */ new Set([...source, ...targetValue]));
385
- } else if (isTargetObj && isObject(source) && !isEmpty(targetValue) || isTargetArr && targetValue.length > 0) {
388
+ } else if (isTargetObj && isObject(source) || isTargetArr && targetValue.length > 0) {
386
389
  const keys = isSourceMap || isSourceSet ? Array.from(source.keys()) : Object.keys(source);
387
390
  for (let i = 0; i < keys.length; i++) {
388
391
  const key = keys[i];
@@ -1786,7 +1789,7 @@ function peek(node) {
1786
1789
  }
1787
1790
  var isFlushing = false;
1788
1791
  function peekInternal(node, activateRecursive) {
1789
- var _a;
1792
+ var _a, _b;
1790
1793
  isFlushing = true;
1791
1794
  if (activateRecursive && ((_a = node.dirtyChildren) == null ? void 0 : _a.size)) {
1792
1795
  const dirty = Array.from(node.dirtyChildren);
@@ -1801,7 +1804,10 @@ function peekInternal(node, activateRecursive) {
1801
1804
  }
1802
1805
  isFlushing = false;
1803
1806
  let value = getNodeValue(node);
1804
- if (!globalState.isLoadingLocal) {
1807
+ if (((_b = node.parent) == null ? void 0 : _b.isPlain) || isHintPlain(value)) {
1808
+ node.isPlain = true;
1809
+ }
1810
+ if (!globalState.isLoadingLocal && !node.isPlain) {
1805
1811
  value = checkLazy(node, value, !!activateRecursive);
1806
1812
  }
1807
1813
  return value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/state",
3
- "version": "3.0.0-beta.0",
3
+ "version": "3.0.0-beta.11",
4
4
  "description": "legend-state",
5
5
  "sideEffects": false,
6
6
  "private": false,
@@ -48,6 +48,12 @@
48
48
  "./types/babel": {
49
49
  "types": "./types/babel.d.ts"
50
50
  },
51
+ "./types/reactive-web": {
52
+ "types": "./types/reactive-web.d.ts"
53
+ },
54
+ "./types/reactive-native": {
55
+ "types": "./types/reactive-native.d.ts"
56
+ },
51
57
  ".": {
52
58
  "import": "./index.mjs",
53
59
  "require": "./index.js",
@@ -21,7 +21,10 @@ var ObservablePersistAsyncStorage = class {
21
21
  if (preload === true) {
22
22
  tables = await AsyncStorage.getAllKeys();
23
23
  } else if (state.isArray(preload)) {
24
- tables = preload;
24
+ const metadataTables = preload.map(
25
+ (table) => table.endsWith(MetadataSuffix) ? void 0 : table + MetadataSuffix
26
+ );
27
+ tables = [...preload, ...metadataTables.filter(Boolean)];
25
28
  }
26
29
  if (tables) {
27
30
  const values = await AsyncStorage.multiGet(tables);
@@ -38,14 +41,19 @@ var ObservablePersistAsyncStorage = class {
38
41
  }
39
42
  loadTable(table) {
40
43
  if (this.data[table] === void 0) {
41
- try {
42
- return (async () => {
43
- const value = await AsyncStorage.getItem(table);
44
- this.data[table] = value ? safeParse(value) : void 0;
45
- })();
46
- } catch (e) {
47
- console.error("[legend-state] ObservablePersistLocalAsyncStorage failed to parse", table);
48
- }
44
+ return AsyncStorage.multiGet([table, table + MetadataSuffix]).then((values) => {
45
+ try {
46
+ values.forEach(([table2, value]) => {
47
+ this.data[table2] = value ? safeParse(value) : void 0;
48
+ });
49
+ } catch (err) {
50
+ console.error("[legend-state] ObservablePersistLocalAsyncStorage failed to parse", table, err);
51
+ }
52
+ }).catch((err) => {
53
+ if ((err == null ? void 0 : err.message) !== "window is not defined") {
54
+ console.error("[legend-state] AsyncStorage.multiGet failed", table, err);
55
+ }
56
+ });
49
57
  }
50
58
  }
51
59
  // Gets
@@ -19,7 +19,10 @@ var ObservablePersistAsyncStorage = class {
19
19
  if (preload === true) {
20
20
  tables = await AsyncStorage.getAllKeys();
21
21
  } else if (isArray(preload)) {
22
- tables = preload;
22
+ const metadataTables = preload.map(
23
+ (table) => table.endsWith(MetadataSuffix) ? void 0 : table + MetadataSuffix
24
+ );
25
+ tables = [...preload, ...metadataTables.filter(Boolean)];
23
26
  }
24
27
  if (tables) {
25
28
  const values = await AsyncStorage.multiGet(tables);
@@ -36,14 +39,19 @@ var ObservablePersistAsyncStorage = class {
36
39
  }
37
40
  loadTable(table) {
38
41
  if (this.data[table] === void 0) {
39
- try {
40
- return (async () => {
41
- const value = await AsyncStorage.getItem(table);
42
- this.data[table] = value ? safeParse(value) : void 0;
43
- })();
44
- } catch (e) {
45
- console.error("[legend-state] ObservablePersistLocalAsyncStorage failed to parse", table);
46
- }
42
+ return AsyncStorage.multiGet([table, table + MetadataSuffix]).then((values) => {
43
+ try {
44
+ values.forEach(([table2, value]) => {
45
+ this.data[table2] = value ? safeParse(value) : void 0;
46
+ });
47
+ } catch (err) {
48
+ console.error("[legend-state] ObservablePersistLocalAsyncStorage failed to parse", table, err);
49
+ }
50
+ }).catch((err) => {
51
+ if ((err == null ? void 0 : err.message) !== "window is not defined") {
52
+ console.error("[legend-state] AsyncStorage.multiGet failed", table, err);
53
+ }
54
+ });
47
55
  }
48
56
  }
49
57
  // Gets
@@ -1,9 +1,10 @@
1
1
  import { FCReactiveObject, configureReactive } from '@legendapp/state/react';
2
2
 
3
- declare function enableReactComponents(config: typeof configureReactive): void;
3
+ declare function enableReactComponents_(config: typeof configureReactive): void;
4
+
4
5
  declare module '@legendapp/state/react' {
5
6
  interface IReactive extends FCReactiveObject<JSX.IntrinsicElements> {
6
7
  }
7
8
  }
8
9
 
9
- export { enableReactComponents };
10
+ export { enableReactComponents_ };
@@ -1,9 +1,10 @@
1
1
  import { FCReactiveObject, configureReactive } from '@legendapp/state/react';
2
2
 
3
- declare function enableReactComponents(config: typeof configureReactive): void;
3
+ declare function enableReactComponents_(config: typeof configureReactive): void;
4
+
4
5
  declare module '@legendapp/state/react' {
5
6
  interface IReactive extends FCReactiveObject<JSX.IntrinsicElements> {
6
7
  }
7
8
  }
8
9
 
9
- export { enableReactComponents };
10
+ export { enableReactComponents_ };
@@ -1,7 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  // src/react-reactive/enableReactComponents.ts
4
- function enableReactComponents(config) {
4
+ var isEnabled = false;
5
+ function enableReactComponents_(config) {
6
+ if (isEnabled) {
7
+ return;
8
+ }
9
+ isEnabled = true;
5
10
  const bindInfo = { value: { handler: "onChange", getValue: (e) => e.target.value, defaultValue: "" } };
6
11
  const bindInfoInput = Object.assign(
7
12
  { checked: { handler: "onChange", getValue: (e) => e.target.checked } },
@@ -16,4 +21,4 @@ function enableReactComponents(config) {
16
21
  });
17
22
  }
18
23
 
19
- exports.enableReactComponents = enableReactComponents;
24
+ exports.enableReactComponents_ = enableReactComponents_;
@@ -1,5 +1,10 @@
1
1
  // src/react-reactive/enableReactComponents.ts
2
- function enableReactComponents(config) {
2
+ var isEnabled = false;
3
+ function enableReactComponents_(config) {
4
+ if (isEnabled) {
5
+ return;
6
+ }
7
+ isEnabled = true;
3
8
  const bindInfo = { value: { handler: "onChange", getValue: (e) => e.target.value, defaultValue: "" } };
4
9
  const bindInfoInput = Object.assign(
5
10
  { checked: { handler: "onChange", getValue: (e) => e.target.checked } },
@@ -14,4 +19,4 @@ function enableReactComponents(config) {
14
19
  });
15
20
  }
16
21
 
17
- export { enableReactComponents };
22
+ export { enableReactComponents_ };
@@ -1,22 +1,5 @@
1
- import { FCReactiveObject, FCReactive, configureReactive } from '@legendapp/state/react';
2
- import { ActivityIndicator, ActivityIndicatorProps, Button, ButtonProps, FlatList, FlatListProps, Image, ImageProps, Pressable, PressableProps, ScrollView, ScrollViewProps, SectionList, SectionListProps, Switch, SwitchProps, Text, TextProps, TextInput, TextInputProps, TouchableWithoutFeedback, TouchableWithoutFeedbackProps, View, ViewProps } from 'react-native';
1
+ import { configureReactive } from '@legendapp/state/react';
3
2
 
4
- declare function enableReactNativeComponents(configure: typeof configureReactive): void;
5
- declare module '@legendapp/state/react' {
6
- interface IReactive extends FCReactiveObject<JSX.IntrinsicElements> {
7
- ActivityIndicator: FCReactive<ActivityIndicator, ActivityIndicatorProps>;
8
- Button: FCReactive<Button, ButtonProps>;
9
- FlatList: FCReactive<FlatList, FlatListProps<any>>;
10
- Image: FCReactive<Image, ImageProps>;
11
- Pressable: FCReactive<typeof Pressable, PressableProps>;
12
- ScrollView: FCReactive<ScrollView, ScrollViewProps>;
13
- SectionList: FCReactive<SectionList, SectionListProps<any>>;
14
- Switch: FCReactive<Switch, SwitchProps>;
15
- Text: FCReactive<Text, TextProps>;
16
- TextInput: FCReactive<TextInput, TextInputProps>;
17
- TouchableWithoutFeedback: FCReactive<TouchableWithoutFeedback, TouchableWithoutFeedbackProps>;
18
- View: FCReactive<View, ViewProps>;
19
- }
20
- }
3
+ declare function enableReactNativeComponents_(configure: typeof configureReactive): void;
21
4
 
22
- export { enableReactNativeComponents };
5
+ export { enableReactNativeComponents_ };
@@ -1,22 +1,5 @@
1
- import { FCReactiveObject, FCReactive, configureReactive } from '@legendapp/state/react';
2
- import { ActivityIndicator, ActivityIndicatorProps, Button, ButtonProps, FlatList, FlatListProps, Image, ImageProps, Pressable, PressableProps, ScrollView, ScrollViewProps, SectionList, SectionListProps, Switch, SwitchProps, Text, TextProps, TextInput, TextInputProps, TouchableWithoutFeedback, TouchableWithoutFeedbackProps, View, ViewProps } from 'react-native';
1
+ import { configureReactive } from '@legendapp/state/react';
3
2
 
4
- declare function enableReactNativeComponents(configure: typeof configureReactive): void;
5
- declare module '@legendapp/state/react' {
6
- interface IReactive extends FCReactiveObject<JSX.IntrinsicElements> {
7
- ActivityIndicator: FCReactive<ActivityIndicator, ActivityIndicatorProps>;
8
- Button: FCReactive<Button, ButtonProps>;
9
- FlatList: FCReactive<FlatList, FlatListProps<any>>;
10
- Image: FCReactive<Image, ImageProps>;
11
- Pressable: FCReactive<typeof Pressable, PressableProps>;
12
- ScrollView: FCReactive<ScrollView, ScrollViewProps>;
13
- SectionList: FCReactive<SectionList, SectionListProps<any>>;
14
- Switch: FCReactive<Switch, SwitchProps>;
15
- Text: FCReactive<Text, TextProps>;
16
- TextInput: FCReactive<TextInput, TextInputProps>;
17
- TouchableWithoutFeedback: FCReactive<TouchableWithoutFeedback, TouchableWithoutFeedbackProps>;
18
- View: FCReactive<View, ViewProps>;
19
- }
20
- }
3
+ declare function enableReactNativeComponents_(configure: typeof configureReactive): void;
21
4
 
22
- export { enableReactNativeComponents };
5
+ export { enableReactNativeComponents_ };
@@ -1,11 +1,16 @@
1
1
  'use strict';
2
2
 
3
- var react = require('react');
4
3
  var react$1 = require('@legendapp/state/react');
4
+ var react = require('react');
5
5
  var reactNative = require('react-native');
6
6
 
7
7
  // src/react-reactive/enableReactNativeComponents.ts
8
- function enableReactNativeComponents(configure) {
8
+ var isEnabled = false;
9
+ function enableReactNativeComponents_(configure) {
10
+ if (isEnabled) {
11
+ return;
12
+ }
13
+ isEnabled = true;
9
14
  configure({
10
15
  components: {
11
16
  ActivityIndicator: reactNative.ActivityIndicator,
@@ -50,4 +55,4 @@ function enableReactNativeComponents(configure) {
50
55
  });
51
56
  }
52
57
 
53
- exports.enableReactNativeComponents = enableReactNativeComponents;
58
+ exports.enableReactNativeComponents_ = enableReactNativeComponents_;
@@ -1,9 +1,14 @@
1
- import { useRef } from 'react';
2
1
  import { useSelector } from '@legendapp/state/react';
2
+ import { useRef } from 'react';
3
3
  import { ActivityIndicator, Button, FlatList, Image, Pressable, ScrollView, SectionList, Switch, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
4
4
 
5
5
  // src/react-reactive/enableReactNativeComponents.ts
6
- function enableReactNativeComponents(configure) {
6
+ var isEnabled = false;
7
+ function enableReactNativeComponents_(configure) {
8
+ if (isEnabled) {
9
+ return;
10
+ }
11
+ isEnabled = true;
7
12
  configure({
8
13
  components: {
9
14
  ActivityIndicator,
@@ -48,4 +53,4 @@ function enableReactNativeComponents(configure) {
48
53
  });
49
54
  }
50
55
 
51
- export { enableReactNativeComponents };
56
+ export { enableReactNativeComponents_ };
@@ -1,7 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  // src/react-reactive/enableReactComponents.ts
4
- function enableReactComponents(config) {
4
+ var isEnabled = false;
5
+ function enableReactComponents_(config) {
6
+ if (isEnabled) {
7
+ return;
8
+ }
9
+ isEnabled = true;
5
10
  const bindInfo = { value: { handler: "onChange", getValue: (e) => e.target.value, defaultValue: "" } };
6
11
  const bindInfoInput = Object.assign(
7
12
  { checked: { handler: "onChange", getValue: (e) => e.target.checked } },
@@ -18,7 +23,7 @@ function enableReactComponents(config) {
18
23
 
19
24
  // src/react-reactive/enableReactive.ts
20
25
  function enableReactive(config) {
21
- enableReactComponents(config);
26
+ enableReactComponents_(config);
22
27
  }
23
28
 
24
29
  exports.enableReactive = enableReactive;
@@ -1,5 +1,10 @@
1
1
  // src/react-reactive/enableReactComponents.ts
2
- function enableReactComponents(config) {
2
+ var isEnabled = false;
3
+ function enableReactComponents_(config) {
4
+ if (isEnabled) {
5
+ return;
6
+ }
7
+ isEnabled = true;
3
8
  const bindInfo = { value: { handler: "onChange", getValue: (e) => e.target.value, defaultValue: "" } };
4
9
  const bindInfoInput = Object.assign(
5
10
  { checked: { handler: "onChange", getValue: (e) => e.target.checked } },
@@ -16,7 +21,7 @@ function enableReactComponents(config) {
16
21
 
17
22
  // src/react-reactive/enableReactive.ts
18
23
  function enableReactive(config) {
19
- enableReactComponents(config);
24
+ enableReactComponents_(config);
20
25
  }
21
26
 
22
27
  export { enableReactive };
@@ -1,11 +1,16 @@
1
1
  'use strict';
2
2
 
3
- var react = require('react');
4
3
  var react$1 = require('@legendapp/state/react');
4
+ var react = require('react');
5
5
  var reactNative = require('react-native');
6
6
 
7
7
  // src/react-reactive/enableReactNativeComponents.ts
8
- function enableReactNativeComponents(configure) {
8
+ var isEnabled = false;
9
+ function enableReactNativeComponents_(configure) {
10
+ if (isEnabled) {
11
+ return;
12
+ }
13
+ isEnabled = true;
9
14
  configure({
10
15
  components: {
11
16
  ActivityIndicator: reactNative.ActivityIndicator,
@@ -52,7 +57,7 @@ function enableReactNativeComponents(configure) {
52
57
 
53
58
  // src/react-reactive/enableReactive.native.ts
54
59
  function enableReactive(configure) {
55
- enableReactNativeComponents(configure);
60
+ enableReactNativeComponents_(configure);
56
61
  }
57
62
 
58
63
  exports.enableReactive = enableReactive;
@@ -1,9 +1,14 @@
1
- import { useRef } from 'react';
2
1
  import { useSelector } from '@legendapp/state/react';
2
+ import { useRef } from 'react';
3
3
  import { ActivityIndicator, Button, FlatList, Image, Pressable, ScrollView, SectionList, Switch, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
4
4
 
5
5
  // src/react-reactive/enableReactNativeComponents.ts
6
- function enableReactNativeComponents(configure) {
6
+ var isEnabled = false;
7
+ function enableReactNativeComponents_(configure) {
8
+ if (isEnabled) {
9
+ return;
10
+ }
11
+ isEnabled = true;
7
12
  configure({
8
13
  components: {
9
14
  ActivityIndicator,
@@ -50,7 +55,7 @@ function enableReactNativeComponents(configure) {
50
55
 
51
56
  // src/react-reactive/enableReactive.native.ts
52
57
  function enableReactive(configure) {
53
- enableReactNativeComponents(configure);
58
+ enableReactNativeComponents_(configure);
54
59
  }
55
60
 
56
61
  export { enableReactive };
@@ -1,11 +1,16 @@
1
1
  'use strict';
2
2
 
3
- var react = require('react');
4
3
  var react$1 = require('@legendapp/state/react');
4
+ var react = require('react');
5
5
  var reactNative = require('react-native');
6
6
 
7
7
  // src/react-reactive/enableReactNativeComponents.ts
8
- function enableReactNativeComponents(configure) {
8
+ var isEnabled = false;
9
+ function enableReactNativeComponents_(configure) {
10
+ if (isEnabled) {
11
+ return;
12
+ }
13
+ isEnabled = true;
9
14
  configure({
10
15
  components: {
11
16
  ActivityIndicator: reactNative.ActivityIndicator,
@@ -52,7 +57,7 @@ function enableReactNativeComponents(configure) {
52
57
 
53
58
  // src/react-reactive/enableReactive.web.ts
54
59
  function enableReactive(configure) {
55
- enableReactNativeComponents(configure);
60
+ enableReactNativeComponents_(configure);
56
61
  }
57
62
 
58
63
  exports.enableReactive = enableReactive;
@@ -1,9 +1,14 @@
1
- import { useRef } from 'react';
2
1
  import { useSelector } from '@legendapp/state/react';
2
+ import { useRef } from 'react';
3
3
  import { ActivityIndicator, Button, FlatList, Image, Pressable, ScrollView, SectionList, Switch, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
4
4
 
5
5
  // src/react-reactive/enableReactNativeComponents.ts
6
- function enableReactNativeComponents(configure) {
6
+ var isEnabled = false;
7
+ function enableReactNativeComponents_(configure) {
8
+ if (isEnabled) {
9
+ return;
10
+ }
11
+ isEnabled = true;
7
12
  configure({
8
13
  components: {
9
14
  ActivityIndicator,
@@ -50,7 +55,7 @@ function enableReactNativeComponents(configure) {
50
55
 
51
56
  // src/react-reactive/enableReactive.web.ts
52
57
  function enableReactive(configure) {
53
- enableReactNativeComponents(configure);
58
+ enableReactNativeComponents_(configure);
54
59
  }
55
60
 
56
61
  export { enableReactive };
package/react.d.mts CHANGED
@@ -77,7 +77,7 @@ interface BindKey<P> {
77
77
  defaultValue?: any;
78
78
  selector?: (propsOut: Record<string, any>, p: Observable<any>) => any;
79
79
  }
80
- type BindKeys<P = any> = Record<keyof P, BindKey<P>>;
80
+ type BindKeys<P = any> = Partial<Record<keyof P, BindKey<P>>>;
81
81
  type FCReactiveObject<T> = {
82
82
  [K in keyof T]: FC<ShapeWithNew$<T[K]>>;
83
83
  };
@@ -101,10 +101,10 @@ type ObjectShapeWith$<T> = {
101
101
  type ExtractFCPropsType<T> = T extends FC<infer P> ? P : never;
102
102
  declare const hasSymbol: false | ((key: string) => symbol);
103
103
  declare function observer<P extends FC<any>>(component: P): P;
104
- declare function reactive<T extends FC<any>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T | FC<ShapeWith$<ExtractFCPropsType<T>>>;
105
- declare function reactive<T extends FC<any>, T2 extends keyof ExtractFCPropsType<T>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T | FC<ShapeWithPick$<ExtractFCPropsType<T>, T2>>;
106
- declare function reactiveObserver<T extends FC<any>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T | FC<ShapeWith$<ExtractFCPropsType<T>>>;
107
- declare function reactiveObserver<T extends FC<any>, T2 extends keyof ExtractFCPropsType<T>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T | FC<ShapeWithPick$<ExtractFCPropsType<T>, T2>>;
104
+ declare function reactive<T extends FC<any>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T & FC<ShapeWith$<ExtractFCPropsType<T>>>;
105
+ declare function reactive<T extends FC<any>, T2 extends keyof ExtractFCPropsType<T>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T & FC<ShapeWithPick$<ExtractFCPropsType<T>, T2>>;
106
+ declare function reactiveObserver<T extends FC<any>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T & FC<ShapeWith$<ExtractFCPropsType<T>>>;
107
+ declare function reactiveObserver<T extends FC<any>, T2 extends keyof ExtractFCPropsType<T>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T & FC<ShapeWithPick$<ExtractFCPropsType<T>, T2>>;
108
108
  declare function reactiveComponents<P extends Record<string, FC>>(components: P): ObjectShapeWith$<P>;
109
109
 
110
110
  declare function useComputed<T>(get: () => T | Promise<T>): Observable<T>;
@@ -151,8 +151,10 @@ declare function useSelector<T>(selector: Selector<T>, options?: UseSelectorOpti
151
151
  declare function useUnmount(fn: () => void): void;
152
152
  declare const useUnmountOnce: typeof useUnmount;
153
153
 
154
- declare function useWhen<T>(predicate: Selector<T>, effect: (value: T) => any | (() => any)): Promise<any>;
155
- declare function useWhenReady<T>(predicate: Selector<T>, effect: (value: T) => any | (() => any)): Promise<any>;
154
+ declare function useWhen<T>(predicate: Selector<T>): Promise<T>;
155
+ declare function useWhen<T, T2>(predicate: Selector<T>, effect: (value: T) => T2): Promise<T2>;
156
+ declare function useWhenReady<T>(predicate: Selector<T>): Promise<T>;
157
+ declare function useWhenReady<T, T2>(predicate: Selector<T>, effect: (value: T) => T2 | (() => T2)): Promise<T2>;
156
158
 
157
159
  declare function configureReactive({ components, binders, }: {
158
160
  components?: Record<string, FC | ComponentClass<any>>;
package/react.d.ts CHANGED
@@ -77,7 +77,7 @@ interface BindKey<P> {
77
77
  defaultValue?: any;
78
78
  selector?: (propsOut: Record<string, any>, p: Observable<any>) => any;
79
79
  }
80
- type BindKeys<P = any> = Record<keyof P, BindKey<P>>;
80
+ type BindKeys<P = any> = Partial<Record<keyof P, BindKey<P>>>;
81
81
  type FCReactiveObject<T> = {
82
82
  [K in keyof T]: FC<ShapeWithNew$<T[K]>>;
83
83
  };
@@ -101,10 +101,10 @@ type ObjectShapeWith$<T> = {
101
101
  type ExtractFCPropsType<T> = T extends FC<infer P> ? P : never;
102
102
  declare const hasSymbol: false | ((key: string) => symbol);
103
103
  declare function observer<P extends FC<any>>(component: P): P;
104
- declare function reactive<T extends FC<any>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T | FC<ShapeWith$<ExtractFCPropsType<T>>>;
105
- declare function reactive<T extends FC<any>, T2 extends keyof ExtractFCPropsType<T>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T | FC<ShapeWithPick$<ExtractFCPropsType<T>, T2>>;
106
- declare function reactiveObserver<T extends FC<any>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T | FC<ShapeWith$<ExtractFCPropsType<T>>>;
107
- declare function reactiveObserver<T extends FC<any>, T2 extends keyof ExtractFCPropsType<T>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T | FC<ShapeWithPick$<ExtractFCPropsType<T>, T2>>;
104
+ declare function reactive<T extends FC<any>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T & FC<ShapeWith$<ExtractFCPropsType<T>>>;
105
+ declare function reactive<T extends FC<any>, T2 extends keyof ExtractFCPropsType<T>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T & FC<ShapeWithPick$<ExtractFCPropsType<T>, T2>>;
106
+ declare function reactiveObserver<T extends FC<any>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T & FC<ShapeWith$<ExtractFCPropsType<T>>>;
107
+ declare function reactiveObserver<T extends FC<any>, T2 extends keyof ExtractFCPropsType<T>>(component: T, bindKeys?: BindKeys<ExtractFCPropsType<T>>): T & FC<ShapeWithPick$<ExtractFCPropsType<T>, T2>>;
108
108
  declare function reactiveComponents<P extends Record<string, FC>>(components: P): ObjectShapeWith$<P>;
109
109
 
110
110
  declare function useComputed<T>(get: () => T | Promise<T>): Observable<T>;
@@ -151,8 +151,10 @@ declare function useSelector<T>(selector: Selector<T>, options?: UseSelectorOpti
151
151
  declare function useUnmount(fn: () => void): void;
152
152
  declare const useUnmountOnce: typeof useUnmount;
153
153
 
154
- declare function useWhen<T>(predicate: Selector<T>, effect: (value: T) => any | (() => any)): Promise<any>;
155
- declare function useWhenReady<T>(predicate: Selector<T>, effect: (value: T) => any | (() => any)): Promise<any>;
154
+ declare function useWhen<T>(predicate: Selector<T>): Promise<T>;
155
+ declare function useWhen<T, T2>(predicate: Selector<T>, effect: (value: T) => T2): Promise<T2>;
156
+ declare function useWhenReady<T>(predicate: Selector<T>): Promise<T>;
157
+ declare function useWhenReady<T, T2>(predicate: Selector<T>, effect: (value: T) => T2 | (() => T2)): Promise<T2>;
156
158
 
157
159
  declare function configureReactive({ components, binders, }: {
158
160
  components?: Record<string, FC | ComponentClass<any>>;