@colyseus/schema 3.0.0-alpha.12 → 3.0.0-alpha.14
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 +29 -26
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +29 -26
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +29 -26
- package/lib/decoder/strategy/StateCallbacks.d.ts +35 -1
- package/lib/decoder/strategy/StateCallbacks.js +29 -26
- package/lib/decoder/strategy/StateCallbacks.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/decoder/strategy/StateCallbacks.ts +82 -28
- package/src/index.ts +1 -1
package/build/cjs/index.js
CHANGED
|
@@ -3992,29 +3992,26 @@ function getStateCallbacks(decoder) {
|
|
|
3992
3992
|
// Handle schema instance
|
|
3993
3993
|
//
|
|
3994
3994
|
if (!uniqueRefIds.has(refId)) {
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
}
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
console.error(e);
|
|
3995
|
+
// trigger onChange
|
|
3996
|
+
const replaceCallbacks = $callbacks?.[exports.OPERATION.REPLACE];
|
|
3997
|
+
for (let i = replaceCallbacks?.length - 1; i >= 0; i--) {
|
|
3998
|
+
replaceCallbacks[i]();
|
|
3999
|
+
// try {
|
|
4000
|
+
// } catch (e) {
|
|
4001
|
+
// console.error(e);
|
|
4002
|
+
// }
|
|
4004
4003
|
}
|
|
4005
4004
|
}
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
}
|
|
4005
|
+
if ($callbacks.hasOwnProperty(change.field)) {
|
|
4006
|
+
const fieldCallbacks = $callbacks[change.field];
|
|
4007
|
+
for (let i = fieldCallbacks?.length - 1; i >= 0; i--) {
|
|
4008
|
+
fieldCallbacks[i](change.value, change.previousValue);
|
|
4009
|
+
// try {
|
|
4010
|
+
// } catch (e) {
|
|
4011
|
+
// console.error(e);
|
|
4012
|
+
// }
|
|
4012
4013
|
}
|
|
4013
4014
|
}
|
|
4014
|
-
catch (e) {
|
|
4015
|
-
//
|
|
4016
|
-
console.error(e);
|
|
4017
|
-
}
|
|
4018
4015
|
}
|
|
4019
4016
|
else {
|
|
4020
4017
|
//
|
|
@@ -4092,12 +4089,15 @@ function getStateCallbacks(decoder) {
|
|
|
4092
4089
|
return $root.addCallback($root.refIds.get(context.instance), exports.OPERATION.REPLACE, callback);
|
|
4093
4090
|
},
|
|
4094
4091
|
bindTo: function bindTo(targetObject, properties) {
|
|
4095
|
-
//
|
|
4096
|
-
//
|
|
4097
|
-
//
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4092
|
+
//
|
|
4093
|
+
// TODO: refactor this implementation. There is room for improvement here.
|
|
4094
|
+
//
|
|
4095
|
+
if (!properties) {
|
|
4096
|
+
properties = Object.keys(metadata);
|
|
4097
|
+
}
|
|
4098
|
+
return $root.addCallback($root.refIds.get(context.instance), exports.OPERATION.REPLACE, () => {
|
|
4099
|
+
properties.forEach((prop) => targetObject[prop] = context.instance[prop]);
|
|
4100
|
+
});
|
|
4101
4101
|
}
|
|
4102
4102
|
}, {
|
|
4103
4103
|
get(target, prop) {
|
|
@@ -4188,7 +4188,10 @@ function getStateCallbacks(decoder) {
|
|
|
4188
4188
|
function $(instance) {
|
|
4189
4189
|
return getProxy(undefined, { instance });
|
|
4190
4190
|
}
|
|
4191
|
-
return
|
|
4191
|
+
return {
|
|
4192
|
+
$,
|
|
4193
|
+
$state: $(decoder.state),
|
|
4194
|
+
};
|
|
4192
4195
|
}
|
|
4193
4196
|
|
|
4194
4197
|
function getRawChangesCallback(decoder, callback) {
|