@directivegames/genesys.js 3.1.26 → 3.1.28

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.
@@ -62,6 +62,53 @@ type CtorArgProperty = {
62
62
  metadata?: PropertyMetadata;
63
63
  }
64
64
 
65
+ function deepishEqual(a: any, b: any, maxDepth = 3): boolean {
66
+ function eq(a: any, b: any, depth: number, maxDepth: number): boolean {
67
+ if (depth > maxDepth) {
68
+ // If we *reach* depth limit, treat as different
69
+ return false;
70
+ }
71
+
72
+ // Fast path: identity or strict equality
73
+ if (a === b) return true;
74
+
75
+ // Handle case where types differ
76
+ if (typeof a !== typeof b) return false;
77
+
78
+ // if both functions, consider them equal
79
+ if (typeof a === 'function' && typeof b === 'function') {
80
+ return true;
81
+ }
82
+
83
+ // Handle primitives
84
+ if (a === null || b === null || typeof a !== 'object') return false;
85
+
86
+ // Arrays
87
+ if (Array.isArray(a) !== Array.isArray(b)) return false;
88
+ if (Array.isArray(a)) {
89
+ if (a.length !== b.length) return false;
90
+ for (let i = 0; i < a.length; i++) {
91
+ if (!eq(a[i], b[i], depth + 1, maxDepth)) return false;
92
+ }
93
+ return true;
94
+ }
95
+
96
+ // Objects
97
+ const aKeys = Object.keys(a);
98
+ const bKeys = Object.keys(b);
99
+ if (aKeys.length !== bKeys.length) return false;
100
+
101
+ for (const key of aKeys) {
102
+ if (!(key in b)) return false;
103
+ if (!eq(a[key], b[key], depth + 1, maxDepth)) return false;
104
+ }
105
+
106
+ return true;
107
+ }
108
+
109
+ return eq(a, b, 0, maxDepth);
110
+ }
111
+
65
112
 
66
113
  /**
67
114
  * The serialized data will either be $root + $objects, or $prefab + $diff
@@ -206,6 +253,8 @@ export class Dumper extends Serializer {
206
253
  throw new Error('Dumper instances cannot be reused.');
207
254
  }
208
255
 
256
+ const startTime = performance.now();
257
+
209
258
  let realPrefabPath: any;
210
259
  if (this.hasFlags(DumperFlags.Inline) && obj.$prefab) {
211
260
  // modify existing prefab to its parent
@@ -245,6 +294,8 @@ export class Dumper extends Serializer {
245
294
  if (realPrefabPath) {
246
295
  obj.$prefab = realPrefabPath;
247
296
  }
297
+ const endTime = performance.now();
298
+ console.log(`📦Dumper: Dumping took time ${(endTime - startTime).toFixed(2)}ms`);
248
299
  }
249
300
  }
250
301
 
@@ -410,11 +461,11 @@ export class Dumper extends Serializer {
410
461
  return DumpValueResult.SkippedEqualToDefaultValue;
411
462
  }
412
463
  } else {
413
- // object type, do a deep comparison
464
+ // object type, do a deep-ish comparison
414
465
  if (
415
466
  defaultValue
416
467
  && Object.getPrototypeOf(value) === Object.getPrototypeOf(defaultValue)
417
- && JSON.stringify(value) === JSON.stringify(defaultValue)
468
+ && deepishEqual(value, defaultValue, 3)
418
469
  ) {
419
470
  return DumpValueResult.SkippedEqualToDefaultValue;
420
471
  }
@@ -670,7 +721,7 @@ export class Loader extends Serializer {
670
721
  this._prepareLoader(data);
671
722
  const result = this._load(data.$root, '$root', target);
672
723
  const endTime = performance.now();
673
- console.log(`Loader.loadToInstance execution time: ${endTime - startTime}ms`);
724
+ console.log(`📦Loader: Loading took time ${(endTime - startTime).toFixed(2)}ms`);
674
725
  return result;
675
726
  }
676
727
 
@@ -697,7 +748,7 @@ export class Loader extends Serializer {
697
748
 
698
749
  const result = this._load(data.$root, '$root', target);
699
750
  const endTime = performance.now();
700
- console.log(`Loader.loadToInstanceAsync execution time: ${endTime - startTime}ms`);
751
+ console.log(`📦Loader: Async loading took time ${(endTime - startTime).toFixed(2)}ms`);
701
752
  return result;
702
753
  }
703
754