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