diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-08-29 12:05:02 -0600 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-08-29 12:05:02 -0600 |
commit | fd1bb1cca9521348ae2849ef30be09264503681e (patch) | |
tree | 6859c24c53fdd2a83ed0a92ee10272aa70b6c55d /engine/utils/coding.ts | |
parent | 8a4ab8d79b5ce1dabb431168398b5d5111fe326c (diff) | |
download | jumpstorm-fd1bb1cca9521348ae2849ef30be09264503681e.tar.gz jumpstorm-fd1bb1cca9521348ae2849ef30be09264503681e.zip |
don't update controllable entities on the client
Diffstat (limited to 'engine/utils/coding.ts')
-rw-r--r-- | engine/utils/coding.ts | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/engine/utils/coding.ts b/engine/utils/coding.ts index 3f78889..283844f 100644 --- a/engine/utils/coding.ts +++ b/engine/utils/coding.ts @@ -9,6 +9,18 @@ const replacer = (_key: any, value: any) => { } }; +const sortObj = (obj: any): any => + obj === null || typeof obj !== 'object' + ? obj + : Array.isArray(obj) + ? obj.map(sortObj) + : Object.assign( + {}, + ...Object.entries(obj) + .sort(([keyA], [keyB]) => keyA.localeCompare(keyB)) + .map(([k, v]) => ({ [k]: sortObj(v) })) + ); + const reviver = (_key: any, value: any) => { if (typeof value === 'object' && value !== null) { if (value.dataType === 'Map') { @@ -18,8 +30,9 @@ const reviver = (_key: any, value: any) => { return value; }; +// "deterministic" stringify export const stringify = (obj: any) => { - return JSON.stringify(obj, replacer); + return JSON.stringify(sortObj(obj), replacer); }; export const parse = <T>(str: string) => { |