|
1 | 1 | import { BoundOrRaw, ComponentBinds, documentBinders, getComponentBinders, rawBind, windowBinders } from "./bind"; |
2 | 2 | import { EventHandler, toConfiguredListener } from "./event"; |
3 | | -import { Actions, Attributes, BodyProxyProps, Classes, DocumentProxyProps, Handlers, Props, Reactive, Stringifiable, Styles, Tag, WindowProxyProps } from "./props"; |
| 3 | +import { Actions, Attributes, BodyProxyProps, Classes, DocumentProxyProps, Handlers, LiteralOrStore, Props, Reactive, Stringifiable, Styles, Tag, WindowProxyProps } from "./props"; |
4 | 4 | import { ReactiveString } from "./reactive_string"; |
5 | 5 | import { Child, Disposable, Renderable } from "./renderable"; |
6 | 6 | import { $derive, AtomStore, Store, StoredTypes, ValueCallback } from "./store"; |
@@ -293,25 +293,16 @@ function attachClass(element: HTMLElement, className?: Classes) { |
293 | 293 | element.classList.remove(c); |
294 | 294 | }); |
295 | 295 | } else { |
296 | | - const prev: Record<string, boolean> = previous ?? {}; |
297 | 296 | Object.entries(next).forEach(([clazz, enabled]) => { |
298 | | - if (enabled) { |
299 | | - if (!prev[clazz]) { |
300 | | - element.classList.add(clazz); |
301 | | - } else { |
302 | | - delete prev[clazz]; |
303 | | - } |
304 | | - } else { |
305 | | - if (prev[clazz]) { |
| 297 | + const dispose = watchProp(enabled, (isEnabled, wasEnabled) => { |
| 298 | + if (wasEnabled && !isEnabled) { |
306 | 299 | element.classList.remove(clazz); |
307 | | - } else { |
308 | | - delete prev[clazz]; |
| 300 | + } else if (isEnabled && !wasEnabled) { |
| 301 | + element.classList.add(clazz); |
309 | 302 | } |
310 | | - } |
311 | | - }); |
312 | | - Object.entries(prev).forEach(([clazz, enabled]) => { |
313 | | - if (enabled) { |
314 | | - element.classList.remove(clazz); |
| 303 | + }); |
| 304 | + if (dispose) { |
| 305 | + disposables.push(dispose); |
315 | 306 | } |
316 | 307 | }); |
317 | 308 | } |
|
0 commit comments