From 2000607fe0ca69b80bed0c1e4d7f1407f8d958e5 Mon Sep 17 00:00:00 2001 From: Chris Lorenzo Date: Tue, 17 Sep 2024 10:22:52 -0400 Subject: [PATCH 1/2] compat: Remove fromEntries for older browser support --- .../text-rendering/renderers/TextRenderer.ts | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/core/text-rendering/renderers/TextRenderer.ts b/src/core/text-rendering/renderers/TextRenderer.ts index f0b47b3b..63d5430e 100644 --- a/src/core/text-rendering/renderers/TextRenderer.ts +++ b/src/core/text-rendering/renderers/TextRenderer.ts @@ -432,23 +432,22 @@ export abstract class TextRenderer< // For each prop setter add a wrapper method that checks if the prop is // different before calling the setter this.set = Object.freeze( - Object.fromEntries( - Object.entries(propSetters).map(([key, setter]) => { - return [ - key as keyof TrProps, - (state: StateT, value: TrProps[keyof TrProps]) => { - if (state.props[key as keyof TrProps] !== value) { - setter(state, value as never); - // Assume any prop change will require a render - // This is required because otherwise a paused RAF will result - // in renders when text props are changed. - this.stage.requestRender(); - } - }, - ]; - }), - ), - ) as typeof this.set; + Object.entries(propSetters).reduce((acc, [key, setter]) => { + acc[key as keyof TrProps] = ( + state: StateT, + value: TrProps[keyof TrProps], + ) => { + if (state.props[key as keyof TrProps] !== value) { + setter(state, value as never); + // Assume any prop change will require a render + // This is required because otherwise a paused RAF will result + // in renders when text props are changed. + this.stage.requestRender(); + } + }; + return acc; + }, {} as TrPropSetters), + ); } setStatus(state: StateT, status: StateT['status'], error?: Error) { From 00de9485e1b31d4f3484caca6c0509d2b2575e3e Mon Sep 17 00:00:00 2001 From: Chris Lorenzo Date: Sat, 21 Sep 2024 11:44:47 -0400 Subject: [PATCH 2/2] update from comments --- .../text-rendering/renderers/TextRenderer.ts | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/core/text-rendering/renderers/TextRenderer.ts b/src/core/text-rendering/renderers/TextRenderer.ts index 63d5430e..dd139cb3 100644 --- a/src/core/text-rendering/renderers/TextRenderer.ts +++ b/src/core/text-rendering/renderers/TextRenderer.ts @@ -431,23 +431,24 @@ export abstract class TextRenderer< }; // For each prop setter add a wrapper method that checks if the prop is // different before calling the setter - this.set = Object.freeze( - Object.entries(propSetters).reduce((acc, [key, setter]) => { - acc[key as keyof TrProps] = ( - state: StateT, - value: TrProps[keyof TrProps], - ) => { + const propSet = {}; + Object.keys(propSetters).forEach((key) => { + Object.defineProperty(propSet, key, { + value: (state: StateT, value: TrProps[keyof TrProps]) => { + // Check if the current prop value is different before calling the setter if (state.props[key as keyof TrProps] !== value) { - setter(state, value as never); + propSetters[key as keyof TrPropSetters](state, value as never); + // Assume any prop change will require a render - // This is required because otherwise a paused RAF will result - // in renders when text props are changed. + // This ensures that renders are triggered appropriately even with RAF paused this.stage.requestRender(); } - }; - return acc; - }, {} as TrPropSetters), - ); + }, + writable: false, // Prevents property from being changed + configurable: false, // Prevents property from being deleted + }); + }); + this.set = propSet as Readonly>; } setStatus(state: StateT, status: StateT['status'], error?: Error) {