@colyseus/schema 3.0.2 → 3.0.3
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/README.md +8 -7
- package/build/cjs/index.js +21 -2
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +21 -2
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +21 -2
- package/lib/decoder/DecodeOperation.js +1 -1
- package/lib/decoder/DecodeOperation.js.map +1 -1
- package/lib/decoder/strategy/StateCallbacks.d.ts +9 -0
- package/lib/decoder/strategy/StateCallbacks.js +20 -1
- package/lib/decoder/strategy/StateCallbacks.js.map +1 -1
- package/package.json +1 -1
- package/src/decoder/DecodeOperation.ts +1 -1
- package/src/decoder/strategy/StateCallbacks.ts +35 -8
package/build/esm/index.mjs
CHANGED
|
@@ -1545,7 +1545,7 @@ function decodeValue(decoder, operation, ref, index, type, bytes, it, allChanges
|
|
|
1545
1545
|
// previousValue,
|
|
1546
1546
|
// });
|
|
1547
1547
|
}
|
|
1548
|
-
value =
|
|
1548
|
+
value = undefined;
|
|
1549
1549
|
}
|
|
1550
1550
|
if (operation === OPERATION.DELETE) ;
|
|
1551
1551
|
else if (Schema.is(type)) {
|
|
@@ -4483,7 +4483,10 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4483
4483
|
}
|
|
4484
4484
|
}
|
|
4485
4485
|
// trigger onChange
|
|
4486
|
-
if (change.value !== change.previousValue
|
|
4486
|
+
if (change.value !== change.previousValue &&
|
|
4487
|
+
// FIXME: see "should not encode item if added and removed at the same patch" test case.
|
|
4488
|
+
// some "ADD" + "DELETE" operations on same patch are being encoded as "DELETE"
|
|
4489
|
+
(change.value !== undefined || change.previousValue !== undefined)) {
|
|
4487
4490
|
const replaceCallbacks = $callbacks[OPERATION.REPLACE];
|
|
4488
4491
|
for (let i = replaceCallbacks?.length - 1; i >= 0; i--) {
|
|
4489
4492
|
replaceCallbacks[i](change.value, change.dynamicIndex ?? change.field);
|
|
@@ -4596,6 +4599,9 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4596
4599
|
const onRemove = function (ref, callback) {
|
|
4597
4600
|
return $root.addCallback($root.refIds.get(ref), OPERATION.DELETE, callback);
|
|
4598
4601
|
};
|
|
4602
|
+
const onChange = function (ref, callback) {
|
|
4603
|
+
return $root.addCallback($root.refIds.get(ref), OPERATION.REPLACE, callback);
|
|
4604
|
+
};
|
|
4599
4605
|
return new Proxy({
|
|
4600
4606
|
onAdd: function (callback, immediate = true) {
|
|
4601
4607
|
//
|
|
@@ -4627,6 +4633,19 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4627
4633
|
return onRemove(context.instance, callback);
|
|
4628
4634
|
}
|
|
4629
4635
|
},
|
|
4636
|
+
onChange: function (callback) {
|
|
4637
|
+
if (context.onInstanceAvailable) {
|
|
4638
|
+
// collection instance not received yet
|
|
4639
|
+
let detachCallback = () => { };
|
|
4640
|
+
context.onInstanceAvailable((ref) => {
|
|
4641
|
+
detachCallback = onChange(ref, callback);
|
|
4642
|
+
});
|
|
4643
|
+
return () => detachCallback();
|
|
4644
|
+
}
|
|
4645
|
+
else if (context.instance) {
|
|
4646
|
+
return onChange(context.instance, callback);
|
|
4647
|
+
}
|
|
4648
|
+
},
|
|
4630
4649
|
}, {
|
|
4631
4650
|
get(target, prop) {
|
|
4632
4651
|
if (!target[prop]) {
|