-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add compatibility layer with previous MapSchema version. add deleteBy…
- Loading branch information
Showing
5 changed files
with
110 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,6 +236,10 @@ export abstract class Schema { | |
// | ||
// TODO: remove from $root.refs | ||
// | ||
console.log("DELETE OPERATION!", { | ||
ref, type, _field, fieldIndex, | ||
}); | ||
ref['deleteByIndex'](fieldIndex); | ||
|
||
value = null; | ||
hasChange = true; | ||
|
@@ -286,22 +290,35 @@ export abstract class Schema { | |
}); | ||
} | ||
|
||
if (value['$changes']) { | ||
value['$changes'].setParent( | ||
changeTree.ref, | ||
changeTree.root, | ||
fieldIndex, | ||
); | ||
} | ||
if (value) { | ||
if (value['$changes']) { | ||
value['$changes'].setParent( | ||
changeTree.ref, | ||
changeTree.root, | ||
fieldIndex, | ||
); | ||
} | ||
|
||
if (ref instanceof Schema) { | ||
ref[_field] = value; | ||
if (ref instanceof Schema) { | ||
ref[field] = value; | ||
|
||
} else if (ref instanceof MapSchema) { | ||
const key = ref['$indexes'].get(field); | ||
ref.set(key, value); | ||
// | ||
// FIXME: use `_field` instead of `field`. | ||
// | ||
// `field` is going to use the setter of the PropertyDescriptor | ||
// and create a proxy for array/map. This is only useful for | ||
// backwards-compatibility with @colyseus/[email protected] | ||
// | ||
// // ref[_field] = value; | ||
|
||
} else if (ref instanceof MapSchema) { | ||
const key = ref['$indexes'].get(field); | ||
ref.set(key, value); | ||
} | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
this._triggerChanges(changes); | ||
|
@@ -670,6 +687,10 @@ export abstract class Schema { | |
return this[this._fieldsByIndex[index]]; | ||
} | ||
|
||
protected deleteByIndex(index: number) { | ||
delete this[this._fieldsByIndex[index]]; | ||
} | ||
|
||
private tryEncodeTypeId (bytes: number[], type: typeof Schema, targetType: typeof Schema) { | ||
if (type._typeid !== targetType._typeid) { | ||
encode.uint8(bytes, TYPE_ID); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters