@colyseus/schema 3.0.8 → 3.0.10

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.
@@ -1846,7 +1846,6 @@ class ArraySchema {
1846
1846
  * - Then, the encoder iterates over all "owned" properties per instance and encodes them.
1847
1847
  */
1848
1848
  static [(_a$4 = $encoder, _b$4 = $decoder, $filter)](ref, index, view) {
1849
- // console.log("ArraSchema[$filter] VIEW??", !view)
1850
1849
  return (!view ||
1851
1850
  typeof (ref[$childType]) === "string" ||
1852
1851
  // view.items.has(ref[$getByIndex](index)[$changes])
@@ -2446,6 +2445,7 @@ class ArraySchema {
2446
2445
  }
2447
2446
  [$deleteByIndex](index) {
2448
2447
  this.items[index] = undefined;
2448
+ this.tmpItems[index] = undefined; // TODO: do not try to get "tmpItems" at decoding time.
2449
2449
  }
2450
2450
  [$onEncodeEnd]() {
2451
2451
  this.tmpItems = this.items.slice();
@@ -2453,6 +2453,7 @@ class ArraySchema {
2453
2453
  }
2454
2454
  [$onDecodeEnd]() {
2455
2455
  this.items = this.items.filter((item) => item !== undefined);
2456
+ this.tmpItems = this.items.slice(); // TODO: do no use "tmpItems" at decoding time.
2456
2457
  }
2457
2458
  toArray() {
2458
2459
  return this.items.slice(0);
@@ -3079,7 +3080,6 @@ var _a$2, _b$2;
3079
3080
  class Schema {
3080
3081
  static { this[_a$2] = encodeSchemaOperation; }
3081
3082
  static { this[_b$2] = decodeSchemaOperation; }
3082
- // public [$changes]: ChangeTree;
3083
3083
  /**
3084
3084
  * Assign the property descriptors required to track changes on this instance.
3085
3085
  * @param instance
@@ -3211,16 +3211,16 @@ class Schema {
3211
3211
  /**
3212
3212
  * Inspect the `refId` of all Schema instances in the tree. Optionally display the contents of the instance.
3213
3213
  *
3214
- * @param instance Schema instance
3214
+ * @param ref Schema instance
3215
3215
  * @param showContents display JSON contents of the instance
3216
3216
  * @returns
3217
3217
  */
3218
- static debugRefIds(instance, showContents = false, level = 0) {
3219
- const ref = instance;
3220
- const changeTree = ref[$changes];
3218
+ static debugRefIds(ref, showContents = false, level = 0) {
3221
3219
  const contents = (showContents) ? ` - ${JSON.stringify(ref.toJSON())}` : "";
3220
+ const changeTree = ref[$changes];
3221
+ const refId = changeTree.refId;
3222
3222
  let output = "";
3223
- output += `${getIndent(level)}${ref.constructor.name} (refId: ${ref[$changes].refId})${contents}\n`;
3223
+ output += `${getIndent(level)}${ref.constructor.name} (refId: ${refId})${contents}\n`;
3224
3224
  changeTree.forEachChild((childChangeTree) => output += this.debugRefIds(childChangeTree.ref, showContents, level + 1));
3225
3225
  return output;
3226
3226
  }
@@ -4035,7 +4035,7 @@ class ReferenceTracker {
4035
4035
  const refCount = this.refCounts[refId];
4036
4036
  if (refCount === undefined) {
4037
4037
  try {
4038
- throw new DecodingWarning("trying to remove refId that doesn't exist");
4038
+ throw new DecodingWarning("trying to remove refId that doesn't exist: " + refId);
4039
4039
  }
4040
4040
  catch (e) {
4041
4041
  console.warn(e);
@@ -4416,7 +4416,6 @@ function getDecoderStateCallbacks(decoder) {
4416
4416
  const onAddCalls = new WeakMap();
4417
4417
  let currentOnAddCallback;
4418
4418
  decoder.triggerChanges = function (allChanges) {
4419
- // console.log("ALL CHANGES =>", allChanges);
4420
4419
  const uniqueRefIds = new Set();
4421
4420
  for (let i = 0, l = allChanges.length; i < l; i++) {
4422
4421
  const change = allChanges[i];
@@ -4559,9 +4558,7 @@ function getDecoderStateCallbacks(decoder) {
4559
4558
  if (metadataField) {
4560
4559
  const instance = context.instance?.[prop];
4561
4560
  const onInstanceAvailable = ((callback) => {
4562
- console.log("onInstanceAvailable!!");
4563
4561
  const unbind = $(context.instance).listen(prop, (value, _) => {
4564
- console.log("prop changed!", prop);
4565
4562
  callback(value, false);
4566
4563
  // FIXME: by "unbinding" the callback here,
4567
4564
  // it will not support when the server
@@ -4609,11 +4606,9 @@ function getDecoderStateCallbacks(decoder) {
4609
4606
  });
4610
4607
  };
4611
4608
  const onRemove = function (ref, callback) {
4612
- console.log("REGISTER ON REMOVE ON", $root.refIds.get(ref));
4613
4609
  return $root.addCallback($root.refIds.get(ref), OPERATION.DELETE, callback);
4614
4610
  };
4615
4611
  const onChange = function (ref, callback) {
4616
- console.log("REGISTER ON CHANGE ON", $root.refIds.get(ref));
4617
4612
  return $root.addCallback($root.refIds.get(ref), OPERATION.REPLACE, callback);
4618
4613
  };
4619
4614
  return new Proxy({