@legendapp/state 3.0.0-beta.28 → 3.0.0-beta.29

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.28",
3
+ "version": "3.0.0-beta.29",
4
4
  "description": "legend-state",
5
5
  "sideEffects": false,
6
6
  "private": false,
@@ -36,7 +36,7 @@ function arrayToRecord(arr, keyField) {
36
36
  }
37
37
  return record;
38
38
  }
39
- function retrySet(params, retry, action, itemKey, itemValue, change, queuedRetries, actionFn, saveResult) {
39
+ function retrySet(params, retry, action, itemKey, itemValue, change, queuedRetries, itemValueFull, actionFn, saveResult) {
40
40
  if (action === "delete") {
41
41
  if (queuedRetries.create.has(itemKey)) {
42
42
  queuedRetries.create.delete(itemKey);
@@ -54,7 +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
+ const clonedValue = clone(itemValueFull);
58
58
  const paramsWithChanges = { ...params, changes: [change] };
59
59
  return runWithRetry(
60
60
  paramsWithChanges,
@@ -401,6 +401,7 @@ function syncedCrud(props) {
401
401
  createObj,
402
402
  changesById.get(itemKey),
403
403
  queuedRetries,
404
+ createObj,
404
405
  createFn,
405
406
  saveResult
406
407
  ).then(() => {
@@ -409,11 +410,15 @@ function syncedCrud(props) {
409
410
  }),
410
411
  // Handle updates
411
412
  ...Array.from(updates).map(async ([itemKey, itemValue]) => {
413
+ const fullValue = updateFullValues.get(itemKey);
412
414
  if (waitForSetParam) {
413
- const fullValue = updateFullValues.get(itemKey);
414
415
  await waitForSet(waitForSetParam, changes, fullValue, { type: "update" });
415
416
  }
416
417
  const changed = await transformOut(itemValue, transform == null ? void 0 : transform.save);
418
+ const fullValueTransformed = await transformOut(
419
+ fullValue,
420
+ transform == null ? void 0 : transform.save
421
+ );
417
422
  if (Object.keys(changed).length > 0) {
418
423
  return retrySet(
419
424
  params,
@@ -423,6 +428,7 @@ function syncedCrud(props) {
423
428
  changed,
424
429
  changesById.get(itemKey),
425
430
  queuedRetries,
431
+ fullValueTransformed,
426
432
  updateFn,
427
433
  saveResult
428
434
  );
@@ -447,19 +453,22 @@ function syncedCrud(props) {
447
453
  valuePrevious,
448
454
  changesById.get(itemKey),
449
455
  queuedRetries,
456
+ valuePrevious,
450
457
  deleteFn,
451
458
  saveResult
452
459
  );
453
460
  }
454
461
  if (fieldDeleted && updateFn) {
462
+ const value2 = { [fieldId]: itemKey, [fieldDeleted]: true };
455
463
  return retrySet(
456
464
  params,
457
465
  retry,
458
466
  "delete",
459
467
  itemKey,
460
- { [fieldId]: itemKey, [fieldDeleted]: true },
468
+ value2,
461
469
  changesById.get(itemKey),
462
470
  queuedRetries,
471
+ value2,
463
472
  updateFn,
464
473
  saveResult
465
474
  );
@@ -34,7 +34,7 @@ function arrayToRecord(arr, keyField) {
34
34
  }
35
35
  return record;
36
36
  }
37
- function retrySet(params, retry, action, itemKey, itemValue, change, queuedRetries, actionFn, saveResult) {
37
+ function retrySet(params, retry, action, itemKey, itemValue, change, queuedRetries, itemValueFull, actionFn, saveResult) {
38
38
  if (action === "delete") {
39
39
  if (queuedRetries.create.has(itemKey)) {
40
40
  queuedRetries.create.delete(itemKey);
@@ -52,7 +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
+ const clonedValue = clone(itemValueFull);
56
56
  const paramsWithChanges = { ...params, changes: [change] };
57
57
  return runWithRetry(
58
58
  paramsWithChanges,
@@ -399,6 +399,7 @@ function syncedCrud(props) {
399
399
  createObj,
400
400
  changesById.get(itemKey),
401
401
  queuedRetries,
402
+ createObj,
402
403
  createFn,
403
404
  saveResult
404
405
  ).then(() => {
@@ -407,11 +408,15 @@ function syncedCrud(props) {
407
408
  }),
408
409
  // Handle updates
409
410
  ...Array.from(updates).map(async ([itemKey, itemValue]) => {
411
+ const fullValue = updateFullValues.get(itemKey);
410
412
  if (waitForSetParam) {
411
- const fullValue = updateFullValues.get(itemKey);
412
413
  await waitForSet(waitForSetParam, changes, fullValue, { type: "update" });
413
414
  }
414
415
  const changed = await transformOut(itemValue, transform == null ? void 0 : transform.save);
416
+ const fullValueTransformed = await transformOut(
417
+ fullValue,
418
+ transform == null ? void 0 : transform.save
419
+ );
415
420
  if (Object.keys(changed).length > 0) {
416
421
  return retrySet(
417
422
  params,
@@ -421,6 +426,7 @@ function syncedCrud(props) {
421
426
  changed,
422
427
  changesById.get(itemKey),
423
428
  queuedRetries,
429
+ fullValueTransformed,
424
430
  updateFn,
425
431
  saveResult
426
432
  );
@@ -445,19 +451,22 @@ function syncedCrud(props) {
445
451
  valuePrevious,
446
452
  changesById.get(itemKey),
447
453
  queuedRetries,
454
+ valuePrevious,
448
455
  deleteFn,
449
456
  saveResult
450
457
  );
451
458
  }
452
459
  if (fieldDeleted && updateFn) {
460
+ const value2 = { [fieldId]: itemKey, [fieldDeleted]: true };
453
461
  return retrySet(
454
462
  params,
455
463
  retry,
456
464
  "delete",
457
465
  itemKey,
458
- { [fieldId]: itemKey, [fieldDeleted]: true },
466
+ value2,
459
467
  changesById.get(itemKey),
460
468
  queuedRetries,
469
+ value2,
461
470
  updateFn,
462
471
  saveResult
463
472
  );