@colyseus/schema 3.0.0-alpha.17 → 3.0.0-alpha.18

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.
@@ -144,6 +144,14 @@ const Metadata = {
144
144
  isDeprecated(metadata, field) {
145
145
  return metadata[field].deprecated === true;
146
146
  },
147
+ init(klass) {
148
+ //
149
+ // Used only to initialize an empty Schema (Encoder#constructor)
150
+ //
151
+ const metadata = {};
152
+ klass.constructor[Symbol.metadata] = metadata;
153
+ Object.defineProperty(metadata, -1, { value: 0, enumerable: false, configurable: true });
154
+ },
147
155
  isValidInstance(klass) {
148
156
  return (klass.constructor[Symbol.metadata] &&
149
157
  Object.prototype.hasOwnProperty.call(klass.constructor[Symbol.metadata], -1));
@@ -3412,6 +3420,10 @@ class Encoder {
3412
3420
  setRoot(state) {
3413
3421
  this.root = new Root();
3414
3422
  this.state = state;
3423
+ // Workaround to allow using an empty Schema.
3424
+ if (state.constructor[Symbol.metadata] === undefined) {
3425
+ Metadata.init(state);
3426
+ }
3415
3427
  state[$changes].setRoot(this.root);
3416
3428
  }
3417
3429
  encode(it = { offset: 0 }, view, buffer = this.sharedBuffer, changeTrees = this.root.changes, isEncodeAll = this.root.allChanges === changeTrees) {