From f44a185230f3ee74a0b5acda5ce08a2a279d4ff7 Mon Sep 17 00:00:00 2001 From: giles Date: Thu, 23 Apr 2026 16:53:06 +0000 Subject: [PATCH] dom-add-class/remove-class: handle list-of-elements targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 'add .foo to my children' compiles to (dom-add-class (host-get me 'children') 'foo') where children is a list. Fanned out via for-each inside dom-add-class/dom-remove-class rather than calling .classList.add on the list itself. Net: add 10→13. --- shared/static/wasm/sx/dom.sx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/shared/static/wasm/sx/dom.sx b/shared/static/wasm/sx/dom.sx index 32849936..91de4888 100644 --- a/shared/static/wasm/sx/dom.sx +++ b/shared/static/wasm/sx/dom.sx @@ -261,12 +261,28 @@ dom-add-class (fn (el cls) - (when el (host-call (host-get el "classList") "add" cls)))) + (cond + ((nil? el) nil) + ((list? el) + (for-each + (fn + (x) + (when x (host-call (host-get x "classList") "add" cls))) + el)) + (true (host-call (host-get el "classList") "add" cls))))) (define dom-remove-class (fn (el cls) - (when el (host-call (host-get el "classList") "remove" cls)))) + (cond + ((nil? el) nil) + ((list? el) + (for-each + (fn + (x) + (when x (host-call (host-get x "classList") "remove" cls))) + el)) + (true (host-call (host-get el "classList") "remove" cls))))) (define dom-has-class? (fn