@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/esm/index.mjs
CHANGED
|
@@ -2682,6 +2682,10 @@ class MapSchema {
|
|
|
2682
2682
|
registerType("map", { constructor: MapSchema });
|
|
2683
2683
|
|
|
2684
2684
|
const DEFAULT_VIEW_TAG = -1;
|
|
2685
|
+
function entity(constructor) {
|
|
2686
|
+
TypeContext.register(constructor);
|
|
2687
|
+
return constructor;
|
|
2688
|
+
}
|
|
2685
2689
|
/**
|
|
2686
2690
|
* [See documentation](https://docs.colyseus.io/state/schema/)
|
|
2687
2691
|
*
|
|
@@ -4412,6 +4416,7 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4412
4416
|
const onAddCalls = new WeakMap();
|
|
4413
4417
|
let currentOnAddCallback;
|
|
4414
4418
|
decoder.triggerChanges = function (allChanges) {
|
|
4419
|
+
// console.log("ALL CHANGES =>", allChanges);
|
|
4415
4420
|
const uniqueRefIds = new Set();
|
|
4416
4421
|
for (let i = 0, l = allChanges.length; i < l; i++) {
|
|
4417
4422
|
const change = allChanges[i];
|
|
@@ -4554,7 +4559,9 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4554
4559
|
if (metadataField) {
|
|
4555
4560
|
const instance = context.instance?.[prop];
|
|
4556
4561
|
const onInstanceAvailable = ((callback) => {
|
|
4562
|
+
console.log("onInstanceAvailable!!");
|
|
4557
4563
|
const unbind = $(context.instance).listen(prop, (value, _) => {
|
|
4564
|
+
console.log("prop changed!", prop);
|
|
4558
4565
|
callback(value, false);
|
|
4559
4566
|
// FIXME: by "unbinding" the callback here,
|
|
4560
4567
|
// it will not support when the server
|
|
@@ -4602,9 +4609,11 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4602
4609
|
});
|
|
4603
4610
|
};
|
|
4604
4611
|
const onRemove = function (ref, callback) {
|
|
4612
|
+
console.log("REGISTER ON REMOVE ON", $root.refIds.get(ref));
|
|
4605
4613
|
return $root.addCallback($root.refIds.get(ref), OPERATION.DELETE, callback);
|
|
4606
4614
|
};
|
|
4607
4615
|
const onChange = function (ref, callback) {
|
|
4616
|
+
console.log("REGISTER ON CHANGE ON", $root.refIds.get(ref));
|
|
4608
4617
|
return $root.addCallback($root.refIds.get(ref), OPERATION.REPLACE, callback);
|
|
4609
4618
|
};
|
|
4610
4619
|
return new Proxy({
|
|
@@ -4626,7 +4635,10 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4626
4635
|
}
|
|
4627
4636
|
},
|
|
4628
4637
|
onRemove: function (callback) {
|
|
4629
|
-
if (context.
|
|
4638
|
+
if (context.instance) {
|
|
4639
|
+
return onRemove(context.instance, callback);
|
|
4640
|
+
}
|
|
4641
|
+
else if (context.onInstanceAvailable) {
|
|
4630
4642
|
// collection instance not received yet
|
|
4631
4643
|
let detachCallback = () => { };
|
|
4632
4644
|
context.onInstanceAvailable((ref) => {
|
|
@@ -4634,12 +4646,12 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4634
4646
|
});
|
|
4635
4647
|
return () => detachCallback();
|
|
4636
4648
|
}
|
|
4637
|
-
else if (context.instance) {
|
|
4638
|
-
return onRemove(context.instance, callback);
|
|
4639
|
-
}
|
|
4640
4649
|
},
|
|
4641
4650
|
onChange: function (callback) {
|
|
4642
|
-
if (context.
|
|
4651
|
+
if (context.instance) {
|
|
4652
|
+
return onChange(context.instance, callback);
|
|
4653
|
+
}
|
|
4654
|
+
else if (context.onInstanceAvailable) {
|
|
4643
4655
|
// collection instance not received yet
|
|
4644
4656
|
let detachCallback = () => { };
|
|
4645
4657
|
context.onInstanceAvailable((ref) => {
|
|
@@ -4647,9 +4659,6 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4647
4659
|
});
|
|
4648
4660
|
return () => detachCallback();
|
|
4649
4661
|
}
|
|
4650
|
-
else if (context.instance) {
|
|
4651
|
-
return onChange(context.instance, callback);
|
|
4652
|
-
}
|
|
4653
4662
|
},
|
|
4654
4663
|
}, {
|
|
4655
4664
|
get(target, prop) {
|
|
@@ -4864,5 +4873,5 @@ registerType("array", { constructor: ArraySchema });
|
|
|
4864
4873
|
registerType("set", { constructor: SetSchema });
|
|
4865
4874
|
registerType("collection", { constructor: CollectionSchema, });
|
|
4866
4875
|
|
|
4867
|
-
export { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $track, ArraySchema, ChangeTree, CollectionSchema, Decoder, Encoder, MapSchema, Metadata, OPERATION, Reflection, ReflectionField, ReflectionType, Schema, SetSchema, StateView, TypeContext, decode, decodeKeyValueOperation, decodeSchemaOperation, defineCustomTypes, defineTypes, deprecated, dumpChanges, encode, encodeArray as encodeKeyValueOperation, encodeSchemaOperation, getDecoderStateCallbacks, getRawChangesCallback, registerType, schema, type, view };
|
|
4876
|
+
export { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $track, ArraySchema, ChangeTree, CollectionSchema, Decoder, Encoder, MapSchema, Metadata, OPERATION, Reflection, ReflectionField, ReflectionType, Schema, SetSchema, StateView, TypeContext, decode, decodeKeyValueOperation, decodeSchemaOperation, defineCustomTypes, defineTypes, deprecated, dumpChanges, encode, encodeArray as encodeKeyValueOperation, encodeSchemaOperation, entity, getDecoderStateCallbacks, getRawChangesCallback, registerType, schema, type, view };
|
|
4868
4877
|
//# sourceMappingURL=index.mjs.map
|