Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compat: Remove fromEntries for older browser support #385

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/core/text-rendering/renderers/TextRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,24 +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.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;
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) {
propSetters[key as keyof TrPropSetters](state, value as never);

// Assume any prop change will require a render
// This ensures that renders are triggered appropriately even with RAF paused
this.stage.requestRender();
}
},
writable: false, // Prevents property from being changed
configurable: false, // Prevents property from being deleted
});
});
this.set = propSet as Readonly<TrPropSetters<StateT>>;
}

setStatus(state: StateT, status: StateT['status'], error?: Error) {
Expand Down
Loading