@legendapp/state 3.0.0-beta.24 → 3.0.0-beta.27
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/index.js +6 -6
- package/index.mjs +6 -6
- package/package.json +1 -1
- package/persist-plugins/expo-sqlite.js +5 -3
- package/persist-plugins/expo-sqlite.mjs +5 -3
- package/react.d.mts +3 -1
- package/react.d.ts +3 -1
- package/sync-plugins/crud.js +2 -1
- package/sync-plugins/crud.mjs +2 -1
- package/sync-plugins/supabase.js +5 -4
- package/sync-plugins/supabase.mjs +5 -4
- package/sync.js +5 -0
- package/sync.mjs +5 -0
package/index.js
CHANGED
|
@@ -1601,7 +1601,7 @@ function setKey(node, key, newValue, level) {
|
|
|
1601
1601
|
setToObservable(childNode, newValue);
|
|
1602
1602
|
} else {
|
|
1603
1603
|
const { newValue: savedValue, prevValue, parentValue } = setNodeValue(childNode, newValue);
|
|
1604
|
-
const isPrim = isPrimitive(savedValue) || savedValue instanceof Date;
|
|
1604
|
+
const isPrim = isPrimitive(prevValue) || prevValue instanceof Date || isPrimitive(savedValue) || savedValue instanceof Date;
|
|
1605
1605
|
if (!isPrim) {
|
|
1606
1606
|
let parent = childNode;
|
|
1607
1607
|
do {
|
|
@@ -1677,7 +1677,7 @@ function handlerMapSet(node, p, value) {
|
|
|
1677
1677
|
} else if (isFunction(vProp)) {
|
|
1678
1678
|
return function(a, b, c) {
|
|
1679
1679
|
const l = arguments.length;
|
|
1680
|
-
const
|
|
1680
|
+
const valueMapOrSet = value;
|
|
1681
1681
|
if (p === "get") {
|
|
1682
1682
|
if (l > 0 && typeof a !== "boolean" && a !== optimized) {
|
|
1683
1683
|
return getProxy(node, a);
|
|
@@ -1691,14 +1691,14 @@ function handlerMapSet(node, p, value) {
|
|
|
1691
1691
|
return getProxy(node);
|
|
1692
1692
|
} else if (p === "delete") {
|
|
1693
1693
|
if (l > 0) {
|
|
1694
|
-
const prev = value.get ?
|
|
1694
|
+
const prev = value.get ? valueMapOrSet.get(a) : a;
|
|
1695
1695
|
deleteFn(node, a);
|
|
1696
1696
|
return prev !== void 0;
|
|
1697
1697
|
}
|
|
1698
1698
|
} else if (p === "clear") {
|
|
1699
|
-
const prev = new Map(
|
|
1700
|
-
const size =
|
|
1701
|
-
|
|
1699
|
+
const prev = isSet(valueMapOrSet) ? new Set(valueMapOrSet) : new Map(valueMapOrSet);
|
|
1700
|
+
const size = valueMapOrSet.size;
|
|
1701
|
+
valueMapOrSet.clear();
|
|
1702
1702
|
if (size) {
|
|
1703
1703
|
updateNodesAndNotify(node, value, prev);
|
|
1704
1704
|
}
|
package/index.mjs
CHANGED
|
@@ -1599,7 +1599,7 @@ function setKey(node, key, newValue, level) {
|
|
|
1599
1599
|
setToObservable(childNode, newValue);
|
|
1600
1600
|
} else {
|
|
1601
1601
|
const { newValue: savedValue, prevValue, parentValue } = setNodeValue(childNode, newValue);
|
|
1602
|
-
const isPrim = isPrimitive(savedValue) || savedValue instanceof Date;
|
|
1602
|
+
const isPrim = isPrimitive(prevValue) || prevValue instanceof Date || isPrimitive(savedValue) || savedValue instanceof Date;
|
|
1603
1603
|
if (!isPrim) {
|
|
1604
1604
|
let parent = childNode;
|
|
1605
1605
|
do {
|
|
@@ -1675,7 +1675,7 @@ function handlerMapSet(node, p, value) {
|
|
|
1675
1675
|
} else if (isFunction(vProp)) {
|
|
1676
1676
|
return function(a, b, c) {
|
|
1677
1677
|
const l = arguments.length;
|
|
1678
|
-
const
|
|
1678
|
+
const valueMapOrSet = value;
|
|
1679
1679
|
if (p === "get") {
|
|
1680
1680
|
if (l > 0 && typeof a !== "boolean" && a !== optimized) {
|
|
1681
1681
|
return getProxy(node, a);
|
|
@@ -1689,14 +1689,14 @@ function handlerMapSet(node, p, value) {
|
|
|
1689
1689
|
return getProxy(node);
|
|
1690
1690
|
} else if (p === "delete") {
|
|
1691
1691
|
if (l > 0) {
|
|
1692
|
-
const prev = value.get ?
|
|
1692
|
+
const prev = value.get ? valueMapOrSet.get(a) : a;
|
|
1693
1693
|
deleteFn(node, a);
|
|
1694
1694
|
return prev !== void 0;
|
|
1695
1695
|
}
|
|
1696
1696
|
} else if (p === "clear") {
|
|
1697
|
-
const prev = new Map(
|
|
1698
|
-
const size =
|
|
1699
|
-
|
|
1697
|
+
const prev = isSet(valueMapOrSet) ? new Set(valueMapOrSet) : new Map(valueMapOrSet);
|
|
1698
|
+
const size = valueMapOrSet.size;
|
|
1699
|
+
valueMapOrSet.clear();
|
|
1700
1700
|
if (size) {
|
|
1701
1701
|
updateNodesAndNotify(node, value, prev);
|
|
1702
1702
|
}
|
package/package.json
CHANGED
|
@@ -8,9 +8,11 @@ var MetadataSuffix = "__m";
|
|
|
8
8
|
var ObservablePersistSqlite = class {
|
|
9
9
|
constructor(storage) {
|
|
10
10
|
this.data = {};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
if (!storage) {
|
|
12
|
+
console.error(
|
|
13
|
+
"[legend-state] ObservablePersistSqlite failed to initialize. You need to pass the SQLiteStorage instance."
|
|
14
|
+
);
|
|
15
|
+
}
|
|
14
16
|
this.storage = storage;
|
|
15
17
|
}
|
|
16
18
|
getTable(table, init) {
|
|
@@ -6,9 +6,11 @@ var MetadataSuffix = "__m";
|
|
|
6
6
|
var ObservablePersistSqlite = class {
|
|
7
7
|
constructor(storage) {
|
|
8
8
|
this.data = {};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
if (!storage) {
|
|
10
|
+
console.error(
|
|
11
|
+
"[legend-state] ObservablePersistSqlite failed to initialize. You need to pass the SQLiteStorage instance."
|
|
12
|
+
);
|
|
13
|
+
}
|
|
12
14
|
this.storage = storage;
|
|
13
15
|
}
|
|
14
16
|
getTable(table, init) {
|
package/react.d.mts
CHANGED
|
@@ -46,7 +46,9 @@ interface PropsIfReady<T> {
|
|
|
46
46
|
interface PropsBase<T> {
|
|
47
47
|
else?: ReactNode | (() => ReactNode);
|
|
48
48
|
$value?: Observable<T>;
|
|
49
|
-
wrap?: FC
|
|
49
|
+
wrap?: FC<{
|
|
50
|
+
children: ReactNode;
|
|
51
|
+
}>;
|
|
50
52
|
children: ReactNode | ((value?: T) => ReactNode);
|
|
51
53
|
}
|
|
52
54
|
type Props<T> = PropsBase<T> & (PropsIf<T> | PropsIfReady<T>);
|
package/react.d.ts
CHANGED
|
@@ -46,7 +46,9 @@ interface PropsIfReady<T> {
|
|
|
46
46
|
interface PropsBase<T> {
|
|
47
47
|
else?: ReactNode | (() => ReactNode);
|
|
48
48
|
$value?: Observable<T>;
|
|
49
|
-
wrap?: FC
|
|
49
|
+
wrap?: FC<{
|
|
50
|
+
children: ReactNode;
|
|
51
|
+
}>;
|
|
50
52
|
children: ReactNode | ((value?: T) => ReactNode);
|
|
51
53
|
}
|
|
52
54
|
type Props<T> = PropsBase<T> & (PropsIf<T> | PropsIfReady<T>);
|
package/sync-plugins/crud.js
CHANGED
|
@@ -54,6 +54,7 @@ function retrySet(params, retry, action, itemKey, itemValue, change, queuedRetri
|
|
|
54
54
|
itemValue = Object.assign(queuedRetry, itemValue);
|
|
55
55
|
}
|
|
56
56
|
queuedRetries[action].set(itemKey, itemValue);
|
|
57
|
+
const clonedValue = clone(itemValue);
|
|
57
58
|
const paramsWithChanges = { ...params, changes: [change] };
|
|
58
59
|
return runWithRetry(
|
|
59
60
|
paramsWithChanges,
|
|
@@ -61,7 +62,7 @@ function retrySet(params, retry, action, itemKey, itemValue, change, queuedRetri
|
|
|
61
62
|
"create_" + itemKey,
|
|
62
63
|
() => actionFn(itemValue, paramsWithChanges).then((result) => {
|
|
63
64
|
queuedRetries[action].delete(itemKey);
|
|
64
|
-
return saveResult(itemKey,
|
|
65
|
+
return saveResult(itemKey, clonedValue, result, true, change);
|
|
65
66
|
})
|
|
66
67
|
);
|
|
67
68
|
}
|
package/sync-plugins/crud.mjs
CHANGED
|
@@ -52,6 +52,7 @@ function retrySet(params, retry, action, itemKey, itemValue, change, queuedRetri
|
|
|
52
52
|
itemValue = Object.assign(queuedRetry, itemValue);
|
|
53
53
|
}
|
|
54
54
|
queuedRetries[action].set(itemKey, itemValue);
|
|
55
|
+
const clonedValue = clone(itemValue);
|
|
55
56
|
const paramsWithChanges = { ...params, changes: [change] };
|
|
56
57
|
return runWithRetry(
|
|
57
58
|
paramsWithChanges,
|
|
@@ -59,7 +60,7 @@ function retrySet(params, retry, action, itemKey, itemValue, change, queuedRetri
|
|
|
59
60
|
"create_" + itemKey,
|
|
60
61
|
() => actionFn(itemValue, paramsWithChanges).then((result) => {
|
|
61
62
|
queuedRetries[action].delete(itemKey);
|
|
62
|
-
return saveResult(itemKey,
|
|
63
|
+
return saveResult(itemKey, clonedValue, result, true, change);
|
|
63
64
|
})
|
|
64
65
|
);
|
|
65
66
|
}
|
package/sync-plugins/supabase.js
CHANGED
|
@@ -54,6 +54,7 @@ function syncedSupabase(props) {
|
|
|
54
54
|
fieldUpdatedAt,
|
|
55
55
|
fieldDeleted,
|
|
56
56
|
realtime,
|
|
57
|
+
fieldId = "id",
|
|
57
58
|
changesSince,
|
|
58
59
|
transform: transformParam,
|
|
59
60
|
stringifyDates,
|
|
@@ -124,7 +125,7 @@ function syncedSupabase(props) {
|
|
|
124
125
|
} : void 0;
|
|
125
126
|
const update = !actions || actions.includes("update") ? updateParam ? wrapSupabaseFn(updateParam, "update") : async (input, params) => {
|
|
126
127
|
const { onError } = params;
|
|
127
|
-
const res = await client.from(collection).update(input).eq(
|
|
128
|
+
const res = await client.from(collection).update(input).eq(fieldId, input[fieldId]).select();
|
|
128
129
|
const { data, error } = res;
|
|
129
130
|
if (data) {
|
|
130
131
|
const created = data[0];
|
|
@@ -144,8 +145,7 @@ function syncedSupabase(props) {
|
|
|
144
145
|
// prettier-ignore
|
|
145
146
|
deleteParam ? wrapSupabaseFn(deleteParam, "delete") : async (input, params) => {
|
|
146
147
|
const { onError } = params;
|
|
147
|
-
const
|
|
148
|
-
const res = await client.from(collection).delete().eq("id", id).select();
|
|
148
|
+
const res = await client.from(collection).delete().eq(fieldId, input[fieldId]).select();
|
|
149
149
|
const { data, error } = res;
|
|
150
150
|
if (data) {
|
|
151
151
|
const created = data[0];
|
|
@@ -176,7 +176,7 @@ function syncedSupabase(props) {
|
|
|
176
176
|
var _a;
|
|
177
177
|
const { eventType, new: value, old } = payload;
|
|
178
178
|
if (eventType === "INSERT" || eventType === "UPDATE") {
|
|
179
|
-
const cur = (_a = value$.peek()) == null ? void 0 : _a[value
|
|
179
|
+
const cur = (_a = value$.peek()) == null ? void 0 : _a[value[fieldId]];
|
|
180
180
|
let isOk = !fieldUpdatedAt;
|
|
181
181
|
let lastSync = void 0;
|
|
182
182
|
if (!isOk) {
|
|
@@ -219,6 +219,7 @@ function syncedSupabase(props) {
|
|
|
219
219
|
fieldUpdatedAt,
|
|
220
220
|
fieldDeleted,
|
|
221
221
|
updatePartial: false,
|
|
222
|
+
fieldId,
|
|
222
223
|
transform,
|
|
223
224
|
generateId,
|
|
224
225
|
waitFor: () => isEnabled$.get() && (waitFor ? state.computeSelector(waitFor) : true),
|
|
@@ -52,6 +52,7 @@ function syncedSupabase(props) {
|
|
|
52
52
|
fieldUpdatedAt,
|
|
53
53
|
fieldDeleted,
|
|
54
54
|
realtime,
|
|
55
|
+
fieldId = "id",
|
|
55
56
|
changesSince,
|
|
56
57
|
transform: transformParam,
|
|
57
58
|
stringifyDates,
|
|
@@ -122,7 +123,7 @@ function syncedSupabase(props) {
|
|
|
122
123
|
} : void 0;
|
|
123
124
|
const update = !actions || actions.includes("update") ? updateParam ? wrapSupabaseFn(updateParam, "update") : async (input, params) => {
|
|
124
125
|
const { onError } = params;
|
|
125
|
-
const res = await client.from(collection).update(input).eq(
|
|
126
|
+
const res = await client.from(collection).update(input).eq(fieldId, input[fieldId]).select();
|
|
126
127
|
const { data, error } = res;
|
|
127
128
|
if (data) {
|
|
128
129
|
const created = data[0];
|
|
@@ -142,8 +143,7 @@ function syncedSupabase(props) {
|
|
|
142
143
|
// prettier-ignore
|
|
143
144
|
deleteParam ? wrapSupabaseFn(deleteParam, "delete") : async (input, params) => {
|
|
144
145
|
const { onError } = params;
|
|
145
|
-
const
|
|
146
|
-
const res = await client.from(collection).delete().eq("id", id).select();
|
|
146
|
+
const res = await client.from(collection).delete().eq(fieldId, input[fieldId]).select();
|
|
147
147
|
const { data, error } = res;
|
|
148
148
|
if (data) {
|
|
149
149
|
const created = data[0];
|
|
@@ -174,7 +174,7 @@ function syncedSupabase(props) {
|
|
|
174
174
|
var _a;
|
|
175
175
|
const { eventType, new: value, old } = payload;
|
|
176
176
|
if (eventType === "INSERT" || eventType === "UPDATE") {
|
|
177
|
-
const cur = (_a = value$.peek()) == null ? void 0 : _a[value
|
|
177
|
+
const cur = (_a = value$.peek()) == null ? void 0 : _a[value[fieldId]];
|
|
178
178
|
let isOk = !fieldUpdatedAt;
|
|
179
179
|
let lastSync = void 0;
|
|
180
180
|
if (!isOk) {
|
|
@@ -217,6 +217,7 @@ function syncedSupabase(props) {
|
|
|
217
217
|
fieldUpdatedAt,
|
|
218
218
|
fieldDeleted,
|
|
219
219
|
updatePartial: false,
|
|
220
|
+
fieldId,
|
|
220
221
|
transform,
|
|
221
222
|
generateId,
|
|
222
223
|
waitFor: () => isEnabled$.get() && (waitFor ? computeSelector(waitFor) : true),
|
package/sync.js
CHANGED
|
@@ -835,6 +835,11 @@ async function loadLocal(value$, syncOptions, syncState$, localState) {
|
|
|
835
835
|
].filter(Boolean)
|
|
836
836
|
);
|
|
837
837
|
} else {
|
|
838
|
+
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && persist && persist.plugin && !Object.hasOwn(persist, "name")) {
|
|
839
|
+
console.warn(
|
|
840
|
+
"[legend-state] Trying to syncObservable without `name` defined. Please include a `name` property in the `persist` configuration."
|
|
841
|
+
);
|
|
842
|
+
}
|
|
838
843
|
nodeValue.resetPersistence = () => prevResetPersistence == null ? void 0 : prevResetPersistence();
|
|
839
844
|
}
|
|
840
845
|
nodeValue.clearPersist = nodeValue.resetPersistence;
|
package/sync.mjs
CHANGED
|
@@ -833,6 +833,11 @@ async function loadLocal(value$, syncOptions, syncState$, localState) {
|
|
|
833
833
|
].filter(Boolean)
|
|
834
834
|
);
|
|
835
835
|
} else {
|
|
836
|
+
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && persist && persist.plugin && !Object.hasOwn(persist, "name")) {
|
|
837
|
+
console.warn(
|
|
838
|
+
"[legend-state] Trying to syncObservable without `name` defined. Please include a `name` property in the `persist` configuration."
|
|
839
|
+
);
|
|
840
|
+
}
|
|
836
841
|
nodeValue.resetPersistence = () => prevResetPersistence == null ? void 0 : prevResetPersistence();
|
|
837
842
|
}
|
|
838
843
|
nodeValue.clearPersist = nodeValue.resetPersistence;
|