@colyseus/schema 5.0.0 → 5.0.1

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.
@@ -24,7 +24,31 @@ var OPERATION;
24
24
  OPERATION[OPERATION["ADD_BY_REFID"] = 129] = "ADD_BY_REFID";
25
25
  })(OPERATION || (OPERATION = {}));
26
26
 
27
- const $refId = Symbol("$refId");
27
+ const _g = (function () {
28
+ if (typeof globalThis !== "undefined")
29
+ return globalThis;
30
+ if (typeof global !== "undefined")
31
+ return global;
32
+ if (typeof self !== "undefined")
33
+ return self;
34
+ if (typeof window !== "undefined")
35
+ return window;
36
+ return {};
37
+ })();
38
+ if (typeof Symbol === "function" && typeof Symbol.for !== "function") {
39
+ const REGISTRY_KEY = "colyseus.symbolRegistry";
40
+ const registry = _g[REGISTRY_KEY] || (_g[REGISTRY_KEY] = Object.create(null));
41
+ Symbol.for = function (key) {
42
+ return registry[key] || (registry[key] = Symbol(key));
43
+ };
44
+ Symbol.keyFor = function (sym) {
45
+ for (const k in registry)
46
+ if (registry[k] === sym)
47
+ return k;
48
+ return undefined;
49
+ };
50
+ }
51
+ const $refId = Symbol.for("$refId");
28
52
  const $track = "~track";
29
53
  const $encoder = "~encoder";
30
54
  const $decoder = "~decoder";
@@ -36,12 +60,12 @@ const $deleteByIndex = "~deleteByIndex";
36
60
  *
37
61
  * Real JS Symbol — see the `$values` comment for rationale.
38
62
  */
39
- const $changes = Symbol("$changes");
63
+ const $changes = Symbol.for("$changes");
40
64
  /**
41
65
  * Used to keep track of the type of the child elements of a collection
42
66
  * (MapSchema, ArraySchema, etc.). Real Symbol — same rationale as $values.
43
67
  */
44
- const $childType = Symbol("$childType");
68
+ const $childType = Symbol.for("$childType");
45
69
  /**
46
70
  * Self-reference an instance sets on `this` so its own methods can recover
47
71
  * the underlying object even when `this` is a Proxy wrapper. Used by
@@ -49,7 +73,7 @@ const $childType = Symbol("$childType");
49
73
  * once at the top of hot methods and then access fields directly without
50
74
  * paying the Proxy.get cost on every read.
51
75
  */
52
- const $proxyTarget = Symbol("$proxyTarget");
76
+ const $proxyTarget = Symbol.for("$proxyTarget");
53
77
  /**
54
78
  * Optional "discard" method for custom types (ArraySchema)
55
79
  * (Discards changes for next serialization)
@@ -68,7 +92,7 @@ const $onDecodeEnd = "~onDecodeEnd";
68
92
  * which means we can drop Object.defineProperty(...{ enumerable: false })
69
93
  * and avoid the slow-path / dictionary-mode hazards that come with it.
70
94
  */
71
- const $values = Symbol("$values");
95
+ const $values = Symbol.for("$values");
72
96
  /**
73
97
  * Metadata
74
98
  */