@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.
@@ -3988,29 +3988,26 @@ function getStateCallbacks(decoder) {
3988
3988
  // Handle schema instance
3989
3989
  //
3990
3990
  if (!uniqueRefIds.has(refId)) {
3991
- try {
3992
- // trigger onChange
3993
- const replaceCallbacks = $callbacks?.[OPERATION.REPLACE];
3994
- for (let i = replaceCallbacks?.length - 1; i >= 0; i--) {
3995
- replaceCallbacks[i]();
3996
- }
3997
- }
3998
- catch (e) {
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
- try {
4003
- if ($callbacks.hasOwnProperty(change.field)) {
4004
- const fieldCallbacks = $callbacks[change.field];
4005
- for (let i = fieldCallbacks?.length - 1; i >= 0; i--) {
4006
- fieldCallbacks[i](change.value, change.previousValue);
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
- // return $root.addCallback(
4092
- // $root.refIds.get(context.instance),
4093
- // OPERATION.BIND,
4094
- // callback
4095
- // );
4096
- console.log("bindTo", targetObject, properties);
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 $(decoder.state);
4187
+ return $;
4188
4188
  }
4189
4189
 
4190
4190
  function getRawChangesCallback(decoder, callback) {