@colyseus/schema 3.0.21 → 3.0.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.
@@ -3923,13 +3923,14 @@ class Encoder {
3923
3923
  const changeTree = this.root.changeTrees[refId];
3924
3924
  if (changeTree === undefined) {
3925
3925
  // detached instance, remove from view and skip.
3926
+ // console.log("detached instance, remove from view and skip.", refId);
3926
3927
  view.changes.delete(refId);
3927
3928
  continue;
3928
3929
  }
3929
3930
  const keys = Object.keys(changes);
3930
3931
  if (keys.length === 0) {
3931
3932
  // FIXME: avoid having empty changes if no changes were made
3932
- // console.log("changes.size === 0, skip", changeTree.ref.constructor.name);
3933
+ // console.log("changes.size === 0, skip", refId, changeTree.ref.constructor.name);
3933
3934
  continue;
3934
3935
  }
3935
3936
  const ref = changeTree.ref;
@@ -4075,7 +4076,7 @@ class ReferenceTracker {
4075
4076
  //
4076
4077
  // Ensure child schema instances have their references removed as well.
4077
4078
  //
4078
- if (Metadata.isValidInstance(ref)) {
4079
+ if (ref.constructor[Symbol.metadata] !== undefined) {
4079
4080
  const metadata = ref.constructor[Symbol.metadata];
4080
4081
  for (const index in metadata) {
4081
4082
  const field = metadata[index].name;
@@ -4086,7 +4087,7 @@ class ReferenceTracker {
4086
4087
  }
4087
4088
  }
4088
4089
  else {
4089
- if (typeof (Object.values(ref[$childType])[0]) === "function") {
4090
+ if (typeof (ref[$childType]) === "function") {
4090
4091
  Array.from(ref.values())
4091
4092
  .forEach((child) => {
4092
4093
  const childRefId = this.refIds.get(child);
@@ -4729,7 +4730,7 @@ class StateView {
4729
4730
  }
4730
4731
  // TODO: allow to set multiple tags at once
4731
4732
  add(obj, tag = DEFAULT_VIEW_TAG, checkIncludeParent = true) {
4732
- if (!obj[$changes]) {
4733
+ if (!obj?.[$changes]) {
4733
4734
  console.warn("StateView#add(), invalid object:", obj);
4734
4735
  return this;
4735
4736
  }
@@ -4851,7 +4852,7 @@ class StateView {
4851
4852
  }
4852
4853
  this.items.delete(changeTree);
4853
4854
  const ref = changeTree.ref;
4854
- const metadata = ref.constructor[Symbol.metadata];
4855
+ const metadata = ref.constructor[Symbol.metadata]; // ArraySchema/MapSchema do not have metadata
4855
4856
  let changes = this.changes.get(changeTree.refId);
4856
4857
  if (changes === undefined) {
4857
4858
  changes = {};
@@ -4872,12 +4873,12 @@ class StateView {
4872
4873
  }
4873
4874
  else {
4874
4875
  // delete all "tagged" properties.
4875
- metadata[$viewFieldIndexes].forEach((index) => changes[index] = exports.OPERATION.DELETE);
4876
+ metadata?.[$viewFieldIndexes].forEach((index) => changes[index] = exports.OPERATION.DELETE);
4876
4877
  }
4877
4878
  }
4878
4879
  else {
4879
4880
  // delete only tagged properties
4880
- metadata[$fieldIndexesByViewTag][tag].forEach((index) => changes[index] = exports.OPERATION.DELETE);
4881
+ metadata?.[$fieldIndexesByViewTag][tag].forEach((index) => changes[index] = exports.OPERATION.DELETE);
4881
4882
  }
4882
4883
  // remove tag
4883
4884
  if (this.tags && this.tags.has(changeTree)) {