@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.
@@ -3992,29 +3992,26 @@ function getStateCallbacks(decoder) {
3992
3992
  // Handle schema instance
3993
3993
  //
3994
3994
  if (!uniqueRefIds.has(refId)) {
3995
- try {
3996
- // trigger onChange
3997
- const replaceCallbacks = $callbacks?.[exports.OPERATION.REPLACE];
3998
- for (let i = replaceCallbacks?.length - 1; i >= 0; i--) {
3999
- replaceCallbacks[i]();
4000
- }
4001
- }
4002
- catch (e) {
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
- try {
4007
- if ($callbacks.hasOwnProperty(change.field)) {
4008
- const fieldCallbacks = $callbacks[change.field];
4009
- for (let i = fieldCallbacks?.length - 1; i >= 0; i--) {
4010
- fieldCallbacks[i](change.value, change.previousValue);
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
- // return $root.addCallback(
4096
- // $root.refIds.get(context.instance),
4097
- // OPERATION.BIND,
4098
- // callback
4099
- // );
4100
- console.log("bindTo", targetObject, properties);
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 $(decoder.state);
4191
+ return {
4192
+ $,
4193
+ $state: $(decoder.state),
4194
+ };
4192
4195
  }
4193
4196
 
4194
4197
  function getRawChangesCallback(decoder, callback) {