@colyseus/schema 3.0.10 → 3.0.11

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.
@@ -1236,6 +1236,7 @@ class ChangeTree {
1236
1236
  //
1237
1237
  this.root?.remove(previousValue[$changes]);
1238
1238
  }
1239
+ deleteOperationAtIndex(this.allChanges, allChangesIndex);
1239
1240
  //
1240
1241
  // FIXME: this is looking a ugly and repeated
1241
1242
  //
@@ -1244,7 +1245,6 @@ class ChangeTree {
1244
1245
  enqueueChangeTree(this.root, this, 'filteredChanges');
1245
1246
  }
1246
1247
  else {
1247
- deleteOperationAtIndex(this.allChanges, allChangesIndex);
1248
1248
  enqueueChangeTree(this.root, this, 'changes');
1249
1249
  }
1250
1250
  }
@@ -3745,15 +3745,31 @@ class Root {
3745
3745
  }
3746
3746
  else {
3747
3747
  this.refCount[changeTree.refId] = refCount;
3748
+ //
3749
+ // When losing a reference to an instance, it is best to move the
3750
+ // ChangeTree to the end of the encoding queue.
3751
+ //
3752
+ // This way, at decoding time, the instance that contains the
3753
+ // ChangeTree will be available before the ChangeTree itself. If the
3754
+ // containing instance is not available, the Decoder will throw
3755
+ // "refId not found" error.
3756
+ //
3757
+ if (changeTree.filteredChanges !== undefined) {
3758
+ this.removeChangeFromChangeSet("filteredChanges", changeTree);
3759
+ enqueueChangeTree(this, changeTree, "filteredChanges");
3760
+ }
3761
+ else {
3762
+ this.removeChangeFromChangeSet("changes", changeTree);
3763
+ enqueueChangeTree(this, changeTree, "changes");
3764
+ }
3748
3765
  }
3749
3766
  changeTree.forEachChild((child, _) => this.remove(child));
3750
3767
  return refCount;
3751
3768
  }
3752
3769
  removeChangeFromChangeSet(changeSetName, changeTree) {
3753
3770
  const changeSet = this[changeSetName];
3754
- const index = changeSet.indexOf(changeTree);
3755
- if (index !== -1) {
3756
- spliceOne(changeSet, index);
3771
+ if (spliceOne(changeSet, changeSet.indexOf(changeTree))) {
3772
+ changeTree[changeSetName].queueRootIndex = -1;
3757
3773
  // changeSet[index] = undefined;
3758
3774
  }
3759
3775
  }