From fd1bb1cca9521348ae2849ef30be09264503681e Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Tue, 29 Aug 2023 12:05:02 -0600 Subject: don't update controllable entities on the client --- engine/utils/coding.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'engine/utils') 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 = (str: string) => { -- cgit v1.2.3-70-g09d2