@colyseus/schema 3.0.0-alpha.31 → 3.0.0-alpha.33
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/build/cjs/index.js +41 -50
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +41 -50
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +41 -50
- package/lib/bench_encode.js +21 -40
- package/lib/bench_encode.js.map +1 -1
- package/lib/decoder/DecodeOperation.js +3 -1
- package/lib/decoder/DecodeOperation.js.map +1 -1
- package/lib/encoder/ChangeTree.js +0 -1
- package/lib/encoder/ChangeTree.js.map +1 -1
- package/lib/encoder/EncodeOperation.js +8 -38
- package/lib/encoder/EncodeOperation.js.map +1 -1
- package/lib/encoder/Encoder.js +8 -4
- package/lib/encoder/Encoder.js.map +1 -1
- package/lib/encoder/Root.d.ts +2 -2
- package/lib/encoder/Root.js +22 -6
- package/lib/encoder/Root.js.map +1 -1
- package/package.json +1 -1
- package/src/bench_encode.ts +21 -43
- package/src/decoder/DecodeOperation.ts +8 -1
- package/src/encoder/ChangeTree.ts +0 -2
- package/src/encoder/EncodeOperation.ts +5 -31
- package/src/encoder/Encoder.ts +10 -5
- package/src/encoder/Root.ts +28 -6
package/src/encoder/Root.ts
CHANGED
|
@@ -21,13 +21,33 @@ export class Root {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
add(changeTree: ChangeTree) {
|
|
24
|
-
const
|
|
25
|
-
|
|
24
|
+
const previousRefCount = this.refCount.get(changeTree);
|
|
25
|
+
|
|
26
|
+
if (previousRefCount === 0) {
|
|
27
|
+
//
|
|
28
|
+
// When a ChangeTree is re-added, it means that it was previously removed.
|
|
29
|
+
// We need to re-add all changes to the `changes` map.
|
|
30
|
+
//
|
|
31
|
+
changeTree.allChanges.forEach((operation, index) => {
|
|
32
|
+
changeTree.changes.set(index, operation);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const refCount = (previousRefCount || 0) + 1;
|
|
37
|
+
this.refCount.set(changeTree, refCount);
|
|
38
|
+
|
|
39
|
+
return refCount;
|
|
26
40
|
}
|
|
27
41
|
|
|
28
42
|
remove(changeTree: ChangeTree) {
|
|
29
|
-
const refCount = this.refCount.get(changeTree);
|
|
30
|
-
|
|
43
|
+
const refCount = (this.refCount.get(changeTree)) - 1;
|
|
44
|
+
|
|
45
|
+
if (refCount <= 0) {
|
|
46
|
+
//
|
|
47
|
+
// Only remove "root" reference if it's the last reference
|
|
48
|
+
//
|
|
49
|
+
changeTree.root = undefined;
|
|
50
|
+
|
|
31
51
|
this.allChanges.delete(changeTree);
|
|
32
52
|
this.changes.delete(changeTree);
|
|
33
53
|
|
|
@@ -36,13 +56,15 @@ export class Root {
|
|
|
36
56
|
this.filteredChanges.delete(changeTree);
|
|
37
57
|
}
|
|
38
58
|
|
|
39
|
-
this.refCount.
|
|
59
|
+
this.refCount.set(changeTree, 0);
|
|
40
60
|
|
|
41
61
|
} else {
|
|
42
|
-
this.refCount.set(changeTree, refCount
|
|
62
|
+
this.refCount.set(changeTree, refCount);
|
|
43
63
|
}
|
|
44
64
|
|
|
45
65
|
changeTree.forEachChild((child, _) => this.remove(child));
|
|
66
|
+
|
|
67
|
+
return refCount;
|
|
46
68
|
}
|
|
47
69
|
|
|
48
70
|
clear() {
|