Add a special vnode that allows manipulating attributes on a raw event target reference #2921
dead-claudia
started this conversation in
Ideas
Replies: 2 comments
-
what about just |
Beta Was this translation helpful? Give feedback.
0 replies
-
I considered that, but I was hoping to avoid discussions on how children should be added/removed from existing nodes that are already live with potential children. Edit: I would be okay with opening up that prospect, though. (I could see React Helmet-like use cases for one. I could also see the value of adding inline style sheets linked to components, in effect using Mithril as a resource loader.) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Mithril version:
Platform and OS:
Project:
Is this something you're interested in implementing yourself? Yes
Description
We should add a special primitive, say
m.link(value, {...})
, that lets us simply set attributes on the element. Examples:m.link(window, {onscroll() { ... }})
for scrollm.link(document, {onmouseup() { ... }, onmousemove() { ... }})
for drag and dropm.link(document, {title: ...})
m.link(window, {scrollX, scrollY})
The event handlers would of course autoredraw as existing Mithril-tracked event handlers do.
Why
I find myself so often wanting to mount and unmount event handlers within UI trees. This would make it such that I could just do it declaratively. It'd also provide a clean way to set the document's title and so on as well.
Edit: Here's a couple userland implementations of the events component of this.
m.patch
suggested on GitterIt's actually surprisingly complex in practice to wire up, even for just events. This proposal suggests a superset, and in total would probably be at worst around the size of the full events implementation above.
Possible Implementation
setAttr
to avoid thesetAttribute
fallback and just always set the value for event targets that don't extendNode
, and updateremoveAttr
as appropriate as well.setAttrs
/removeAttrs
as appropriate.Open Questions
m.bind
, but that's even worse, and I don't want some long, unwieldy name for this, either. I could totally use some more ideas in this department.Beta Was this translation helpful? Give feedback.
All reactions