Suggestion: allow Hyperscript selectors to be used in the diffing algorithm #2943
Replies: 6 comments
-
Could break some apps if people were relying on the old behaviour... m('div' + isActive ? '.active' : '', ...) |
Beta Was this translation helpful? Give feedback.
-
@spacejack I'm aware, but it should only present itself if you use |
Beta Was this translation helpful? Give feedback.
-
I'd rather improve the docs than introduce this. Both behaviors make sense, and users can opt into remove/create by using keys if needed. Oh, now that I think of it, I suppose that you could force update by using the same selectors and passing parameters through the attrs object rather than the selector... Mild 👎 |
Beta Was this translation helpful? Give feedback.
-
@pygy Just to throw this out there, I'm only mildly 👍 , just the only reason I even suggested it was for UX reasons, not necessarily because I'm otherwise interested in it. |
Beta Was this translation helpful? Give feedback.
-
I just submitted an issue on snabbdom for the exact inverse problem (using h("div#myID") leading to setting a semi-implicit key on the Vnode). I like the way mithril is using this syntax only as a shorthand for settings class/id on the element, letting the key property be the only "real" / explicit key. Anyways, both options seem viable to me, and probably the documentation option is the more conservative/least painful action to take. |
Beta Was this translation helpful? Give feedback.
-
Revisiting this months later, I see very little actionable here. Here, it's documented to just be one way to pass attributes, hardly any different from passing dynamic attributes. The docs could use a little clarification that they're equivalent, but this is the only thing necessary. |
Beta Was this translation helpful? Give feedback.
-
Currently, people are getting confused by
cond ? m(".foo") : m(".bar")
not diffing as expected. It's come up quite a few times in Gitter by now, and it leads to some pretty subtle user bugs.Expected Behavior
What many people are expecting is that
m(".foo")
andm(".bar")
are treated as different elements, and I'm suggesting using that as part of the node's identity, as if it were part of the node's tag name.Current Behavior
Currently, Mithril sees
m(".foo")
as no more thanm("div", {className: "foo"})
, and diffs based on the tag name itself.Possible Solution
Add a check here to also check for the Hyperscript selector along with the tag name heuristic.
Context
It'd avoid subtle bugs like in this, where
oncreate
doesn't fire like you'd visually expect ifvnode.state.loading
is initiallytrue
.Edit: An alternative to this would be to document the behavior as a common gotcha, recommending the use of
key
as applicable.Beta Was this translation helpful? Give feedback.
All reactions