MithrilJS / mithril.js

A JavaScript Framework for Building Brilliant Applications
https://mithril.js.org
MIT License
14.02k stars 926 forks source link

Make a first-class way for event handlers to be run without auto-redrawing. #378

Closed l-cornelius-dol closed 9 years ago

l-cornelius-dol commented 9 years ago

Allow a noredraw object for event handlers which aren't wrapped in redrawing, or iterate config applying any onxxx attributes in the same way.

Event handling is sufficiently tightly bound to a component that avoiding use of config is preferable, since, ideally, config should be reserved for unusual use-cases, not common ones.

Modify setAttributes to add the following code to the if/else setting attributes:

//handle `noredraw: {...}`
else if (attrName === "noredraw" && dataAttr != null && type.call(dataAttr) == OBJECT) {
    for (var rule in dataAttr) {
        node[attrName] = dataAttr[rule];
    }
}
philtoms commented 9 years ago

I don't know if this is slightly off topic but have you considered using an immutability library? The idea being that the view is only updated on state change. I did a small update to your fiddle here http://jsfiddle.net/philtoms/obd7q4ox/