@colyseus/schema 2.0.10 → 2.0.12
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 +16 -0
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +16 -0
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +16 -0
- package/lib/types/ArraySchema.js +8 -0
- package/lib/types/ArraySchema.js.map +1 -1
- package/lib/types/MapSchema.js +8 -0
- package/lib/types/MapSchema.js.map +1 -1
- package/package.json +2 -1
- package/src/types/ArraySchema.ts +10 -0
- package/src/types/MapSchema.ts +11 -0
package/build/cjs/index.js
CHANGED
|
@@ -472,6 +472,14 @@ var ArraySchema = /** @class */ (function () {
|
|
|
472
472
|
};
|
|
473
473
|
ArraySchema.prototype.setAt = function (index, value) {
|
|
474
474
|
var _a, _b;
|
|
475
|
+
if (value === undefined || value === null) {
|
|
476
|
+
console.error("ArraySchema items cannot be null nor undefined; Use `deleteAt(index)` instead.");
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
// skip if the value is the same as cached.
|
|
480
|
+
if (this.$items.get(index) === value) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
475
483
|
if (value['$changes'] !== undefined) {
|
|
476
484
|
value['$changes'].setParent(this, this.$changes.root, index);
|
|
477
485
|
}
|
|
@@ -939,6 +947,9 @@ var MapSchema = /** @class */ (function () {
|
|
|
939
947
|
if (value === undefined || value === null) {
|
|
940
948
|
throw new Error("MapSchema#set('".concat(key, "', ").concat(value, "): trying to set ").concat(value, " value on '").concat(key, "'."));
|
|
941
949
|
}
|
|
950
|
+
// Force "key" as string
|
|
951
|
+
// See: https://github.com/colyseus/colyseus/issues/561#issuecomment-1646733468
|
|
952
|
+
key = key.toString();
|
|
942
953
|
// get "index" for this value.
|
|
943
954
|
var hasIndex = typeof (this.$changes.indexes[key]) !== "undefined";
|
|
944
955
|
var index = (hasIndex)
|
|
@@ -959,6 +970,11 @@ var MapSchema = /** @class */ (function () {
|
|
|
959
970
|
this.$changes.indexes[key] = index;
|
|
960
971
|
this.$indexes.set(index, key);
|
|
961
972
|
}
|
|
973
|
+
else if (!isRef &&
|
|
974
|
+
this.$items.get(key) === value) {
|
|
975
|
+
// if value is the same, avoid re-encoding it.
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
962
978
|
else if (isRef && // if is schema, force ADD operation if value differ from previous one.
|
|
963
979
|
this.$items.get(key) !== value) {
|
|
964
980
|
operation = exports.OPERATION.ADD;
|