@colyseus/schema 3.0.6 → 3.0.8
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 +18 -8
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +18 -9
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +18 -8
- package/lib/decoder/strategy/StateCallbacks.js +13 -8
- package/lib/decoder/strategy/StateCallbacks.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/decoder/strategy/StateCallbacks.ts +15 -8
- package/src/index.ts +1 -1
package/build/cjs/index.js
CHANGED
|
@@ -2684,6 +2684,10 @@ class MapSchema {
|
|
|
2684
2684
|
registerType("map", { constructor: MapSchema });
|
|
2685
2685
|
|
|
2686
2686
|
const DEFAULT_VIEW_TAG = -1;
|
|
2687
|
+
function entity(constructor) {
|
|
2688
|
+
TypeContext.register(constructor);
|
|
2689
|
+
return constructor;
|
|
2690
|
+
}
|
|
2687
2691
|
/**
|
|
2688
2692
|
* [See documentation](https://docs.colyseus.io/state/schema/)
|
|
2689
2693
|
*
|
|
@@ -4414,6 +4418,7 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4414
4418
|
const onAddCalls = new WeakMap();
|
|
4415
4419
|
let currentOnAddCallback;
|
|
4416
4420
|
decoder.triggerChanges = function (allChanges) {
|
|
4421
|
+
// console.log("ALL CHANGES =>", allChanges);
|
|
4417
4422
|
const uniqueRefIds = new Set();
|
|
4418
4423
|
for (let i = 0, l = allChanges.length; i < l; i++) {
|
|
4419
4424
|
const change = allChanges[i];
|
|
@@ -4556,7 +4561,9 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4556
4561
|
if (metadataField) {
|
|
4557
4562
|
const instance = context.instance?.[prop];
|
|
4558
4563
|
const onInstanceAvailable = ((callback) => {
|
|
4564
|
+
console.log("onInstanceAvailable!!");
|
|
4559
4565
|
const unbind = $(context.instance).listen(prop, (value, _) => {
|
|
4566
|
+
console.log("prop changed!", prop);
|
|
4560
4567
|
callback(value, false);
|
|
4561
4568
|
// FIXME: by "unbinding" the callback here,
|
|
4562
4569
|
// it will not support when the server
|
|
@@ -4604,9 +4611,11 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4604
4611
|
});
|
|
4605
4612
|
};
|
|
4606
4613
|
const onRemove = function (ref, callback) {
|
|
4614
|
+
console.log("REGISTER ON REMOVE ON", $root.refIds.get(ref));
|
|
4607
4615
|
return $root.addCallback($root.refIds.get(ref), exports.OPERATION.DELETE, callback);
|
|
4608
4616
|
};
|
|
4609
4617
|
const onChange = function (ref, callback) {
|
|
4618
|
+
console.log("REGISTER ON CHANGE ON", $root.refIds.get(ref));
|
|
4610
4619
|
return $root.addCallback($root.refIds.get(ref), exports.OPERATION.REPLACE, callback);
|
|
4611
4620
|
};
|
|
4612
4621
|
return new Proxy({
|
|
@@ -4628,7 +4637,10 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4628
4637
|
}
|
|
4629
4638
|
},
|
|
4630
4639
|
onRemove: function (callback) {
|
|
4631
|
-
if (context.
|
|
4640
|
+
if (context.instance) {
|
|
4641
|
+
return onRemove(context.instance, callback);
|
|
4642
|
+
}
|
|
4643
|
+
else if (context.onInstanceAvailable) {
|
|
4632
4644
|
// collection instance not received yet
|
|
4633
4645
|
let detachCallback = () => { };
|
|
4634
4646
|
context.onInstanceAvailable((ref) => {
|
|
@@ -4636,12 +4648,12 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4636
4648
|
});
|
|
4637
4649
|
return () => detachCallback();
|
|
4638
4650
|
}
|
|
4639
|
-
else if (context.instance) {
|
|
4640
|
-
return onRemove(context.instance, callback);
|
|
4641
|
-
}
|
|
4642
4651
|
},
|
|
4643
4652
|
onChange: function (callback) {
|
|
4644
|
-
if (context.
|
|
4653
|
+
if (context.instance) {
|
|
4654
|
+
return onChange(context.instance, callback);
|
|
4655
|
+
}
|
|
4656
|
+
else if (context.onInstanceAvailable) {
|
|
4645
4657
|
// collection instance not received yet
|
|
4646
4658
|
let detachCallback = () => { };
|
|
4647
4659
|
context.onInstanceAvailable((ref) => {
|
|
@@ -4649,9 +4661,6 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4649
4661
|
});
|
|
4650
4662
|
return () => detachCallback();
|
|
4651
4663
|
}
|
|
4652
|
-
else if (context.instance) {
|
|
4653
|
-
return onChange(context.instance, callback);
|
|
4654
|
-
}
|
|
4655
4664
|
},
|
|
4656
4665
|
}, {
|
|
4657
4666
|
get(target, prop) {
|
|
@@ -4898,6 +4907,7 @@ exports.dumpChanges = dumpChanges;
|
|
|
4898
4907
|
exports.encode = encode;
|
|
4899
4908
|
exports.encodeKeyValueOperation = encodeArray;
|
|
4900
4909
|
exports.encodeSchemaOperation = encodeSchemaOperation;
|
|
4910
|
+
exports.entity = entity;
|
|
4901
4911
|
exports.getDecoderStateCallbacks = getDecoderStateCallbacks;
|
|
4902
4912
|
exports.getRawChangesCallback = getRawChangesCallback;
|
|
4903
4913
|
exports.registerType = registerType;
|