@colyseus/schema 3.0.16 → 3.0.18

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.
@@ -1538,15 +1538,6 @@ function decodeValue(decoder, operation, ref, index, type, bytes, it, allChanges
1538
1538
  else if (Schema.is(type)) {
1539
1539
  const refId = decode.number(bytes, it);
1540
1540
  value = $root.refs.get(refId);
1541
- if (previousValue) {
1542
- const previousRefId = $root.refIds.get(previousValue);
1543
- if (previousRefId &&
1544
- refId !== previousRefId &&
1545
- // FIXME: we may need to check for REPLACE operation as well
1546
- ((operation & OPERATION.DELETE) === OPERATION.DELETE)) {
1547
- $root.removeRef(previousRefId);
1548
- }
1549
- }
1550
1541
  if ((operation & OPERATION.ADD) === OPERATION.ADD) {
1551
1542
  const childType = decoder.getInstanceType(bytes, it, type);
1552
1543
  if (!value) {
@@ -1574,7 +1565,6 @@ function decodeValue(decoder, operation, ref, index, type, bytes, it, allChanges
1574
1565
  if (previousValue) {
1575
1566
  let previousRefId = $root.refIds.get(previousValue);
1576
1567
  if (previousRefId !== undefined && refId !== previousRefId) {
1577
- $root.removeRef(previousRefId);
1578
1568
  //
1579
1569
  // enqueue onRemove if structure has been replaced.
1580
1570
  //
@@ -1599,7 +1589,8 @@ function decodeValue(decoder, operation, ref, index, type, bytes, it, allChanges
1599
1589
  }
1600
1590
  }
1601
1591
  }
1602
- $root.addRef(refId, value, (valueRef !== previousValue));
1592
+ $root.addRef(refId, value, (valueRef !== previousValue ||
1593
+ (operation === OPERATION.DELETE_AND_ADD && valueRef === previousValue)));
1603
1594
  }
1604
1595
  return { value, previousValue };
1605
1596
  }
@@ -4075,7 +4066,7 @@ class ReferenceTracker {
4075
4066
  for (const index in metadata) {
4076
4067
  const field = metadata[index].name;
4077
4068
  const childRefId = typeof (ref[field]) === "object" && this.refIds.get(ref[field]);
4078
- if (childRefId) {
4069
+ if (childRefId && !this.deletedRefs.has(childRefId)) {
4079
4070
  this.removeRef(childRefId);
4080
4071
  }
4081
4072
  }
@@ -4083,7 +4074,12 @@ class ReferenceTracker {
4083
4074
  else {
4084
4075
  if (typeof (Object.values(ref[$childType])[0]) === "function") {
4085
4076
  Array.from(ref.values())
4086
- .forEach((child) => this.removeRef(this.refIds.get(child)));
4077
+ .forEach((child) => {
4078
+ const childRefId = this.refIds.get(child);
4079
+ if (!this.deletedRefs.has(childRefId)) {
4080
+ this.removeRef(childRefId);
4081
+ }
4082
+ });
4087
4083
  }
4088
4084
  }
4089
4085
  this.refs.delete(refId); // remove ref