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