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