@colyseus/schema 3.0.0-alpha.22 → 3.0.0-alpha.24

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.
@@ -3508,7 +3508,11 @@ class Encoder {
3508
3508
  }
3509
3509
  if (it.offset > buffer.byteLength) {
3510
3510
  const newSize = getNextPowerOf2(buffer.byteLength * 2);
3511
- console.warn("@colyseus/schema encode buffer overflow. Current buffer size: " + buffer.byteLength + ", encoding offset: " + it.offset + ", new size: " + newSize);
3511
+ console.warn(`@colyseus/schema buffer overflow. Encoded state is higher than default BUFFER_SIZE. Use the following to increase default BUFFER_SIZE:
3512
+
3513
+ import { Encoder } from "@colyseus/schema";
3514
+ Encoder.BUFFER_SIZE = ${Math.round(newSize / 1024)} * 1024; // ${Math.round(newSize / 1024)} KB
3515
+ `);
3512
3516
  //
3513
3517
  // resize buffer and re-encode (TODO: can we avoid re-encoding here?)
3514
3518
  //
@@ -4140,7 +4144,11 @@ function getDecoderStateCallbacks(decoder) {
4140
4144
  }
4141
4145
  else {
4142
4146
  // collection instance not received yet
4143
- context.onInstanceAvailable((ref, existing) => onAdd(ref, prop, callback, immediate && existing));
4147
+ let detachCallback = () => { };
4148
+ context.onInstanceAvailable((ref, existing) => {
4149
+ detachCallback = onAdd(ref, prop, callback, immediate && existing);
4150
+ });
4151
+ return () => detachCallback();
4144
4152
  }
4145
4153
  },
4146
4154
  onChange: function onChange(callback) {
@@ -4215,19 +4223,27 @@ function getDecoderStateCallbacks(decoder) {
4215
4223
  //
4216
4224
  if (context.onInstanceAvailable) {
4217
4225
  // collection instance not received yet
4218
- context.onInstanceAvailable((ref, existing) => onAdd(ref, callback, immediate && existing && !isTriggeringOnAdd));
4226
+ let detachCallback = () => { };
4227
+ context.onInstanceAvailable((ref, existing) => {
4228
+ detachCallback = onAdd(ref, callback, immediate && existing && !isTriggeringOnAdd);
4229
+ });
4230
+ return () => detachCallback();
4219
4231
  }
4220
4232
  else if (context.instance) {
4221
- onAdd(context.instance, callback, immediate && !isTriggeringOnAdd);
4233
+ return onAdd(context.instance, callback, immediate && !isTriggeringOnAdd);
4222
4234
  }
4223
4235
  },
4224
4236
  onRemove: function (callback) {
4225
4237
  if (context.onInstanceAvailable) {
4226
4238
  // collection instance not received yet
4227
- context.onInstanceAvailable((ref) => onRemove(ref, callback));
4239
+ let detachCallback = () => { };
4240
+ context.onInstanceAvailable((ref) => {
4241
+ detachCallback = onRemove(ref, callback);
4242
+ });
4243
+ return () => detachCallback();
4228
4244
  }
4229
4245
  else if (context.instance) {
4230
- onRemove(context.instance, callback);
4246
+ return onRemove(context.instance, callback);
4231
4247
  }
4232
4248
  },
4233
4249
  }, {