-
-
Notifications
You must be signed in to change notification settings - Fork 926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using key in attrs causes onupdate. Expected oninit #2650
Comments
hello marc, i ported your example to flems so that it's easier to collaborate. check out @osban re-initializing examples you can probably benefit to moving to using route-resolvers with your routing. -- UPDATE -- changing line 68 to |
@MarcWeber I agree with @cavemansspa's assessment. If you'd use a route resolver, you could use a Layout, and do something like this. |
@cavemansspa Thing I don't get is: The :component passing different key to new component could have state. So why does using key on the the parent components make it work ? I mean I could be setting state and m.redraw, right ? The logging (on update) does show that the changed attrs get passed. What are plans for SSR? Example is here: fleem So I change the state (eg coud be stream/ var or like in this case a function).. I pass it as key.. Yet it results in onupdate ? |
there's a subtlety where you need to wrap with |
Ok - thank you very much. Still looks too complicated to me. The documentation could be more clear by making the array parentheses red or so if they are the most important thing which doesn't make sense to me at all. For me [x] or x was the same. My brain doesn't want to accept this. I have seen that example in docs but totally (intentionally) missed the array cause doesn't make sense to me. My original case is solved. But I personally tend to see it as bug violating KISS principle which mean keep it stupid simple. Mithril gets much right though. Up to you whether you want to close this or not. |
@MarcWeber this is related to #2654 Keys are only detected in children lists, not in the vnodes returned by components. If you wrap the vnode in an array, Mithril treats it as the child of a keyed fragment and it is re-initialized as you wish. Going from return m(C_item_new, {
'type': attrs.type,
'key': attrs.type
}) to return [
m(C_item_new, {
'type': attrs.type,
'key': attrs.type
})
] |
☝️ |
dev or stable mithril: https://mawercer.de/tmp/tmp/mithriltest.html
I do set key, yet onupdate is called. Why ?
If I change :type to :key also replacing attrs.type by attrs.key then oninit gets called.
Setting a different key shouldn't it cause recreating the component ?
So what am I missing ?
The text was updated successfully, but these errors were encountered: