Skip to content

fix(perf): use if in toggle_class instead of dynamic property access shenanigans #8631

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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 5 additions & 1 deletion src/runtime/internal/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,11 @@ export const resize_observer_device_pixel_content_box = /* @__PURE__ */ new Resi
export { ResizeObserverSingleton };

export function toggle_class(element, name, toggle) {
element.classList[toggle ? 'add' : 'remove'](name);
if (toggle) {
element.classList.add(name);
} else {
element.classList.remove(name);
}
}

export function custom_event<T = any>(type: string, detail?: T, { bubbles = false, cancelable = false } = {}): CustomEvent<T> {
Expand Down