@legendapp/state 3.0.0-beta.20 → 3.0.0-beta.22
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 +13 -5
- package/sync-plugins/crud.mjs +13 -5
package/package.json
CHANGED
package/sync-plugins/crud.js
CHANGED
|
@@ -179,6 +179,7 @@ function syncedCrud(props) {
|
|
|
179
179
|
const { value, changes, update, retryAsCreate, node } = params;
|
|
180
180
|
const creates = /* @__PURE__ */ new Map();
|
|
181
181
|
const updates = /* @__PURE__ */ new Map();
|
|
182
|
+
const updateFullValues = /* @__PURE__ */ new Map();
|
|
182
183
|
const deletes = /* @__PURE__ */ new Set();
|
|
183
184
|
const changesById = /* @__PURE__ */ new Map();
|
|
184
185
|
const getUpdateValue = (itemValue, prev) => {
|
|
@@ -198,7 +199,7 @@ function syncedCrud(props) {
|
|
|
198
199
|
if (value) {
|
|
199
200
|
let id = value == null ? void 0 : value[fieldId];
|
|
200
201
|
let isCreate = fieldCreatedAt ? !value[fieldCreatedAt] : !prevAtPath;
|
|
201
|
-
if (
|
|
202
|
+
if (state.isNullOrUndefined(id) && generateId) {
|
|
202
203
|
id = ensureId(value, fieldId, generateId);
|
|
203
204
|
}
|
|
204
205
|
if (!state.isNullOrUndefined(id)) {
|
|
@@ -215,6 +216,7 @@ function syncedCrud(props) {
|
|
|
215
216
|
} else if (path.length === 0) {
|
|
216
217
|
if (valueAtPath) {
|
|
217
218
|
updates.set(id, getUpdateValue(valueAtPath, prevAtPath));
|
|
219
|
+
updateFullValues.set(id, valueAtPath);
|
|
218
220
|
} else if (prevAtPath) {
|
|
219
221
|
deletes.add(prevAtPath);
|
|
220
222
|
}
|
|
@@ -226,6 +228,7 @@ function syncedCrud(props) {
|
|
|
226
228
|
true
|
|
227
229
|
);
|
|
228
230
|
updates.set(id, getUpdateValue(value, previous));
|
|
231
|
+
updateFullValues.set(id, value);
|
|
229
232
|
}
|
|
230
233
|
} else {
|
|
231
234
|
console.error("[legend-state]: added synced item without an id");
|
|
@@ -247,7 +250,7 @@ function syncedCrud(props) {
|
|
|
247
250
|
} else {
|
|
248
251
|
const isDiff = !prevAtPath || !sync.deepEqual(value2, prev);
|
|
249
252
|
if (isDiff) {
|
|
250
|
-
itemsChanged.push([getUpdateValue(value2, prev), prev]);
|
|
253
|
+
itemsChanged.push([getUpdateValue(value2, prev), prev, value2]);
|
|
251
254
|
}
|
|
252
255
|
}
|
|
253
256
|
}
|
|
@@ -266,10 +269,10 @@ function syncedCrud(props) {
|
|
|
266
269
|
pathTypes.slice(1),
|
|
267
270
|
prevAtPath
|
|
268
271
|
);
|
|
269
|
-
itemsChanged = [[getUpdateValue(itemValue, previous), previous]];
|
|
272
|
+
itemsChanged = [[getUpdateValue(itemValue, previous), previous, itemValue]];
|
|
270
273
|
}
|
|
271
274
|
}
|
|
272
|
-
itemsChanged == null ? void 0 : itemsChanged.forEach(([item, prev]) => {
|
|
275
|
+
itemsChanged == null ? void 0 : itemsChanged.forEach(([item, prev, fullValue]) => {
|
|
273
276
|
const isCreate = !pendingCreates.has(item[fieldId]) && (fieldCreatedAt ? !item[fieldCreatedAt] && !(prev == null ? void 0 : prev[fieldCreatedAt]) : fieldUpdatedAt ? !item[fieldUpdatedAt] && !(prev == null ? void 0 : prev[fieldCreatedAt]) : state.isNullOrUndefined(prev));
|
|
274
277
|
if (isCreate) {
|
|
275
278
|
if (generateId) {
|
|
@@ -291,6 +294,10 @@ function syncedCrud(props) {
|
|
|
291
294
|
const id = item[fieldId];
|
|
292
295
|
changesById.set(id, change);
|
|
293
296
|
updates.set(id, updates.has(id) ? Object.assign(updates.get(id), item) : item);
|
|
297
|
+
updateFullValues.set(
|
|
298
|
+
id,
|
|
299
|
+
updateFullValues.has(id) ? Object.assign(updateFullValues.get(id), fullValue) : fullValue
|
|
300
|
+
);
|
|
294
301
|
} else {
|
|
295
302
|
console.warn("[legend-state] missing update function");
|
|
296
303
|
}
|
|
@@ -377,7 +384,8 @@ function syncedCrud(props) {
|
|
|
377
384
|
// Handle updates
|
|
378
385
|
...Array.from(updates).map(async ([itemKey, itemValue]) => {
|
|
379
386
|
if (waitForSetParam) {
|
|
380
|
-
|
|
387
|
+
const fullValue = updateFullValues.get(itemKey);
|
|
388
|
+
await waitForSet(waitForSetParam, changes, fullValue, { type: "update" });
|
|
381
389
|
}
|
|
382
390
|
const changed = await transformOut(itemValue, transform == null ? void 0 : transform.save);
|
|
383
391
|
if (Object.keys(changed).length > 0) {
|
package/sync-plugins/crud.mjs
CHANGED
|
@@ -177,6 +177,7 @@ function syncedCrud(props) {
|
|
|
177
177
|
const { value, changes, update, retryAsCreate, node } = params;
|
|
178
178
|
const creates = /* @__PURE__ */ new Map();
|
|
179
179
|
const updates = /* @__PURE__ */ new Map();
|
|
180
|
+
const updateFullValues = /* @__PURE__ */ new Map();
|
|
180
181
|
const deletes = /* @__PURE__ */ new Set();
|
|
181
182
|
const changesById = /* @__PURE__ */ new Map();
|
|
182
183
|
const getUpdateValue = (itemValue, prev) => {
|
|
@@ -196,7 +197,7 @@ function syncedCrud(props) {
|
|
|
196
197
|
if (value) {
|
|
197
198
|
let id = value == null ? void 0 : value[fieldId];
|
|
198
199
|
let isCreate = fieldCreatedAt ? !value[fieldCreatedAt] : !prevAtPath;
|
|
199
|
-
if (
|
|
200
|
+
if (isNullOrUndefined(id) && generateId) {
|
|
200
201
|
id = ensureId(value, fieldId, generateId);
|
|
201
202
|
}
|
|
202
203
|
if (!isNullOrUndefined(id)) {
|
|
@@ -213,6 +214,7 @@ function syncedCrud(props) {
|
|
|
213
214
|
} else if (path.length === 0) {
|
|
214
215
|
if (valueAtPath) {
|
|
215
216
|
updates.set(id, getUpdateValue(valueAtPath, prevAtPath));
|
|
217
|
+
updateFullValues.set(id, valueAtPath);
|
|
216
218
|
} else if (prevAtPath) {
|
|
217
219
|
deletes.add(prevAtPath);
|
|
218
220
|
}
|
|
@@ -224,6 +226,7 @@ function syncedCrud(props) {
|
|
|
224
226
|
true
|
|
225
227
|
);
|
|
226
228
|
updates.set(id, getUpdateValue(value, previous));
|
|
229
|
+
updateFullValues.set(id, value);
|
|
227
230
|
}
|
|
228
231
|
} else {
|
|
229
232
|
console.error("[legend-state]: added synced item without an id");
|
|
@@ -245,7 +248,7 @@ function syncedCrud(props) {
|
|
|
245
248
|
} else {
|
|
246
249
|
const isDiff = !prevAtPath || !deepEqual(value2, prev);
|
|
247
250
|
if (isDiff) {
|
|
248
|
-
itemsChanged.push([getUpdateValue(value2, prev), prev]);
|
|
251
|
+
itemsChanged.push([getUpdateValue(value2, prev), prev, value2]);
|
|
249
252
|
}
|
|
250
253
|
}
|
|
251
254
|
}
|
|
@@ -264,10 +267,10 @@ function syncedCrud(props) {
|
|
|
264
267
|
pathTypes.slice(1),
|
|
265
268
|
prevAtPath
|
|
266
269
|
);
|
|
267
|
-
itemsChanged = [[getUpdateValue(itemValue, previous), previous]];
|
|
270
|
+
itemsChanged = [[getUpdateValue(itemValue, previous), previous, itemValue]];
|
|
268
271
|
}
|
|
269
272
|
}
|
|
270
|
-
itemsChanged == null ? void 0 : itemsChanged.forEach(([item, prev]) => {
|
|
273
|
+
itemsChanged == null ? void 0 : itemsChanged.forEach(([item, prev, fullValue]) => {
|
|
271
274
|
const isCreate = !pendingCreates.has(item[fieldId]) && (fieldCreatedAt ? !item[fieldCreatedAt] && !(prev == null ? void 0 : prev[fieldCreatedAt]) : fieldUpdatedAt ? !item[fieldUpdatedAt] && !(prev == null ? void 0 : prev[fieldCreatedAt]) : isNullOrUndefined(prev));
|
|
272
275
|
if (isCreate) {
|
|
273
276
|
if (generateId) {
|
|
@@ -289,6 +292,10 @@ function syncedCrud(props) {
|
|
|
289
292
|
const id = item[fieldId];
|
|
290
293
|
changesById.set(id, change);
|
|
291
294
|
updates.set(id, updates.has(id) ? Object.assign(updates.get(id), item) : item);
|
|
295
|
+
updateFullValues.set(
|
|
296
|
+
id,
|
|
297
|
+
updateFullValues.has(id) ? Object.assign(updateFullValues.get(id), fullValue) : fullValue
|
|
298
|
+
);
|
|
292
299
|
} else {
|
|
293
300
|
console.warn("[legend-state] missing update function");
|
|
294
301
|
}
|
|
@@ -375,7 +382,8 @@ function syncedCrud(props) {
|
|
|
375
382
|
// Handle updates
|
|
376
383
|
...Array.from(updates).map(async ([itemKey, itemValue]) => {
|
|
377
384
|
if (waitForSetParam) {
|
|
378
|
-
|
|
385
|
+
const fullValue = updateFullValues.get(itemKey);
|
|
386
|
+
await waitForSet(waitForSetParam, changes, fullValue, { type: "update" });
|
|
379
387
|
}
|
|
380
388
|
const changed = await transformOut(itemValue, transform == null ? void 0 : transform.save);
|
|
381
389
|
if (Object.keys(changed).length > 0) {
|