@legendapp/state 3.0.0-beta.7 → 3.0.0-beta.8
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 +1 -1
- package/sync-plugins/crud.js +22 -24
- package/sync-plugins/crud.mjs +22 -24
package/package.json
CHANGED
package/sync-plugins/crud.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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
|
-
|
|
279
|
-
key !==
|
|
282
|
+
saved[key] === c || // user has changed local value
|
|
283
|
+
key !== fieldId && i !== c
|
|
280
284
|
) {
|
|
281
|
-
delete
|
|
285
|
+
delete saved[key];
|
|
282
286
|
}
|
|
283
287
|
});
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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,
|
package/sync-plugins/crud.mjs
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
|
|
277
|
-
key !==
|
|
280
|
+
saved[key] === c || // user has changed local value
|
|
281
|
+
key !== fieldId && i !== c
|
|
278
282
|
) {
|
|
279
|
-
delete
|
|
283
|
+
delete saved[key];
|
|
280
284
|
}
|
|
281
285
|
});
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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,
|