@legendapp/state 3.0.0-beta.19 → 3.0.0-beta.20
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/config/enableReactTracking.d.mts +2 -2
- package/config/enableReactTracking.d.ts +2 -2
- package/config/enableReactTracking.js +16 -7
- package/config/enableReactTracking.mjs +16 -7
- package/index.js +11 -2
- package/index.mjs +11 -2
- package/package.json +16 -1
- package/react-native.d.mts +4 -0
- package/react-native.d.ts +4 -0
- package/react-native.js +53 -0
- package/react-native.mjs +40 -0
- package/react-reactive/Components.d.mts +19 -0
- package/react-reactive/Components.d.ts +19 -0
- package/react-reactive/Components.js +53 -0
- package/react-reactive/Components.mjs +40 -0
- package/react-web.d.mts +6 -0
- package/react-web.d.ts +6 -0
- package/react-web.js +39 -0
- package/react-web.mjs +37 -0
- package/react.d.mts +4 -10
- package/react.d.ts +4 -10
- package/react.js +40 -70
- package/react.mjs +41 -70
- package/sync-plugins/crud.d.mts +12 -5
- package/sync-plugins/crud.d.ts +12 -5
- package/sync-plugins/crud.js +4 -4
- package/sync-plugins/crud.mjs +5 -5
- package/sync-plugins/keel.d.mts +2 -2
- package/sync-plugins/keel.d.ts +2 -2
- package/sync-plugins/supabase.js +21 -18
- package/sync-plugins/supabase.mjs +21 -18
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
interface ReactTrackingOptions {
|
|
2
2
|
auto?: boolean;
|
|
3
3
|
warnUnobserved?: boolean;
|
|
4
|
-
|
|
4
|
+
warnMissingUse?: boolean;
|
|
5
5
|
}
|
|
6
|
-
declare function enableReactTracking({ auto, warnUnobserved,
|
|
6
|
+
declare function enableReactTracking({ auto, warnUnobserved, warnMissingUse }: ReactTrackingOptions): void;
|
|
7
7
|
|
|
8
8
|
export { enableReactTracking };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
interface ReactTrackingOptions {
|
|
2
2
|
auto?: boolean;
|
|
3
3
|
warnUnobserved?: boolean;
|
|
4
|
-
|
|
4
|
+
warnMissingUse?: boolean;
|
|
5
5
|
}
|
|
6
|
-
declare function enableReactTracking({ auto, warnUnobserved,
|
|
6
|
+
declare function enableReactTracking({ auto, warnUnobserved, warnMissingUse }: ReactTrackingOptions): void;
|
|
7
7
|
|
|
8
8
|
export { enableReactTracking };
|
|
@@ -6,9 +6,9 @@ var react$1 = require('@legendapp/state/react');
|
|
|
6
6
|
var react = require('react');
|
|
7
7
|
|
|
8
8
|
// src/config/enableReactTracking.ts
|
|
9
|
-
function enableReactTracking({ auto, warnUnobserved,
|
|
9
|
+
function enableReactTracking({ auto, warnUnobserved, warnMissingUse }) {
|
|
10
10
|
const { get } = state.internal;
|
|
11
|
-
if (auto || process.env.NODE_ENV === "development" && (warnUnobserved ||
|
|
11
|
+
if (auto || process.env.NODE_ENV === "development" && (warnUnobserved || warnMissingUse)) {
|
|
12
12
|
const ReactRenderContext = react.createContext(0);
|
|
13
13
|
const isInRender = () => {
|
|
14
14
|
try {
|
|
@@ -21,8 +21,11 @@ function enableReactTracking({ auto, warnUnobserved, warnGet }) {
|
|
|
21
21
|
}
|
|
22
22
|
return false;
|
|
23
23
|
};
|
|
24
|
+
const isObserved = () => {
|
|
25
|
+
return !!state.tracking.current;
|
|
26
|
+
};
|
|
24
27
|
const needsSelector = () => {
|
|
25
|
-
if (!
|
|
28
|
+
if (!isObserved()) {
|
|
26
29
|
return isInRender();
|
|
27
30
|
}
|
|
28
31
|
return false;
|
|
@@ -30,11 +33,17 @@ function enableReactTracking({ auto, warnUnobserved, warnGet }) {
|
|
|
30
33
|
configureLegendState.configureLegendState({
|
|
31
34
|
observableFunctions: {
|
|
32
35
|
get: (node, options) => {
|
|
33
|
-
if (process.env.NODE_ENV === "development" &&
|
|
36
|
+
if (process.env.NODE_ENV === "development" && warnMissingUse) {
|
|
34
37
|
if (isInRender()) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
if (isObserved()) {
|
|
39
|
+
console.warn(
|
|
40
|
+
"[legend-state] Detected a `get()` call in an observer component. It is recommended to use the `use$` hook instead to be compatible with React Compiler: https://legendapp.com/open-source/state/v3/react/react-api/#use$"
|
|
41
|
+
);
|
|
42
|
+
} else {
|
|
43
|
+
console.warn(
|
|
44
|
+
"[legend-state] Detected a `get()` call in a component. You likely want to use the `use$` hook to be reactive to it changing, or change `get()` to `peek()` to get the value without tracking: https://legendapp.com/open-source/state/v3/react/react-api/#use$"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
38
47
|
}
|
|
39
48
|
} else if (needsSelector()) {
|
|
40
49
|
if (auto) {
|
|
@@ -4,9 +4,9 @@ import { useSelector } from '@legendapp/state/react';
|
|
|
4
4
|
import { createContext, __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, useContext } from 'react';
|
|
5
5
|
|
|
6
6
|
// src/config/enableReactTracking.ts
|
|
7
|
-
function enableReactTracking({ auto, warnUnobserved,
|
|
7
|
+
function enableReactTracking({ auto, warnUnobserved, warnMissingUse }) {
|
|
8
8
|
const { get } = internal;
|
|
9
|
-
if (auto || process.env.NODE_ENV === "development" && (warnUnobserved ||
|
|
9
|
+
if (auto || process.env.NODE_ENV === "development" && (warnUnobserved || warnMissingUse)) {
|
|
10
10
|
const ReactRenderContext = createContext(0);
|
|
11
11
|
const isInRender = () => {
|
|
12
12
|
try {
|
|
@@ -19,8 +19,11 @@ function enableReactTracking({ auto, warnUnobserved, warnGet }) {
|
|
|
19
19
|
}
|
|
20
20
|
return false;
|
|
21
21
|
};
|
|
22
|
+
const isObserved = () => {
|
|
23
|
+
return !!tracking.current;
|
|
24
|
+
};
|
|
22
25
|
const needsSelector = () => {
|
|
23
|
-
if (!
|
|
26
|
+
if (!isObserved()) {
|
|
24
27
|
return isInRender();
|
|
25
28
|
}
|
|
26
29
|
return false;
|
|
@@ -28,11 +31,17 @@ function enableReactTracking({ auto, warnUnobserved, warnGet }) {
|
|
|
28
31
|
configureLegendState({
|
|
29
32
|
observableFunctions: {
|
|
30
33
|
get: (node, options) => {
|
|
31
|
-
if (process.env.NODE_ENV === "development" &&
|
|
34
|
+
if (process.env.NODE_ENV === "development" && warnMissingUse) {
|
|
32
35
|
if (isInRender()) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
if (isObserved()) {
|
|
37
|
+
console.warn(
|
|
38
|
+
"[legend-state] Detected a `get()` call in an observer component. It is recommended to use the `use$` hook instead to be compatible with React Compiler: https://legendapp.com/open-source/state/v3/react/react-api/#use$"
|
|
39
|
+
);
|
|
40
|
+
} else {
|
|
41
|
+
console.warn(
|
|
42
|
+
"[legend-state] Detected a `get()` call in a component. You likely want to use the `use$` hook to be reactive to it changing, or change `get()` to `peek()` to get the value without tracking: https://legendapp.com/open-source/state/v3/react/react-api/#use$"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
36
45
|
}
|
|
37
46
|
} else if (needsSelector()) {
|
|
38
47
|
if (auto) {
|
package/index.js
CHANGED
|
@@ -1565,7 +1565,9 @@ var proxyHandler = {
|
|
|
1565
1565
|
if (isObservable(thisArg)) {
|
|
1566
1566
|
thisArg = thisArg.peek();
|
|
1567
1567
|
}
|
|
1568
|
-
|
|
1568
|
+
const fnRaw = getNodeValue(target);
|
|
1569
|
+
const fn = isFunction(fnRaw) ? fnRaw : target.lazyFn || target;
|
|
1570
|
+
return Reflect.apply(fn, thisArg, argArray);
|
|
1569
1571
|
}
|
|
1570
1572
|
};
|
|
1571
1573
|
function set(node, newValue) {
|
|
@@ -2313,7 +2315,14 @@ function syncState(obs) {
|
|
|
2313
2315
|
syncCount: 0,
|
|
2314
2316
|
resetPersistence: void 0,
|
|
2315
2317
|
reset: () => Promise.resolve(),
|
|
2316
|
-
sync: () =>
|
|
2318
|
+
sync: () => {
|
|
2319
|
+
var _a;
|
|
2320
|
+
obs.peek();
|
|
2321
|
+
if ((_a = node.state) == null ? void 0 : _a.isGetting.peek()) {
|
|
2322
|
+
return when(node.state.isLoaded);
|
|
2323
|
+
}
|
|
2324
|
+
return Promise.resolve();
|
|
2325
|
+
},
|
|
2317
2326
|
getPendingChanges: () => ({}),
|
|
2318
2327
|
// TODOV3 remove
|
|
2319
2328
|
clearPersist: void 0
|
package/index.mjs
CHANGED
|
@@ -1563,7 +1563,9 @@ var proxyHandler = {
|
|
|
1563
1563
|
if (isObservable(thisArg)) {
|
|
1564
1564
|
thisArg = thisArg.peek();
|
|
1565
1565
|
}
|
|
1566
|
-
|
|
1566
|
+
const fnRaw = getNodeValue(target);
|
|
1567
|
+
const fn = isFunction(fnRaw) ? fnRaw : target.lazyFn || target;
|
|
1568
|
+
return Reflect.apply(fn, thisArg, argArray);
|
|
1567
1569
|
}
|
|
1568
1570
|
};
|
|
1569
1571
|
function set(node, newValue) {
|
|
@@ -2311,7 +2313,14 @@ function syncState(obs) {
|
|
|
2311
2313
|
syncCount: 0,
|
|
2312
2314
|
resetPersistence: void 0,
|
|
2313
2315
|
reset: () => Promise.resolve(),
|
|
2314
|
-
sync: () =>
|
|
2316
|
+
sync: () => {
|
|
2317
|
+
var _a;
|
|
2318
|
+
obs.peek();
|
|
2319
|
+
if ((_a = node.state) == null ? void 0 : _a.isGetting.peek()) {
|
|
2320
|
+
return when(node.state.isLoaded);
|
|
2321
|
+
}
|
|
2322
|
+
return Promise.resolve();
|
|
2323
|
+
},
|
|
2315
2324
|
getPendingChanges: () => ({}),
|
|
2316
2325
|
// TODOV3 remove
|
|
2317
2326
|
clearPersist: void 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legendapp/state",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.20",
|
|
4
4
|
"description": "legend-state",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"private": false,
|
|
@@ -69,6 +69,16 @@
|
|
|
69
69
|
"require": "./react.js",
|
|
70
70
|
"types": "./react.d.ts"
|
|
71
71
|
},
|
|
72
|
+
"./react-native": {
|
|
73
|
+
"import": "./react-native.mjs",
|
|
74
|
+
"require": "./react-native.js",
|
|
75
|
+
"types": "./react-native.d.ts"
|
|
76
|
+
},
|
|
77
|
+
"./react-web": {
|
|
78
|
+
"import": "./react-web.mjs",
|
|
79
|
+
"require": "./react-web.js",
|
|
80
|
+
"types": "./react-web.d.ts"
|
|
81
|
+
},
|
|
72
82
|
"./trace": {
|
|
73
83
|
"import": "./trace.mjs",
|
|
74
84
|
"require": "./trace.js",
|
|
@@ -79,6 +89,11 @@
|
|
|
79
89
|
"require": "./react-reactive/enableReactive.js",
|
|
80
90
|
"types": "./react-reactive/enableReactive.d.ts"
|
|
81
91
|
},
|
|
92
|
+
"./react-reactive/Components": {
|
|
93
|
+
"import": "./react-reactive/Components.mjs",
|
|
94
|
+
"require": "./react-reactive/Components.js",
|
|
95
|
+
"types": "./react-reactive/Components.d.ts"
|
|
96
|
+
},
|
|
82
97
|
"./react-reactive/enableReactComponents": {
|
|
83
98
|
"import": "./react-reactive/enableReactComponents.mjs",
|
|
84
99
|
"require": "./react-reactive/enableReactComponents.js",
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { $ActivityIndicator, $Button, $FlatList, $Image, $Pressable, $ScrollView, $SectionList, $Switch, $Text, $TextInput, $TouchableWithoutFeedback, $View } from './react-reactive/Components.mjs';
|
|
2
|
+
import 'react';
|
|
3
|
+
import '@legendapp/state/react';
|
|
4
|
+
import 'react-native';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { $ActivityIndicator, $Button, $FlatList, $Image, $Pressable, $ScrollView, $SectionList, $Switch, $Text, $TextInput, $TouchableWithoutFeedback, $View } from './react-reactive/Components.js';
|
|
2
|
+
import 'react';
|
|
3
|
+
import '@legendapp/state/react';
|
|
4
|
+
import 'react-native';
|
package/react-native.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('@legendapp/state/react');
|
|
4
|
+
var react$1 = require('react');
|
|
5
|
+
var reactNative = require('react-native');
|
|
6
|
+
|
|
7
|
+
// src/react-reactive/Components.ts
|
|
8
|
+
var $ActivityIndicator = react.reactive(reactNative.ActivityIndicator);
|
|
9
|
+
var $Button = react.reactive(reactNative.Button);
|
|
10
|
+
var $FlatList = react.reactive(reactNative.FlatList, void 0, {
|
|
11
|
+
data: {
|
|
12
|
+
selector: (propsOut, p) => {
|
|
13
|
+
const state = react$1.useRef(0);
|
|
14
|
+
const [renderNum, value] = react.use$(() => [state.current++, p.get(true)]);
|
|
15
|
+
propsOut.extraData = renderNum;
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
var $Image = react.reactive(reactNative.Image);
|
|
21
|
+
var $Pressable = react.reactive(reactNative.Pressable);
|
|
22
|
+
var $ScrollView = react.reactive(reactNative.ScrollView);
|
|
23
|
+
var $SectionList = react.reactive(reactNative.SectionList);
|
|
24
|
+
var $Switch = react.reactive(reactNative.Switch, void 0, {
|
|
25
|
+
value: {
|
|
26
|
+
handler: "onValueChange",
|
|
27
|
+
getValue: (e) => e,
|
|
28
|
+
defaultValue: false
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
var $Text = react.reactive(reactNative.Text);
|
|
32
|
+
var $TextInput = react.reactive(reactNative.TextInput, void 0, {
|
|
33
|
+
value: {
|
|
34
|
+
handler: "onChange",
|
|
35
|
+
getValue: (e) => e.nativeEvent.text,
|
|
36
|
+
defaultValue: ""
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
var $TouchableWithoutFeedback = react.reactive(reactNative.TouchableWithoutFeedback);
|
|
40
|
+
var $View = react.reactive(reactNative.View);
|
|
41
|
+
|
|
42
|
+
exports.$ActivityIndicator = $ActivityIndicator;
|
|
43
|
+
exports.$Button = $Button;
|
|
44
|
+
exports.$FlatList = $FlatList;
|
|
45
|
+
exports.$Image = $Image;
|
|
46
|
+
exports.$Pressable = $Pressable;
|
|
47
|
+
exports.$ScrollView = $ScrollView;
|
|
48
|
+
exports.$SectionList = $SectionList;
|
|
49
|
+
exports.$Switch = $Switch;
|
|
50
|
+
exports.$Text = $Text;
|
|
51
|
+
exports.$TextInput = $TextInput;
|
|
52
|
+
exports.$TouchableWithoutFeedback = $TouchableWithoutFeedback;
|
|
53
|
+
exports.$View = $View;
|
package/react-native.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { reactive, use$ } from '@legendapp/state/react';
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import { ActivityIndicator, Button, FlatList, Image, Pressable, ScrollView, SectionList, Switch, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
|
|
4
|
+
|
|
5
|
+
// src/react-reactive/Components.ts
|
|
6
|
+
var $ActivityIndicator = reactive(ActivityIndicator);
|
|
7
|
+
var $Button = reactive(Button);
|
|
8
|
+
var $FlatList = reactive(FlatList, void 0, {
|
|
9
|
+
data: {
|
|
10
|
+
selector: (propsOut, p) => {
|
|
11
|
+
const state = useRef(0);
|
|
12
|
+
const [renderNum, value] = use$(() => [state.current++, p.get(true)]);
|
|
13
|
+
propsOut.extraData = renderNum;
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var $Image = reactive(Image);
|
|
19
|
+
var $Pressable = reactive(Pressable);
|
|
20
|
+
var $ScrollView = reactive(ScrollView);
|
|
21
|
+
var $SectionList = reactive(SectionList);
|
|
22
|
+
var $Switch = reactive(Switch, void 0, {
|
|
23
|
+
value: {
|
|
24
|
+
handler: "onValueChange",
|
|
25
|
+
getValue: (e) => e,
|
|
26
|
+
defaultValue: false
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
var $Text = reactive(Text);
|
|
30
|
+
var $TextInput = reactive(TextInput, void 0, {
|
|
31
|
+
value: {
|
|
32
|
+
handler: "onChange",
|
|
33
|
+
getValue: (e) => e.nativeEvent.text,
|
|
34
|
+
defaultValue: ""
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
var $TouchableWithoutFeedback = reactive(TouchableWithoutFeedback);
|
|
38
|
+
var $View = reactive(View);
|
|
39
|
+
|
|
40
|
+
export { $ActivityIndicator, $Button, $FlatList, $Image, $Pressable, $ScrollView, $SectionList, $Switch, $Text, $TextInput, $TouchableWithoutFeedback, $View };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as _legendapp_state_react from '@legendapp/state/react';
|
|
3
|
+
import * as react_native from 'react-native';
|
|
4
|
+
import { View } from 'react-native';
|
|
5
|
+
|
|
6
|
+
declare const $ActivityIndicator: React.ComponentClass<_legendapp_state_react.ShapeWith$<react_native.ActivityIndicatorProps>, any>;
|
|
7
|
+
declare const $Button: React.ComponentClass<_legendapp_state_react.ShapeWith$<react_native.ButtonProps>, any>;
|
|
8
|
+
declare const $FlatList: React.FC<_legendapp_state_react.ShapeWith$<react_native.FlatListProps<unknown>>>;
|
|
9
|
+
declare const $Image: React.ComponentClass<_legendapp_state_react.ShapeWith$<react_native.ImageProps>, any>;
|
|
10
|
+
declare const $Pressable: React.ForwardRefExoticComponent<_legendapp_state_react.ShapeWith$<react_native.PressableProps & React.RefAttributes<View>>>;
|
|
11
|
+
declare const $ScrollView: React.ComponentClass<_legendapp_state_react.ShapeWith$<react_native.ScrollViewProps>, any>;
|
|
12
|
+
declare const $SectionList: React.ComponentClass<_legendapp_state_react.ShapeWith$<react_native.SectionListProps<unknown, unknown>>, any>;
|
|
13
|
+
declare const $Switch: React.FC<_legendapp_state_react.ShapeWith$<react_native.SwitchProps>>;
|
|
14
|
+
declare const $Text: React.ComponentClass<_legendapp_state_react.ShapeWith$<react_native.TextProps>, any>;
|
|
15
|
+
declare const $TextInput: React.FC<_legendapp_state_react.ShapeWith$<react_native.TextInputProps>>;
|
|
16
|
+
declare const $TouchableWithoutFeedback: React.ComponentClass<_legendapp_state_react.ShapeWith$<react_native.TouchableWithoutFeedbackProps>, any>;
|
|
17
|
+
declare const $View: React.ComponentClass<_legendapp_state_react.ShapeWith$<react_native.ViewProps>, any>;
|
|
18
|
+
|
|
19
|
+
export { $ActivityIndicator, $Button, $FlatList, $Image, $Pressable, $ScrollView, $SectionList, $Switch, $Text, $TextInput, $TouchableWithoutFeedback, $View };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as _legendapp_state_react from '@legendapp/state/react';
|
|
3
|
+
import * as react_native from 'react-native';
|
|
4
|
+
import { View } from 'react-native';
|
|
5
|
+
|
|
6
|
+
declare const $ActivityIndicator: React.ComponentClass<_legendapp_state_react.ShapeWith$<react_native.ActivityIndicatorProps>, any>;
|
|
7
|
+
declare const $Button: React.ComponentClass<_legendapp_state_react.ShapeWith$<react_native.ButtonProps>, any>;
|
|
8
|
+
declare const $FlatList: React.FC<_legendapp_state_react.ShapeWith$<react_native.FlatListProps<unknown>>>;
|
|
9
|
+
declare const $Image: React.ComponentClass<_legendapp_state_react.ShapeWith$<react_native.ImageProps>, any>;
|
|
10
|
+
declare const $Pressable: React.ForwardRefExoticComponent<_legendapp_state_react.ShapeWith$<react_native.PressableProps & React.RefAttributes<View>>>;
|
|
11
|
+
declare const $ScrollView: React.ComponentClass<_legendapp_state_react.ShapeWith$<react_native.ScrollViewProps>, any>;
|
|
12
|
+
declare const $SectionList: React.ComponentClass<_legendapp_state_react.ShapeWith$<react_native.SectionListProps<unknown, unknown>>, any>;
|
|
13
|
+
declare const $Switch: React.FC<_legendapp_state_react.ShapeWith$<react_native.SwitchProps>>;
|
|
14
|
+
declare const $Text: React.ComponentClass<_legendapp_state_react.ShapeWith$<react_native.TextProps>, any>;
|
|
15
|
+
declare const $TextInput: React.FC<_legendapp_state_react.ShapeWith$<react_native.TextInputProps>>;
|
|
16
|
+
declare const $TouchableWithoutFeedback: React.ComponentClass<_legendapp_state_react.ShapeWith$<react_native.TouchableWithoutFeedbackProps>, any>;
|
|
17
|
+
declare const $View: React.ComponentClass<_legendapp_state_react.ShapeWith$<react_native.ViewProps>, any>;
|
|
18
|
+
|
|
19
|
+
export { $ActivityIndicator, $Button, $FlatList, $Image, $Pressable, $ScrollView, $SectionList, $Switch, $Text, $TextInput, $TouchableWithoutFeedback, $View };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('@legendapp/state/react');
|
|
4
|
+
var react$1 = require('react');
|
|
5
|
+
var reactNative = require('react-native');
|
|
6
|
+
|
|
7
|
+
// src/react-reactive/Components.ts
|
|
8
|
+
var $ActivityIndicator = react.reactive(reactNative.ActivityIndicator);
|
|
9
|
+
var $Button = react.reactive(reactNative.Button);
|
|
10
|
+
var $FlatList = react.reactive(reactNative.FlatList, void 0, {
|
|
11
|
+
data: {
|
|
12
|
+
selector: (propsOut, p) => {
|
|
13
|
+
const state = react$1.useRef(0);
|
|
14
|
+
const [renderNum, value] = react.use$(() => [state.current++, p.get(true)]);
|
|
15
|
+
propsOut.extraData = renderNum;
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
var $Image = react.reactive(reactNative.Image);
|
|
21
|
+
var $Pressable = react.reactive(reactNative.Pressable);
|
|
22
|
+
var $ScrollView = react.reactive(reactNative.ScrollView);
|
|
23
|
+
var $SectionList = react.reactive(reactNative.SectionList);
|
|
24
|
+
var $Switch = react.reactive(reactNative.Switch, void 0, {
|
|
25
|
+
value: {
|
|
26
|
+
handler: "onValueChange",
|
|
27
|
+
getValue: (e) => e,
|
|
28
|
+
defaultValue: false
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
var $Text = react.reactive(reactNative.Text);
|
|
32
|
+
var $TextInput = react.reactive(reactNative.TextInput, void 0, {
|
|
33
|
+
value: {
|
|
34
|
+
handler: "onChange",
|
|
35
|
+
getValue: (e) => e.nativeEvent.text,
|
|
36
|
+
defaultValue: ""
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
var $TouchableWithoutFeedback = react.reactive(reactNative.TouchableWithoutFeedback);
|
|
40
|
+
var $View = react.reactive(reactNative.View);
|
|
41
|
+
|
|
42
|
+
exports.$ActivityIndicator = $ActivityIndicator;
|
|
43
|
+
exports.$Button = $Button;
|
|
44
|
+
exports.$FlatList = $FlatList;
|
|
45
|
+
exports.$Image = $Image;
|
|
46
|
+
exports.$Pressable = $Pressable;
|
|
47
|
+
exports.$ScrollView = $ScrollView;
|
|
48
|
+
exports.$SectionList = $SectionList;
|
|
49
|
+
exports.$Switch = $Switch;
|
|
50
|
+
exports.$Text = $Text;
|
|
51
|
+
exports.$TextInput = $TextInput;
|
|
52
|
+
exports.$TouchableWithoutFeedback = $TouchableWithoutFeedback;
|
|
53
|
+
exports.$View = $View;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { reactive, use$ } from '@legendapp/state/react';
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import { ActivityIndicator, Button, FlatList, Image, Pressable, ScrollView, SectionList, Switch, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
|
|
4
|
+
|
|
5
|
+
// src/react-reactive/Components.ts
|
|
6
|
+
var $ActivityIndicator = reactive(ActivityIndicator);
|
|
7
|
+
var $Button = reactive(Button);
|
|
8
|
+
var $FlatList = reactive(FlatList, void 0, {
|
|
9
|
+
data: {
|
|
10
|
+
selector: (propsOut, p) => {
|
|
11
|
+
const state = useRef(0);
|
|
12
|
+
const [renderNum, value] = use$(() => [state.current++, p.get(true)]);
|
|
13
|
+
propsOut.extraData = renderNum;
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var $Image = reactive(Image);
|
|
19
|
+
var $Pressable = reactive(Pressable);
|
|
20
|
+
var $ScrollView = reactive(ScrollView);
|
|
21
|
+
var $SectionList = reactive(SectionList);
|
|
22
|
+
var $Switch = reactive(Switch, void 0, {
|
|
23
|
+
value: {
|
|
24
|
+
handler: "onValueChange",
|
|
25
|
+
getValue: (e) => e,
|
|
26
|
+
defaultValue: false
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
var $Text = reactive(Text);
|
|
30
|
+
var $TextInput = reactive(TextInput, void 0, {
|
|
31
|
+
value: {
|
|
32
|
+
handler: "onChange",
|
|
33
|
+
getValue: (e) => e.nativeEvent.text,
|
|
34
|
+
defaultValue: ""
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
var $TouchableWithoutFeedback = reactive(TouchableWithoutFeedback);
|
|
38
|
+
var $View = reactive(View);
|
|
39
|
+
|
|
40
|
+
export { $ActivityIndicator, $Button, $FlatList, $Image, $Pressable, $ScrollView, $SectionList, $Switch, $Text, $TextInput, $TouchableWithoutFeedback, $View };
|
package/react-web.d.mts
ADDED
package/react-web.d.ts
ADDED
package/react-web.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var state = require('@legendapp/state');
|
|
4
|
+
var react$1 = require('@legendapp/state/react');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
// src/react-web/$React.tsx
|
|
8
|
+
var bindInfoOneWay = {
|
|
9
|
+
value: { handler: "onChange", getValue: (e) => e.target.value, defaultValue: "" }
|
|
10
|
+
};
|
|
11
|
+
var bindInfoInput = Object.assign(
|
|
12
|
+
{ checked: { handler: "onChange", getValue: (e) => e.target.checked } },
|
|
13
|
+
bindInfoOneWay
|
|
14
|
+
);
|
|
15
|
+
var binders = /* @__PURE__ */ new Map([
|
|
16
|
+
["input", bindInfoInput],
|
|
17
|
+
["textarea", bindInfoOneWay],
|
|
18
|
+
["select", bindInfoOneWay]
|
|
19
|
+
]);
|
|
20
|
+
var $React = new Proxy(
|
|
21
|
+
{},
|
|
22
|
+
{
|
|
23
|
+
get(target, p) {
|
|
24
|
+
if (!target[p]) {
|
|
25
|
+
const render = react.forwardRef((props, ref) => {
|
|
26
|
+
const propsOut = { ...props };
|
|
27
|
+
if (ref && (state.isFunction(ref) || !state.isEmpty(ref))) {
|
|
28
|
+
propsOut.ref = ref;
|
|
29
|
+
}
|
|
30
|
+
return react.createElement(p, propsOut);
|
|
31
|
+
});
|
|
32
|
+
target[p] = react$1.reactive(render, [], binders.get(p));
|
|
33
|
+
}
|
|
34
|
+
return target[p];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
exports.$React = $React;
|
package/react-web.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { isFunction, isEmpty } from '@legendapp/state';
|
|
2
|
+
import { reactive } from '@legendapp/state/react';
|
|
3
|
+
import { forwardRef, createElement } from 'react';
|
|
4
|
+
|
|
5
|
+
// src/react-web/$React.tsx
|
|
6
|
+
var bindInfoOneWay = {
|
|
7
|
+
value: { handler: "onChange", getValue: (e) => e.target.value, defaultValue: "" }
|
|
8
|
+
};
|
|
9
|
+
var bindInfoInput = Object.assign(
|
|
10
|
+
{ checked: { handler: "onChange", getValue: (e) => e.target.checked } },
|
|
11
|
+
bindInfoOneWay
|
|
12
|
+
);
|
|
13
|
+
var binders = /* @__PURE__ */ new Map([
|
|
14
|
+
["input", bindInfoInput],
|
|
15
|
+
["textarea", bindInfoOneWay],
|
|
16
|
+
["select", bindInfoOneWay]
|
|
17
|
+
]);
|
|
18
|
+
var $React = new Proxy(
|
|
19
|
+
{},
|
|
20
|
+
{
|
|
21
|
+
get(target, p) {
|
|
22
|
+
if (!target[p]) {
|
|
23
|
+
const render = forwardRef((props, ref) => {
|
|
24
|
+
const propsOut = { ...props };
|
|
25
|
+
if (ref && (isFunction(ref) || !isEmpty(ref))) {
|
|
26
|
+
propsOut.ref = ref;
|
|
27
|
+
}
|
|
28
|
+
return createElement(p, propsOut);
|
|
29
|
+
});
|
|
30
|
+
target[p] = reactive(render, [], binders.get(p));
|
|
31
|
+
}
|
|
32
|
+
return target[p];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export { $React };
|
package/react.d.mts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { ReactNode, ReactElement,
|
|
2
|
+
import { ReactNode, ReactElement, FC, NamedExoticComponent, LegacyRef, DependencyList, ReducerWithoutAction, ReducerStateWithoutAction, DispatchWithoutAction, Reducer, ReducerState, Dispatch, ReducerAction, ComponentClass } from 'react';
|
|
3
3
|
import { ObservableParam, Observable, ObservableBoolean, Selector, GetOptions, RecursiveValueOrFunction, ObserveOptions, ObserveEvent, ObserveEventCallback } from '@legendapp/state';
|
|
4
|
-
import { IReactive as IReactive$1 } from '@legendapp/state/react';
|
|
5
4
|
|
|
6
5
|
declare function Computed({ children }: {
|
|
7
6
|
children: ObservableParam | (() => ReactNode);
|
|
8
7
|
}): ReactElement;
|
|
9
8
|
|
|
10
|
-
declare const Memo$1: NamedExoticComponent<{
|
|
11
|
-
children: any;
|
|
12
|
-
scoped?: boolean;
|
|
13
|
-
}>;
|
|
14
|
-
type ReactiveProxy = typeof Memo$1 & IReactive$1;
|
|
15
|
-
declare const $: ReactiveProxy;
|
|
16
|
-
|
|
17
9
|
type ForItemProps<T, TProps = {}> = {
|
|
18
10
|
item$: Observable<T>;
|
|
19
11
|
id?: string;
|
|
@@ -115,10 +107,12 @@ type ReactifyProps<T, K extends keyof T> = Omit<T, K> & {
|
|
|
115
107
|
};
|
|
116
108
|
declare const hasSymbol: false | ((key: string) => symbol);
|
|
117
109
|
declare function observer<P extends FC<any>>(component: P): P;
|
|
110
|
+
declare function reactive<T extends object>(component: React.ComponentClass<T>, keys: undefined | null, bindKeys?: BindKeys<T>): React.FC<ShapeWith$<T>>;
|
|
118
111
|
declare function reactive<T extends object>(component: React.FC<T>, keys: undefined | null, bindKeys?: BindKeys<T>): React.FC<ShapeWith$<T>>;
|
|
119
112
|
declare function reactive<T extends object>(component: React.ForwardRefExoticComponent<T>, keys: undefined | null, bindKeys?: BindKeys<T>): React.ForwardRefExoticComponent<ShapeWith$<T>>;
|
|
120
113
|
declare function reactive<T extends object, K extends keyof T>(component: React.FC<T>, keys: K[] | (keyof T)[], bindKeys?: BindKeys<T, K>): React.FC<ReactifyProps<T, K>>;
|
|
121
114
|
declare function reactive<T extends object, K extends keyof T>(component: React.ForwardRefExoticComponent<T>, keys: K[] | (keyof T)[], bindKeys?: BindKeys<T, K>): React.ForwardRefExoticComponent<ReactifyProps<T, K>>;
|
|
115
|
+
declare function reactive<T extends object>(component: React.ComponentClass<T>): React.ComponentClass<ShapeWith$<T>>;
|
|
122
116
|
declare function reactive<T extends object>(component: React.FC<T>): React.FC<ShapeWith$<T>>;
|
|
123
117
|
declare function reactive<T extends object>(component: React.ForwardRefExoticComponent<T>): React.ForwardRefExoticComponent<ShapeWith$<T>>;
|
|
124
118
|
declare function reactiveObserver<T extends object>(component: React.FC<T>, keys: undefined | null, bindKeys?: BindKeys<T>): React.FC<ShapeWith$<T>>;
|
|
@@ -183,4 +177,4 @@ declare function configureReactive({ components, binders, }: {
|
|
|
183
177
|
binders?: Record<string, BindKeys>;
|
|
184
178
|
}): void;
|
|
185
179
|
|
|
186
|
-
export {
|
|
180
|
+
export { type BindKey, type BindKeys, Computed, type ExtractFCPropsType, type FCReactive, type FCReactiveObject, For, type IReactive, Memo, type ObjectShapeWith$, type ReactifyProps, Reactive, type ShapeWith$, type ShapeWithNew$, type ShapeWithPick$, Show, Switch, type UseObserveOptions, type UseSelectorOptions, configureReactive, hasSymbol, observer, reactive, reactiveComponents, reactiveObserver, useSelector as use$, useComputed, useEffectOnce, useIsMounted, useMount, useMountOnce, useObservable, useObservableReducer, useObserve, useObserveEffect, usePauseProvider, useSelector, useUnmount, useUnmountOnce, useWhen, useWhenReady };
|
package/react.d.ts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { ReactNode, ReactElement,
|
|
2
|
+
import { ReactNode, ReactElement, FC, NamedExoticComponent, LegacyRef, DependencyList, ReducerWithoutAction, ReducerStateWithoutAction, DispatchWithoutAction, Reducer, ReducerState, Dispatch, ReducerAction, ComponentClass } from 'react';
|
|
3
3
|
import { ObservableParam, Observable, ObservableBoolean, Selector, GetOptions, RecursiveValueOrFunction, ObserveOptions, ObserveEvent, ObserveEventCallback } from '@legendapp/state';
|
|
4
|
-
import { IReactive as IReactive$1 } from '@legendapp/state/react';
|
|
5
4
|
|
|
6
5
|
declare function Computed({ children }: {
|
|
7
6
|
children: ObservableParam | (() => ReactNode);
|
|
8
7
|
}): ReactElement;
|
|
9
8
|
|
|
10
|
-
declare const Memo$1: NamedExoticComponent<{
|
|
11
|
-
children: any;
|
|
12
|
-
scoped?: boolean;
|
|
13
|
-
}>;
|
|
14
|
-
type ReactiveProxy = typeof Memo$1 & IReactive$1;
|
|
15
|
-
declare const $: ReactiveProxy;
|
|
16
|
-
|
|
17
9
|
type ForItemProps<T, TProps = {}> = {
|
|
18
10
|
item$: Observable<T>;
|
|
19
11
|
id?: string;
|
|
@@ -115,10 +107,12 @@ type ReactifyProps<T, K extends keyof T> = Omit<T, K> & {
|
|
|
115
107
|
};
|
|
116
108
|
declare const hasSymbol: false | ((key: string) => symbol);
|
|
117
109
|
declare function observer<P extends FC<any>>(component: P): P;
|
|
110
|
+
declare function reactive<T extends object>(component: React.ComponentClass<T>, keys: undefined | null, bindKeys?: BindKeys<T>): React.FC<ShapeWith$<T>>;
|
|
118
111
|
declare function reactive<T extends object>(component: React.FC<T>, keys: undefined | null, bindKeys?: BindKeys<T>): React.FC<ShapeWith$<T>>;
|
|
119
112
|
declare function reactive<T extends object>(component: React.ForwardRefExoticComponent<T>, keys: undefined | null, bindKeys?: BindKeys<T>): React.ForwardRefExoticComponent<ShapeWith$<T>>;
|
|
120
113
|
declare function reactive<T extends object, K extends keyof T>(component: React.FC<T>, keys: K[] | (keyof T)[], bindKeys?: BindKeys<T, K>): React.FC<ReactifyProps<T, K>>;
|
|
121
114
|
declare function reactive<T extends object, K extends keyof T>(component: React.ForwardRefExoticComponent<T>, keys: K[] | (keyof T)[], bindKeys?: BindKeys<T, K>): React.ForwardRefExoticComponent<ReactifyProps<T, K>>;
|
|
115
|
+
declare function reactive<T extends object>(component: React.ComponentClass<T>): React.ComponentClass<ShapeWith$<T>>;
|
|
122
116
|
declare function reactive<T extends object>(component: React.FC<T>): React.FC<ShapeWith$<T>>;
|
|
123
117
|
declare function reactive<T extends object>(component: React.ForwardRefExoticComponent<T>): React.ForwardRefExoticComponent<ShapeWith$<T>>;
|
|
124
118
|
declare function reactiveObserver<T extends object>(component: React.FC<T>, keys: undefined | null, bindKeys?: BindKeys<T>): React.FC<ShapeWith$<T>>;
|
|
@@ -183,4 +177,4 @@ declare function configureReactive({ components, binders, }: {
|
|
|
183
177
|
binders?: Record<string, BindKeys>;
|
|
184
178
|
}): void;
|
|
185
179
|
|
|
186
|
-
export {
|
|
180
|
+
export { type BindKey, type BindKeys, Computed, type ExtractFCPropsType, type FCReactive, type FCReactiveObject, For, type IReactive, Memo, type ObjectShapeWith$, type ReactifyProps, Reactive, type ShapeWith$, type ShapeWithNew$, type ShapeWithPick$, Show, Switch, type UseObserveOptions, type UseSelectorOptions, configureReactive, hasSymbol, observer, reactive, reactiveComponents, reactiveObserver, useSelector as use$, useComputed, useEffectOnce, useIsMounted, useMount, useMountOnce, useObservable, useObservableReducer, useObserve, useObserveEffect, usePauseProvider, useSelector, useUnmount, useUnmountOnce, useWhen, useWhenReady };
|
package/react.js
CHANGED
|
@@ -101,12 +101,24 @@ function createSelectorFunctions(options, isPaused$) {
|
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
|
+
function doSuspense(selector) {
|
|
105
|
+
const vProm = state.when(selector);
|
|
106
|
+
if (React__default.default.use) {
|
|
107
|
+
React__default.default.use(vProm);
|
|
108
|
+
} else {
|
|
109
|
+
throw vProm;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
104
112
|
function useSelector(selector, options) {
|
|
105
113
|
var _a;
|
|
114
|
+
let value;
|
|
106
115
|
if (reactGlobals.inObserver && state.isObservable(selector) && !(options == null ? void 0 : options.suspense)) {
|
|
107
|
-
|
|
116
|
+
value = state.computeSelector(selector, options);
|
|
117
|
+
if ((options == null ? void 0 : options.suspense) && value === void 0) {
|
|
118
|
+
doSuspense(selector);
|
|
119
|
+
}
|
|
120
|
+
return value;
|
|
108
121
|
}
|
|
109
|
-
let value;
|
|
110
122
|
try {
|
|
111
123
|
const isPaused$ = React.useContext(getPauseContext());
|
|
112
124
|
const selectorFn = React.useMemo(() => createSelectorFunctions(options, isPaused$), []);
|
|
@@ -121,16 +133,8 @@ function useSelector(selector, options) {
|
|
|
121
133
|
}
|
|
122
134
|
throw err;
|
|
123
135
|
}
|
|
124
|
-
if (options == null ? void 0 : options.suspense) {
|
|
125
|
-
|
|
126
|
-
if (state.isPromise(value) || !value && state.isObservable(selector)) {
|
|
127
|
-
const vProm = isProm ? value : state.when(selector);
|
|
128
|
-
if (React__default.default.use) {
|
|
129
|
-
React__default.default.use(vProm);
|
|
130
|
-
} else {
|
|
131
|
-
throw vProm;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
136
|
+
if ((options == null ? void 0 : options.suspense) && value === void 0) {
|
|
137
|
+
doSuspense(selector);
|
|
134
138
|
}
|
|
135
139
|
return value;
|
|
136
140
|
}
|
|
@@ -139,25 +143,6 @@ function useSelector(selector, options) {
|
|
|
139
143
|
function Computed({ children }) {
|
|
140
144
|
return useSelector(() => state.computeSelector(state.computeSelector(children)), { skipCheck: true });
|
|
141
145
|
}
|
|
142
|
-
|
|
143
|
-
// src/react/configureReactive.ts
|
|
144
|
-
var ReactiveFns = /* @__PURE__ */ new Map();
|
|
145
|
-
var ReactiveFnBinders = /* @__PURE__ */ new Map();
|
|
146
|
-
function configureReactive({
|
|
147
|
-
components,
|
|
148
|
-
binders
|
|
149
|
-
}) {
|
|
150
|
-
if (components) {
|
|
151
|
-
for (const key in components) {
|
|
152
|
-
ReactiveFns.set(key, components[key]);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (binders) {
|
|
156
|
-
for (const key in binders) {
|
|
157
|
-
ReactiveFnBinders.set(key, binders[key]);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
146
|
var hasSymbol = typeof Symbol === "function" && Symbol.for;
|
|
162
147
|
var didWarnProps = false;
|
|
163
148
|
function createReactiveComponent(component, observe3, reactive2, keysReactive, bindKeys) {
|
|
@@ -285,42 +270,7 @@ function reactiveComponents(components) {
|
|
|
285
270
|
);
|
|
286
271
|
}
|
|
287
272
|
|
|
288
|
-
// src/react
|
|
289
|
-
var Memo = React.memo(
|
|
290
|
-
Computed,
|
|
291
|
-
(prev, next) => next.scoped ? prev.children === next.children : true
|
|
292
|
-
);
|
|
293
|
-
var setReactProps = /* @__PURE__ */ new Set([
|
|
294
|
-
"$$typeof",
|
|
295
|
-
"defaultProps",
|
|
296
|
-
"propTypes",
|
|
297
|
-
"tag",
|
|
298
|
-
"PropTypes",
|
|
299
|
-
"displayName",
|
|
300
|
-
"getDefaultProps",
|
|
301
|
-
"type",
|
|
302
|
-
"compare"
|
|
303
|
-
]);
|
|
304
|
-
var reactives = {};
|
|
305
|
-
var $ = new Proxy(Memo, {
|
|
306
|
-
get(target, p) {
|
|
307
|
-
if (Object.hasOwn(target, p) || setReactProps.has(p)) {
|
|
308
|
-
return target[p];
|
|
309
|
-
}
|
|
310
|
-
if (!reactives[p]) {
|
|
311
|
-
const Component = ReactiveFns.get(p) || p;
|
|
312
|
-
const render = React.forwardRef((props, ref) => {
|
|
313
|
-
const propsOut = { ...props };
|
|
314
|
-
if (ref && (state.isFunction(ref) || !state.isEmpty(ref))) {
|
|
315
|
-
propsOut.ref = ref;
|
|
316
|
-
}
|
|
317
|
-
return React.createElement(Component, propsOut);
|
|
318
|
-
});
|
|
319
|
-
reactives[p] = reactive(render, [], ReactiveFnBinders.get(p));
|
|
320
|
-
}
|
|
321
|
-
return reactives[p];
|
|
322
|
-
}
|
|
323
|
-
});
|
|
273
|
+
// src/react/For.tsx
|
|
324
274
|
var { findIDKey, getNode, optimized } = state.internal;
|
|
325
275
|
var autoMemoCache = /* @__PURE__ */ new Map();
|
|
326
276
|
function For({
|
|
@@ -395,10 +345,31 @@ function For({
|
|
|
395
345
|
}
|
|
396
346
|
return out;
|
|
397
347
|
}
|
|
398
|
-
var
|
|
348
|
+
var Memo = React.memo(
|
|
399
349
|
Computed,
|
|
400
350
|
(prev, next) => next.scoped ? prev.children === next.children : true
|
|
401
351
|
);
|
|
352
|
+
|
|
353
|
+
// src/react/configureReactive.ts
|
|
354
|
+
var ReactiveFns = /* @__PURE__ */ new Map();
|
|
355
|
+
var ReactiveFnBinders = /* @__PURE__ */ new Map();
|
|
356
|
+
function configureReactive({
|
|
357
|
+
components,
|
|
358
|
+
binders
|
|
359
|
+
}) {
|
|
360
|
+
if (components) {
|
|
361
|
+
for (const key in components) {
|
|
362
|
+
ReactiveFns.set(key, components[key]);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (binders) {
|
|
366
|
+
for (const key in binders) {
|
|
367
|
+
ReactiveFnBinders.set(key, binders[key]);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// src/react/Reactive.tsx
|
|
402
373
|
var Reactive = new Proxy(
|
|
403
374
|
{},
|
|
404
375
|
{
|
|
@@ -607,10 +578,9 @@ function useWhenReady(predicate, effect) {
|
|
|
607
578
|
return React.useMemo(() => state.whenReady(predicate, effect), []);
|
|
608
579
|
}
|
|
609
580
|
|
|
610
|
-
exports.$ = $;
|
|
611
581
|
exports.Computed = Computed;
|
|
612
582
|
exports.For = For;
|
|
613
|
-
exports.Memo =
|
|
583
|
+
exports.Memo = Memo;
|
|
614
584
|
exports.Reactive = Reactive;
|
|
615
585
|
exports.Show = Show;
|
|
616
586
|
exports.Switch = Switch;
|
package/react.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isFunction, isEmpty, observable,
|
|
1
|
+
import { isFunction, isEmpty, observable, computeSelector, isArray, isMap, isObservableValueReady, linked, isPromise, observe, when, whenReady, internal, trackSelector, isPrimitive, isObservable } from '@legendapp/state';
|
|
2
2
|
import React, { memo, forwardRef, createElement, useState, useContext, useMemo, useRef, useEffect, createContext, useCallback } from 'react';
|
|
3
3
|
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
4
4
|
import { enableReactive } from '@legendapp/state/react-reactive/enableReactive';
|
|
@@ -95,12 +95,24 @@ function createSelectorFunctions(options, isPaused$) {
|
|
|
95
95
|
}
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
|
+
function doSuspense(selector) {
|
|
99
|
+
const vProm = when(selector);
|
|
100
|
+
if (React.use) {
|
|
101
|
+
React.use(vProm);
|
|
102
|
+
} else {
|
|
103
|
+
throw vProm;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
98
106
|
function useSelector(selector, options) {
|
|
99
107
|
var _a;
|
|
108
|
+
let value;
|
|
100
109
|
if (reactGlobals.inObserver && isObservable(selector) && !(options == null ? void 0 : options.suspense)) {
|
|
101
|
-
|
|
110
|
+
value = computeSelector(selector, options);
|
|
111
|
+
if ((options == null ? void 0 : options.suspense) && value === void 0) {
|
|
112
|
+
doSuspense(selector);
|
|
113
|
+
}
|
|
114
|
+
return value;
|
|
102
115
|
}
|
|
103
|
-
let value;
|
|
104
116
|
try {
|
|
105
117
|
const isPaused$ = useContext(getPauseContext());
|
|
106
118
|
const selectorFn = useMemo(() => createSelectorFunctions(options, isPaused$), []);
|
|
@@ -115,16 +127,8 @@ function useSelector(selector, options) {
|
|
|
115
127
|
}
|
|
116
128
|
throw err;
|
|
117
129
|
}
|
|
118
|
-
if (options == null ? void 0 : options.suspense) {
|
|
119
|
-
|
|
120
|
-
if (isPromise(value) || !value && isObservable(selector)) {
|
|
121
|
-
const vProm = isProm ? value : when(selector);
|
|
122
|
-
if (React.use) {
|
|
123
|
-
React.use(vProm);
|
|
124
|
-
} else {
|
|
125
|
-
throw vProm;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
130
|
+
if ((options == null ? void 0 : options.suspense) && value === void 0) {
|
|
131
|
+
doSuspense(selector);
|
|
128
132
|
}
|
|
129
133
|
return value;
|
|
130
134
|
}
|
|
@@ -133,25 +137,6 @@ function useSelector(selector, options) {
|
|
|
133
137
|
function Computed({ children }) {
|
|
134
138
|
return useSelector(() => computeSelector(computeSelector(children)), { skipCheck: true });
|
|
135
139
|
}
|
|
136
|
-
|
|
137
|
-
// src/react/configureReactive.ts
|
|
138
|
-
var ReactiveFns = /* @__PURE__ */ new Map();
|
|
139
|
-
var ReactiveFnBinders = /* @__PURE__ */ new Map();
|
|
140
|
-
function configureReactive({
|
|
141
|
-
components,
|
|
142
|
-
binders
|
|
143
|
-
}) {
|
|
144
|
-
if (components) {
|
|
145
|
-
for (const key in components) {
|
|
146
|
-
ReactiveFns.set(key, components[key]);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (binders) {
|
|
150
|
-
for (const key in binders) {
|
|
151
|
-
ReactiveFnBinders.set(key, binders[key]);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
140
|
var hasSymbol = typeof Symbol === "function" && Symbol.for;
|
|
156
141
|
var didWarnProps = false;
|
|
157
142
|
function createReactiveComponent(component, observe3, reactive2, keysReactive, bindKeys) {
|
|
@@ -279,42 +264,7 @@ function reactiveComponents(components) {
|
|
|
279
264
|
);
|
|
280
265
|
}
|
|
281
266
|
|
|
282
|
-
// src/react
|
|
283
|
-
var Memo = memo(
|
|
284
|
-
Computed,
|
|
285
|
-
(prev, next) => next.scoped ? prev.children === next.children : true
|
|
286
|
-
);
|
|
287
|
-
var setReactProps = /* @__PURE__ */ new Set([
|
|
288
|
-
"$$typeof",
|
|
289
|
-
"defaultProps",
|
|
290
|
-
"propTypes",
|
|
291
|
-
"tag",
|
|
292
|
-
"PropTypes",
|
|
293
|
-
"displayName",
|
|
294
|
-
"getDefaultProps",
|
|
295
|
-
"type",
|
|
296
|
-
"compare"
|
|
297
|
-
]);
|
|
298
|
-
var reactives = {};
|
|
299
|
-
var $ = new Proxy(Memo, {
|
|
300
|
-
get(target, p) {
|
|
301
|
-
if (Object.hasOwn(target, p) || setReactProps.has(p)) {
|
|
302
|
-
return target[p];
|
|
303
|
-
}
|
|
304
|
-
if (!reactives[p]) {
|
|
305
|
-
const Component = ReactiveFns.get(p) || p;
|
|
306
|
-
const render = forwardRef((props, ref) => {
|
|
307
|
-
const propsOut = { ...props };
|
|
308
|
-
if (ref && (isFunction(ref) || !isEmpty(ref))) {
|
|
309
|
-
propsOut.ref = ref;
|
|
310
|
-
}
|
|
311
|
-
return createElement(Component, propsOut);
|
|
312
|
-
});
|
|
313
|
-
reactives[p] = reactive(render, [], ReactiveFnBinders.get(p));
|
|
314
|
-
}
|
|
315
|
-
return reactives[p];
|
|
316
|
-
}
|
|
317
|
-
});
|
|
267
|
+
// src/react/For.tsx
|
|
318
268
|
var { findIDKey, getNode, optimized } = internal;
|
|
319
269
|
var autoMemoCache = /* @__PURE__ */ new Map();
|
|
320
270
|
function For({
|
|
@@ -389,10 +339,31 @@ function For({
|
|
|
389
339
|
}
|
|
390
340
|
return out;
|
|
391
341
|
}
|
|
392
|
-
var
|
|
342
|
+
var Memo = memo(
|
|
393
343
|
Computed,
|
|
394
344
|
(prev, next) => next.scoped ? prev.children === next.children : true
|
|
395
345
|
);
|
|
346
|
+
|
|
347
|
+
// src/react/configureReactive.ts
|
|
348
|
+
var ReactiveFns = /* @__PURE__ */ new Map();
|
|
349
|
+
var ReactiveFnBinders = /* @__PURE__ */ new Map();
|
|
350
|
+
function configureReactive({
|
|
351
|
+
components,
|
|
352
|
+
binders
|
|
353
|
+
}) {
|
|
354
|
+
if (components) {
|
|
355
|
+
for (const key in components) {
|
|
356
|
+
ReactiveFns.set(key, components[key]);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
if (binders) {
|
|
360
|
+
for (const key in binders) {
|
|
361
|
+
ReactiveFnBinders.set(key, binders[key]);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/react/Reactive.tsx
|
|
396
367
|
var Reactive = new Proxy(
|
|
397
368
|
{},
|
|
398
369
|
{
|
|
@@ -601,4 +572,4 @@ function useWhenReady(predicate, effect) {
|
|
|
601
572
|
return useMemo(() => whenReady(predicate, effect), []);
|
|
602
573
|
}
|
|
603
574
|
|
|
604
|
-
export {
|
|
575
|
+
export { Computed, For, Memo, Reactive, Show, Switch, configureReactive, hasSymbol, observer, reactive, reactiveComponents, reactiveObserver, useSelector as use$, useComputed, useEffectOnce, useIsMounted, useMount, useMountOnce, useObservable, useObservableReducer, useObserve, useObserveEffect, usePauseProvider, useSelector, useUnmount, useUnmountOnce, useWhen, useWhenReady };
|
package/sync-plugins/crud.d.mts
CHANGED
|
@@ -3,17 +3,23 @@ import { SyncedGetParams, SyncedErrorParams, SyncedOptions, SyncedSetParams, Syn
|
|
|
3
3
|
|
|
4
4
|
type CrudAsOption = 'Map' | 'object' | 'value' | 'array';
|
|
5
5
|
type CrudResult<T> = T;
|
|
6
|
+
interface SyncedCrudPropsNoRead<TLocal, TAsOption extends CrudAsOption> {
|
|
7
|
+
get?: never | undefined;
|
|
8
|
+
list?: never | undefined;
|
|
9
|
+
initial?: InitialValue<TLocal, TAsOption>;
|
|
10
|
+
as?: TAsOption;
|
|
11
|
+
}
|
|
6
12
|
interface SyncedCrudPropsSingle<TRemote extends object, TLocal> {
|
|
7
|
-
get
|
|
13
|
+
get: (params: SyncedGetParams<TRemote>) => Promise<CrudResult<TRemote | null>> | CrudResult<TRemote | null>;
|
|
8
14
|
list?: never | undefined;
|
|
9
|
-
initial?: InitialValue<TLocal
|
|
15
|
+
initial?: InitialValue<Partial<NoInfer<TLocal>>, 'value'>;
|
|
10
16
|
as?: never | 'value';
|
|
11
17
|
}
|
|
12
18
|
interface SyncedCrudPropsMany<TRemote extends object, TLocal, TAsOption extends CrudAsOption> {
|
|
13
|
-
list
|
|
19
|
+
list: (params: SyncedGetParams<TRemote>) => Promise<CrudResult<TRemote[] | null>> | CrudResult<TRemote[] | null>;
|
|
14
20
|
get?: never | undefined;
|
|
15
21
|
as?: TAsOption;
|
|
16
|
-
initial?: InitialValue<TLocal
|
|
22
|
+
initial?: InitialValue<Partial<NoInfer<TLocal>>, TAsOption>;
|
|
17
23
|
}
|
|
18
24
|
interface SyncedCrudOnSavedParams<TRemote extends object, TLocal> {
|
|
19
25
|
saved: TLocal;
|
|
@@ -52,8 +58,9 @@ type SyncedCrudReturnType<TLocal, TAsOption extends CrudAsOption> = TAsOption ex
|
|
|
52
58
|
} ? number : string, TLocal> : TAsOption extends 'object' ? Record<TLocal extends {
|
|
53
59
|
id: number;
|
|
54
60
|
} ? number : string, TLocal> : TAsOption extends 'value' ? TLocal : TLocal[];
|
|
61
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: SyncedCrudPropsNoRead<TRemote, TAsOption> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, TAsOption>;
|
|
55
62
|
declare function syncedCrud<TRemote extends object, TLocal = TRemote>(props: SyncedCrudPropsSingle<TRemote, TLocal> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, 'value'>;
|
|
56
63
|
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: SyncedCrudPropsMany<TRemote, TLocal, TAsOption> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, Exclude<TAsOption, 'value'>>;
|
|
57
64
|
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: (SyncedCrudPropsSingle<TRemote, TLocal> | SyncedCrudPropsMany<TRemote, TLocal, TAsOption>) & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, TAsOption>;
|
|
58
65
|
|
|
59
|
-
export { type CrudAsOption, type CrudErrorParams, type CrudOnErrorFn, type CrudResult, type SyncedCrudOnSavedParams, type SyncedCrudPropsBase, type SyncedCrudPropsMany, type SyncedCrudPropsSingle, type SyncedCrudReturnType, type WaitForSetCrudFnParams, syncedCrud };
|
|
66
|
+
export { type CrudAsOption, type CrudErrorParams, type CrudOnErrorFn, type CrudResult, type SyncedCrudOnSavedParams, type SyncedCrudPropsBase, type SyncedCrudPropsMany, type SyncedCrudPropsNoRead, type SyncedCrudPropsSingle, type SyncedCrudReturnType, type WaitForSetCrudFnParams, syncedCrud };
|
package/sync-plugins/crud.d.ts
CHANGED
|
@@ -3,17 +3,23 @@ import { SyncedGetParams, SyncedErrorParams, SyncedOptions, SyncedSetParams, Syn
|
|
|
3
3
|
|
|
4
4
|
type CrudAsOption = 'Map' | 'object' | 'value' | 'array';
|
|
5
5
|
type CrudResult<T> = T;
|
|
6
|
+
interface SyncedCrudPropsNoRead<TLocal, TAsOption extends CrudAsOption> {
|
|
7
|
+
get?: never | undefined;
|
|
8
|
+
list?: never | undefined;
|
|
9
|
+
initial?: InitialValue<TLocal, TAsOption>;
|
|
10
|
+
as?: TAsOption;
|
|
11
|
+
}
|
|
6
12
|
interface SyncedCrudPropsSingle<TRemote extends object, TLocal> {
|
|
7
|
-
get
|
|
13
|
+
get: (params: SyncedGetParams<TRemote>) => Promise<CrudResult<TRemote | null>> | CrudResult<TRemote | null>;
|
|
8
14
|
list?: never | undefined;
|
|
9
|
-
initial?: InitialValue<TLocal
|
|
15
|
+
initial?: InitialValue<Partial<NoInfer<TLocal>>, 'value'>;
|
|
10
16
|
as?: never | 'value';
|
|
11
17
|
}
|
|
12
18
|
interface SyncedCrudPropsMany<TRemote extends object, TLocal, TAsOption extends CrudAsOption> {
|
|
13
|
-
list
|
|
19
|
+
list: (params: SyncedGetParams<TRemote>) => Promise<CrudResult<TRemote[] | null>> | CrudResult<TRemote[] | null>;
|
|
14
20
|
get?: never | undefined;
|
|
15
21
|
as?: TAsOption;
|
|
16
|
-
initial?: InitialValue<TLocal
|
|
22
|
+
initial?: InitialValue<Partial<NoInfer<TLocal>>, TAsOption>;
|
|
17
23
|
}
|
|
18
24
|
interface SyncedCrudOnSavedParams<TRemote extends object, TLocal> {
|
|
19
25
|
saved: TLocal;
|
|
@@ -52,8 +58,9 @@ type SyncedCrudReturnType<TLocal, TAsOption extends CrudAsOption> = TAsOption ex
|
|
|
52
58
|
} ? number : string, TLocal> : TAsOption extends 'object' ? Record<TLocal extends {
|
|
53
59
|
id: number;
|
|
54
60
|
} ? number : string, TLocal> : TAsOption extends 'value' ? TLocal : TLocal[];
|
|
61
|
+
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: SyncedCrudPropsNoRead<TRemote, TAsOption> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, TAsOption>;
|
|
55
62
|
declare function syncedCrud<TRemote extends object, TLocal = TRemote>(props: SyncedCrudPropsSingle<TRemote, TLocal> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, 'value'>;
|
|
56
63
|
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: SyncedCrudPropsMany<TRemote, TLocal, TAsOption> & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, Exclude<TAsOption, 'value'>>;
|
|
57
64
|
declare function syncedCrud<TRemote extends object, TLocal = TRemote, TAsOption extends CrudAsOption = 'object'>(props: (SyncedCrudPropsSingle<TRemote, TLocal> | SyncedCrudPropsMany<TRemote, TLocal, TAsOption>) & SyncedCrudPropsBase<TRemote, TLocal>): SyncedCrudReturnType<TLocal, TAsOption>;
|
|
58
65
|
|
|
59
|
-
export { type CrudAsOption, type CrudErrorParams, type CrudOnErrorFn, type CrudResult, type SyncedCrudOnSavedParams, type SyncedCrudPropsBase, type SyncedCrudPropsMany, type SyncedCrudPropsSingle, type SyncedCrudReturnType, type WaitForSetCrudFnParams, syncedCrud };
|
|
66
|
+
export { type CrudAsOption, type CrudErrorParams, type CrudOnErrorFn, type CrudResult, type SyncedCrudOnSavedParams, type SyncedCrudPropsBase, type SyncedCrudPropsMany, type SyncedCrudPropsNoRead, type SyncedCrudPropsSingle, type SyncedCrudReturnType, type WaitForSetCrudFnParams, syncedCrud };
|
package/sync-plugins/crud.js
CHANGED
|
@@ -189,7 +189,7 @@ function syncedCrud(props) {
|
|
|
189
189
|
/*deep*/
|
|
190
190
|
true
|
|
191
191
|
),
|
|
192
|
-
itemValue[fieldId] ? { [fieldId]: itemValue[fieldId] } : {}
|
|
192
|
+
!state.isNullOrUndefined(itemValue[fieldId]) ? { [fieldId]: itemValue[fieldId] } : {}
|
|
193
193
|
) : itemValue;
|
|
194
194
|
};
|
|
195
195
|
changes.forEach((change) => {
|
|
@@ -198,10 +198,10 @@ function syncedCrud(props) {
|
|
|
198
198
|
if (value) {
|
|
199
199
|
let id = value == null ? void 0 : value[fieldId];
|
|
200
200
|
let isCreate = fieldCreatedAt ? !value[fieldCreatedAt] : !prevAtPath;
|
|
201
|
-
if (!id && generateId) {
|
|
201
|
+
if (!state.isNullOrUndefined(id) && generateId) {
|
|
202
202
|
id = ensureId(value, fieldId, generateId);
|
|
203
203
|
}
|
|
204
|
-
if (id) {
|
|
204
|
+
if (!state.isNullOrUndefined(id)) {
|
|
205
205
|
changesById.set(id, change);
|
|
206
206
|
if (pendingCreates.has(id)) {
|
|
207
207
|
isCreate = false;
|
|
@@ -304,7 +304,7 @@ function syncedCrud(props) {
|
|
|
304
304
|
let saved = (transform == null ? void 0 : transform.load) ? await transform.load(data, "set") : data;
|
|
305
305
|
const isChild = itemKey !== "undefined" && asType !== "value";
|
|
306
306
|
const currentPeeked = state.getNodeValue(node);
|
|
307
|
-
const currentValue = isChild ? (_a = asType === "array" && state.isArray(currentPeeked) ? currentPeeked.find((v) => v[fieldId] === itemKey) : void 0) != null ? _a : currentPeeked[itemKey] : currentPeeked;
|
|
307
|
+
const currentValue = isChild ? (_a = asType === "array" && state.isArray(currentPeeked) ? currentPeeked.find((v) => v[fieldId] === itemKey) : void 0) != null ? _a : asType === "Map" ? currentPeeked.get(itemKey) : currentPeeked[itemKey] : currentPeeked;
|
|
308
308
|
if (saved && !state.isNullOrUndefined(currentValue)) {
|
|
309
309
|
if (onSaved) {
|
|
310
310
|
const ret = onSaved({
|
package/sync-plugins/crud.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isPromise,
|
|
1
|
+
import { isPromise, isNullOrUndefined, applyChanges, setAtPath, symbolDelete, isArray, internal, getNodeValue } from '@legendapp/state';
|
|
2
2
|
import { synced, deepEqual, internal as internal$1, diffObjects } from '@legendapp/state/sync';
|
|
3
3
|
|
|
4
4
|
// src/sync-plugins/crud.ts
|
|
@@ -187,7 +187,7 @@ function syncedCrud(props) {
|
|
|
187
187
|
/*deep*/
|
|
188
188
|
true
|
|
189
189
|
),
|
|
190
|
-
itemValue[fieldId] ? { [fieldId]: itemValue[fieldId] } : {}
|
|
190
|
+
!isNullOrUndefined(itemValue[fieldId]) ? { [fieldId]: itemValue[fieldId] } : {}
|
|
191
191
|
) : itemValue;
|
|
192
192
|
};
|
|
193
193
|
changes.forEach((change) => {
|
|
@@ -196,10 +196,10 @@ function syncedCrud(props) {
|
|
|
196
196
|
if (value) {
|
|
197
197
|
let id = value == null ? void 0 : value[fieldId];
|
|
198
198
|
let isCreate = fieldCreatedAt ? !value[fieldCreatedAt] : !prevAtPath;
|
|
199
|
-
if (!id && generateId) {
|
|
199
|
+
if (!isNullOrUndefined(id) && generateId) {
|
|
200
200
|
id = ensureId(value, fieldId, generateId);
|
|
201
201
|
}
|
|
202
|
-
if (id) {
|
|
202
|
+
if (!isNullOrUndefined(id)) {
|
|
203
203
|
changesById.set(id, change);
|
|
204
204
|
if (pendingCreates.has(id)) {
|
|
205
205
|
isCreate = false;
|
|
@@ -302,7 +302,7 @@ function syncedCrud(props) {
|
|
|
302
302
|
let saved = (transform == null ? void 0 : transform.load) ? await transform.load(data, "set") : data;
|
|
303
303
|
const isChild = itemKey !== "undefined" && asType !== "value";
|
|
304
304
|
const currentPeeked = getNodeValue(node);
|
|
305
|
-
const currentValue = isChild ? (_a = asType === "array" && isArray(currentPeeked) ? currentPeeked.find((v) => v[fieldId] === itemKey) : void 0) != null ? _a : currentPeeked[itemKey] : currentPeeked;
|
|
305
|
+
const currentValue = isChild ? (_a = asType === "array" && isArray(currentPeeked) ? currentPeeked.find((v) => v[fieldId] === itemKey) : void 0) != null ? _a : asType === "Map" ? currentPeeked.get(itemKey) : currentPeeked[itemKey] : currentPeeked;
|
|
306
306
|
if (saved && !isNullOrUndefined(currentValue)) {
|
|
307
307
|
if (onSaved) {
|
|
308
308
|
const ret = onSaved({
|
package/sync-plugins/keel.d.mts
CHANGED
|
@@ -98,8 +98,8 @@ interface SyncedKeelPropsBase<TRemote extends {
|
|
|
98
98
|
create?: (i: NoInfer<Partial<TRemote>>) => Promise<APIResult<NoInfer<TRemote>>>;
|
|
99
99
|
update?: (params: {
|
|
100
100
|
where: any;
|
|
101
|
-
values?: NoInfer<
|
|
102
|
-
}) => Promise<APIResult<
|
|
101
|
+
values?: Partial<NoInfer<TRemote>>;
|
|
102
|
+
}) => Promise<APIResult<TRemote>>;
|
|
103
103
|
delete?: (params: {
|
|
104
104
|
id: string;
|
|
105
105
|
}) => Promise<APIResult<string>>;
|
package/sync-plugins/keel.d.ts
CHANGED
|
@@ -98,8 +98,8 @@ interface SyncedKeelPropsBase<TRemote extends {
|
|
|
98
98
|
create?: (i: NoInfer<Partial<TRemote>>) => Promise<APIResult<NoInfer<TRemote>>>;
|
|
99
99
|
update?: (params: {
|
|
100
100
|
where: any;
|
|
101
|
-
values?: NoInfer<
|
|
102
|
-
}) => Promise<APIResult<
|
|
101
|
+
values?: Partial<NoInfer<TRemote>>;
|
|
102
|
+
}) => Promise<APIResult<TRemote>>;
|
|
103
103
|
delete?: (params: {
|
|
104
104
|
id: string;
|
|
105
105
|
}) => Promise<APIResult<string>>;
|
package/sync-plugins/supabase.js
CHANGED
|
@@ -140,25 +140,28 @@ function syncedSupabase(props) {
|
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
142
|
} : void 0;
|
|
143
|
-
const deleteFn = !fieldDeleted && (!actions || actions.includes("delete")) ?
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
143
|
+
const deleteFn = !fieldDeleted && (!actions || actions.includes("delete")) ? (
|
|
144
|
+
// prettier-ignore
|
|
145
|
+
deleteParam ? wrapSupabaseFn(deleteParam, "delete") : async (input, params) => {
|
|
146
|
+
const { onError } = params;
|
|
147
|
+
const id = input.id;
|
|
148
|
+
const res = await client.from(collection).delete().eq("id", id).select();
|
|
149
|
+
const { data, error } = res;
|
|
150
|
+
if (data) {
|
|
151
|
+
const created = data[0];
|
|
152
|
+
return created;
|
|
153
|
+
} else if (error) {
|
|
154
|
+
handleSupabaseError(error, onError, {
|
|
155
|
+
setParams: params,
|
|
156
|
+
source: "delete",
|
|
157
|
+
type: "set",
|
|
158
|
+
retry: params,
|
|
159
|
+
input,
|
|
160
|
+
revert: sync.createRevertChanges(params.value$, params.changes)
|
|
161
|
+
});
|
|
162
|
+
}
|
|
160
163
|
}
|
|
161
|
-
|
|
164
|
+
) : void 0;
|
|
162
165
|
const subscribe = realtime ? ({ node, value$, update: update2 }) => {
|
|
163
166
|
const { filter: filter2, schema: schema2 } = state.isObject(realtime) ? realtime : {};
|
|
164
167
|
const channel = client.channel(`LS_${node.key || ""}${channelNum++}`).on(
|
|
@@ -138,25 +138,28 @@ function syncedSupabase(props) {
|
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
140
|
} : void 0;
|
|
141
|
-
const deleteFn = !fieldDeleted && (!actions || actions.includes("delete")) ?
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
141
|
+
const deleteFn = !fieldDeleted && (!actions || actions.includes("delete")) ? (
|
|
142
|
+
// prettier-ignore
|
|
143
|
+
deleteParam ? wrapSupabaseFn(deleteParam, "delete") : async (input, params) => {
|
|
144
|
+
const { onError } = params;
|
|
145
|
+
const id = input.id;
|
|
146
|
+
const res = await client.from(collection).delete().eq("id", id).select();
|
|
147
|
+
const { data, error } = res;
|
|
148
|
+
if (data) {
|
|
149
|
+
const created = data[0];
|
|
150
|
+
return created;
|
|
151
|
+
} else if (error) {
|
|
152
|
+
handleSupabaseError(error, onError, {
|
|
153
|
+
setParams: params,
|
|
154
|
+
source: "delete",
|
|
155
|
+
type: "set",
|
|
156
|
+
retry: params,
|
|
157
|
+
input,
|
|
158
|
+
revert: createRevertChanges(params.value$, params.changes)
|
|
159
|
+
});
|
|
160
|
+
}
|
|
158
161
|
}
|
|
159
|
-
|
|
162
|
+
) : void 0;
|
|
160
163
|
const subscribe = realtime ? ({ node, value$, update: update2 }) => {
|
|
161
164
|
const { filter: filter2, schema: schema2 } = isObject(realtime) ? realtime : {};
|
|
162
165
|
const channel = client.channel(`LS_${node.key || ""}${channelNum++}`).on(
|