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