@colyseus/schema 4.0.11 → 4.0.13

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colyseus/schema",
3
- "version": "4.0.11",
3
+ "version": "4.0.13",
4
4
  "description": "Binary state serializer with delta encoding for games",
5
5
  "type": "module",
6
6
  "bin": {
@@ -40,7 +40,12 @@ export class ReferenceTracker {
40
40
  // for decoding
41
41
  addRef(refId: number, ref: IRef, incrementCount: boolean = true) {
42
42
  this.refs.set(refId, ref);
43
- ref[$refId] = refId;
43
+
44
+ Object.defineProperty(ref, $refId, {
45
+ value: refId,
46
+ enumerable: false,
47
+ writable: true
48
+ });
44
49
 
45
50
  if (incrementCount) {
46
51
  this.refCount[refId] = (this.refCount[refId] || 0) + 1;
@@ -86,15 +86,19 @@ export class StateCallbackStrategy<TState extends IRef> {
86
86
 
87
87
  // Collection not available yet. Listen for its availability before attaching the handler.
88
88
  if (!collection || collection[$refId] === undefined) {
89
- removeHandler = this.addCallback(
89
+ let removePropertyCallback: () => void;
90
+ removePropertyCallback = this.addCallback(
90
91
  instance[$refId],
91
92
  propertyName,
92
93
  (value: TReturn, _: TReturn) => {
93
94
  if (value !== null && value !== undefined) {
95
+ // Remove the property listener now that collection is available
96
+ removePropertyCallback();
94
97
  removeHandler = this.addCallback(value[$refId], operation, handler);
95
98
  }
96
99
  }
97
100
  );
101
+ removeHandler = removePropertyCallback;
98
102
  return removeOnAdd;
99
103
 
100
104
  } else {
@@ -28,7 +28,11 @@ export class Root {
28
28
 
29
29
  // Assign unique `refId` to ref if it doesn't have one yet.
30
30
  if (ref[$refId] === undefined) {
31
- ref[$refId] = this.getNextUniqueId();
31
+ Object.defineProperty(ref, $refId, {
32
+ value: this.getNextUniqueId(),
33
+ enumerable: false,
34
+ writable: true
35
+ });
32
36
  }
33
37
 
34
38
  const refId = ref[$refId];