@legendapp/state 3.0.0-beta.7 → 3.0.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/state",
3
- "version": "3.0.0-beta.7",
3
+ "version": "3.0.0-beta.9",
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",
@@ -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
@@ -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>;
package/react.d.ts CHANGED
@@ -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>;
@@ -256,40 +256,38 @@ function syncedCrud(props) {
256
256
  const saveResult = async (itemKey, input, data, isCreate) => {
257
257
  var _a;
258
258
  if (data) {
259
- const saved = (transform == null ? void 0 : transform.load) ? await transform.load(data, "set") : data;
259
+ let saved = (transform == null ? void 0 : transform.load) ? await transform.load(data, "set") : data;
260
260
  const isChild = itemKey !== "undefined" && asType !== "value";
261
261
  const currentPeeked = state.getNodeValue(node);
262
262
  const currentValue = isChild ? (_a = asType === "array" && state.isArray(currentPeeked) ? currentPeeked.find((v) => v[fieldId] === itemKey) : void 0) != null ? _a : currentPeeked[itemKey] : currentPeeked;
263
- const dataOnSaved = {
264
- saved,
265
- input,
266
- currentValue,
267
- isCreate,
268
- props
269
- };
270
- let savedOut = saved;
271
- if (savedOut && !state.isNullOrUndefined(currentValue)) {
272
- savedOut = clone(savedOut);
273
- Object.keys(savedOut).forEach((key) => {
263
+ if (saved && !state.isNullOrUndefined(currentValue)) {
264
+ if (onSaved) {
265
+ const ret = onSaved({
266
+ saved,
267
+ input,
268
+ currentValue,
269
+ isCreate,
270
+ props
271
+ });
272
+ if (ret) {
273
+ saved = ret;
274
+ }
275
+ }
276
+ saved = clone(saved);
277
+ Object.keys(saved).forEach((key) => {
274
278
  const i = input[key];
275
279
  const c = currentValue[key];
276
280
  if (
277
281
  // value is already the new value, can ignore
278
- savedOut[key] === c || // user has changed local value
279
- key !== "id" && i !== c
282
+ saved[key] === c || // user has changed local value
283
+ key !== fieldId && i !== c
280
284
  ) {
281
- delete savedOut[key];
285
+ delete saved[key];
282
286
  }
283
287
  });
284
- if (onSaved) {
285
- const ret = onSaved(dataOnSaved);
286
- if (ret) {
287
- savedOut = ret;
288
- }
289
- }
290
- const createdAt = fieldCreatedAt ? savedOut[fieldCreatedAt] : void 0;
291
- const updatedAt = fieldUpdatedAt ? savedOut[fieldUpdatedAt] : void 0;
292
- const value2 = itemKey !== "undefined" && asType !== "value" ? { [itemKey]: savedOut } : savedOut;
288
+ const createdAt = fieldCreatedAt ? saved[fieldCreatedAt] : void 0;
289
+ const updatedAt = fieldUpdatedAt ? saved[fieldUpdatedAt] : void 0;
290
+ const value2 = itemKey !== "undefined" && asType !== "value" ? { [itemKey]: saved } : saved;
293
291
  update({
294
292
  value: value2,
295
293
  lastSync: updatedAt || createdAt ? +new Date(updatedAt || createdAt) : void 0,
@@ -254,40 +254,38 @@ function syncedCrud(props) {
254
254
  const saveResult = async (itemKey, input, data, isCreate) => {
255
255
  var _a;
256
256
  if (data) {
257
- const saved = (transform == null ? void 0 : transform.load) ? await transform.load(data, "set") : data;
257
+ let saved = (transform == null ? void 0 : transform.load) ? await transform.load(data, "set") : data;
258
258
  const isChild = itemKey !== "undefined" && asType !== "value";
259
259
  const currentPeeked = getNodeValue(node);
260
260
  const currentValue = isChild ? (_a = asType === "array" && isArray(currentPeeked) ? currentPeeked.find((v) => v[fieldId] === itemKey) : void 0) != null ? _a : currentPeeked[itemKey] : currentPeeked;
261
- const dataOnSaved = {
262
- saved,
263
- input,
264
- currentValue,
265
- isCreate,
266
- props
267
- };
268
- let savedOut = saved;
269
- if (savedOut && !isNullOrUndefined(currentValue)) {
270
- savedOut = clone(savedOut);
271
- Object.keys(savedOut).forEach((key) => {
261
+ if (saved && !isNullOrUndefined(currentValue)) {
262
+ if (onSaved) {
263
+ const ret = onSaved({
264
+ saved,
265
+ input,
266
+ currentValue,
267
+ isCreate,
268
+ props
269
+ });
270
+ if (ret) {
271
+ saved = ret;
272
+ }
273
+ }
274
+ saved = clone(saved);
275
+ Object.keys(saved).forEach((key) => {
272
276
  const i = input[key];
273
277
  const c = currentValue[key];
274
278
  if (
275
279
  // value is already the new value, can ignore
276
- savedOut[key] === c || // user has changed local value
277
- key !== "id" && i !== c
280
+ saved[key] === c || // user has changed local value
281
+ key !== fieldId && i !== c
278
282
  ) {
279
- delete savedOut[key];
283
+ delete saved[key];
280
284
  }
281
285
  });
282
- if (onSaved) {
283
- const ret = onSaved(dataOnSaved);
284
- if (ret) {
285
- savedOut = ret;
286
- }
287
- }
288
- const createdAt = fieldCreatedAt ? savedOut[fieldCreatedAt] : void 0;
289
- const updatedAt = fieldUpdatedAt ? savedOut[fieldUpdatedAt] : void 0;
290
- const value2 = itemKey !== "undefined" && asType !== "value" ? { [itemKey]: savedOut } : savedOut;
286
+ const createdAt = fieldCreatedAt ? saved[fieldCreatedAt] : void 0;
287
+ const updatedAt = fieldUpdatedAt ? saved[fieldUpdatedAt] : void 0;
288
+ const value2 = itemKey !== "undefined" && asType !== "value" ? { [itemKey]: saved } : saved;
291
289
  update({
292
290
  value: value2,
293
291
  lastSync: updatedAt || createdAt ? +new Date(updatedAt || createdAt) : void 0,
package/trace.js CHANGED
@@ -19,13 +19,12 @@ function getNodePath(node) {
19
19
  // src/trace/useTraceListeners.ts
20
20
  var { optimized, tracking } = state.internal;
21
21
  function useTraceListeners(name) {
22
- if (process.env.NODE_ENV === "development" && tracking.current) {
22
+ if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && tracking.current) {
23
23
  tracking.current.traceListeners = traceNodes.bind(this, name);
24
24
  }
25
25
  }
26
26
  function traceNodes(name, nodes) {
27
- if (process.env.NODE_ENV === "development" && tracking.current) {
28
- tracking.current.traceListeners = void 0;
27
+ if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && nodes.size) {
29
28
  const arr = [];
30
29
  if (nodes) {
31
30
  for (const tracked of nodes.values()) {
@@ -45,7 +44,7 @@ ${arr.join("\n")}`
45
44
  }
46
45
  var { tracking: tracking2 } = state.internal;
47
46
  function useTraceUpdates(name) {
48
- if (process.env.NODE_ENV === "development" && tracking2.current) {
47
+ if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && tracking2.current) {
49
48
  tracking2.current.traceUpdates = replaceUpdateFn.bind(void 0, name);
50
49
  }
51
50
  }
@@ -54,13 +53,13 @@ function replaceUpdateFn(name, updateFn) {
54
53
  }
55
54
  function onChange(name, updateFn, params) {
56
55
  const { changes } = params;
57
- if (process.env.NODE_ENV === "development") {
56
+ if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
58
57
  changes.forEach(({ path, valueAtPath, prevAtPath }) => {
59
58
  console.log(`[legend-state] Rendering ${name ? name + " " : ""}because "${path}" changed:
60
59
  from: ${JSON.stringify(prevAtPath)}
61
60
  to: ${JSON.stringify(valueAtPath)}`);
62
61
  });
63
- return updateFn();
62
+ return updateFn(params);
64
63
  }
65
64
  }
66
65
  var { optimized: optimized2, tracking: tracking3 } = state.internal;
package/trace.mjs CHANGED
@@ -17,13 +17,12 @@ function getNodePath(node) {
17
17
  // src/trace/useTraceListeners.ts
18
18
  var { optimized, tracking } = internal;
19
19
  function useTraceListeners(name) {
20
- if (process.env.NODE_ENV === "development" && tracking.current) {
20
+ if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && tracking.current) {
21
21
  tracking.current.traceListeners = traceNodes.bind(this, name);
22
22
  }
23
23
  }
24
24
  function traceNodes(name, nodes) {
25
- if (process.env.NODE_ENV === "development" && tracking.current) {
26
- tracking.current.traceListeners = void 0;
25
+ if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && nodes.size) {
27
26
  const arr = [];
28
27
  if (nodes) {
29
28
  for (const tracked of nodes.values()) {
@@ -43,7 +42,7 @@ ${arr.join("\n")}`
43
42
  }
44
43
  var { tracking: tracking2 } = internal;
45
44
  function useTraceUpdates(name) {
46
- if (process.env.NODE_ENV === "development" && tracking2.current) {
45
+ if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && tracking2.current) {
47
46
  tracking2.current.traceUpdates = replaceUpdateFn.bind(void 0, name);
48
47
  }
49
48
  }
@@ -52,13 +51,13 @@ function replaceUpdateFn(name, updateFn) {
52
51
  }
53
52
  function onChange(name, updateFn, params) {
54
53
  const { changes } = params;
55
- if (process.env.NODE_ENV === "development") {
54
+ if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
56
55
  changes.forEach(({ path, valueAtPath, prevAtPath }) => {
57
56
  console.log(`[legend-state] Rendering ${name ? name + " " : ""}because "${path}" changed:
58
57
  from: ${JSON.stringify(prevAtPath)}
59
58
  to: ${JSON.stringify(valueAtPath)}`);
60
59
  });
61
- return updateFn();
60
+ return updateFn(params);
62
61
  }
63
62
  }
64
63
  var { optimized: optimized2, tracking: tracking3 } = internal;
@@ -0,0 +1,19 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
+ import type { IReactive } from '@legendapp/state/react';
3
+
4
+ declare module '@legendapp/state/react' {
5
+ interface IReactive {
6
+ ActivityIndicator: FCReactive<ActivityIndicator, ActivityIndicatorProps>;
7
+ Button: FCReactive<Button, ButtonProps>;
8
+ FlatList: FCReactive<FlatList, FlatListProps<any>>;
9
+ Image: FCReactive<Image, ImageProps>;
10
+ Pressable: FCReactive<typeof Pressable, PressableProps>;
11
+ ScrollView: FCReactive<ScrollView, ScrollViewProps>;
12
+ SectionList: FCReactive<SectionList, SectionListProps<any>>;
13
+ Switch: FCReactive<Switch, SwitchProps>;
14
+ Text: FCReactive<Text, TextProps>;
15
+ TextInput: FCReactive<TextInput, TextInputProps>;
16
+ TouchableWithoutFeedback: FCReactive<TouchableWithoutFeedback, TouchableWithoutFeedbackProps>;
17
+ View: FCReactive<View, ViewProps>;
18
+ }
19
+ }
@@ -0,0 +1,7 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
+ import type { IReactive, FCReactiveObject } from '@legendapp/state/react';
3
+
4
+ declare module '@legendapp/state/react' {
5
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
6
+ interface IReactive extends FCReactiveObject<JSX.IntrinsicElements> {}
7
+ }