singult
singult copied to clipboard
Merge should remove stale attributes and inline styles
Currently merge only projects attributes from hiccup to the DOM---that'll overwrite any existing attributes, but it doesn't clear out attributes that aren't in the Hiccup representation.
I'm actually relying on this not happening. For example, a "selected" component (via class name) will stay selected even after some filter is applied. I can see how removing would be closer to the idea of merging though. I guess the trade-off is keeping an extra state variable around that tracks the state of any elements of interest.
We're in the same boat on several applications. Occasionally it is nice to go "out of band" to twiddle an individual class on or off via a direct element reference rather than go through Singult to walk the entire DOM. This is especially useful with performance on mobile devices. However, the contract of Singult is "the DOM should look like this Hiccup", so I'm of the mind to consider it a bug. That said, development of Singult is on hold at the moment while I look into more fruitful CLJS <-> DOM manipulation architectures, so don't worry about the behavior changing anytime soon.
For anyone reading this and disparing for a way to remove attributes with merge, setting an attribute to nil will cause singult to remove it from the dom.
e.g. (using c2's bind)
(bind! [:input :disabled (if @enabled nil true)])
will result in the disabled attribute being added and removed appropriate when the 'enabled' atom changes.