From b5b8fb1e3c7f32607540729cccb2531cbd1dfec1 Mon Sep 17 00:00:00 2001 From: Jan-Stefan Janetzky Date: Sat, 6 Jul 2019 14:21:03 +0200 Subject: [PATCH] use .classList.toggle instead of add / remove if toggle is undefined, `.toggle` will act as a flip flop (wich the name "toggle" should imply) if toggle is true, it will add the class unless it is already contained if toggle is false, it will remove the class unless it is already removed alternatively i'd probably suggest renaming it from toggle_class to something else. a toggle is a state aware flip flop by default. any objections? --- src/runtime/internal/dom.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index f65d07117c..b59a47547d 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -247,8 +247,8 @@ export function add_resize_listener(element, fn) { }; } -export function toggle_class(element, name, toggle) { - element.classList[toggle ? 'add' : 'remove'](name); +export function toggle_class(element: Node, name: string, toggle?: boolean) { + element.classList.toggle(name, toggle); } export function custom_event(type: string, detail?: T) {