dom-add-class/remove-class: handle list-of-elements targets
'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.
This commit is contained in:
@@ -261,12 +261,28 @@
|
|||||||
dom-add-class
|
dom-add-class
|
||||||
(fn
|
(fn
|
||||||
(el cls)
|
(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
|
(define
|
||||||
dom-remove-class
|
dom-remove-class
|
||||||
(fn
|
(fn
|
||||||
(el cls)
|
(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
|
(define
|
||||||
dom-has-class?
|
dom-has-class?
|
||||||
(fn
|
(fn
|
||||||
|
|||||||
Reference in New Issue
Block a user