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