@colyseus/schema 3.0.23 → 3.0.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.
- package/build/cjs/index.js +14 -2
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +14 -2
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +14 -2
- package/lib/encoder/StateView.js +14 -2
- package/lib/encoder/StateView.js.map +1 -1
- package/package.json +1 -1
- package/src/encoder/StateView.ts +18 -2
package/build/cjs/index.js
CHANGED
|
@@ -4734,13 +4734,25 @@ class StateView {
|
|
|
4734
4734
|
}
|
|
4735
4735
|
// TODO: allow to set multiple tags at once
|
|
4736
4736
|
add(obj, tag = DEFAULT_VIEW_TAG, checkIncludeParent = true) {
|
|
4737
|
-
|
|
4737
|
+
const changeTree = obj?.[$changes];
|
|
4738
|
+
if (!changeTree) {
|
|
4738
4739
|
console.warn("StateView#add(), invalid object:", obj);
|
|
4739
4740
|
return this;
|
|
4740
4741
|
}
|
|
4742
|
+
else if (!changeTree.parent &&
|
|
4743
|
+
changeTree.refId !== 0 // allow root object
|
|
4744
|
+
) {
|
|
4745
|
+
/**
|
|
4746
|
+
* TODO: can we avoid this?
|
|
4747
|
+
*
|
|
4748
|
+
* When the "parent" structure has the @view() tag, it is currently
|
|
4749
|
+
* not possible to identify it has to be added to the view as well
|
|
4750
|
+
* (this.addParentOf() is not called).
|
|
4751
|
+
*/
|
|
4752
|
+
throw new Error(`Cannot add a detached instance to the StateView. Make sure to assign the "${changeTree.ref.constructor.name}" instance to the state before calling view.add()`);
|
|
4753
|
+
}
|
|
4741
4754
|
// FIXME: ArraySchema/MapSchema do not have metadata
|
|
4742
4755
|
const metadata = obj.constructor[Symbol.metadata];
|
|
4743
|
-
const changeTree = obj[$changes];
|
|
4744
4756
|
this.visible.add(changeTree);
|
|
4745
4757
|
// add to iterable list (only the explicitly added items)
|
|
4746
4758
|
if (this.iterable && checkIncludeParent) {
|