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
Warn about reusing object within attrs? #2826
Comments
@gjmcn here (in your two commented-out examples, which are functionally identical) you have a pretty good example of an anti-pattern: you're directly mutating the nested properties of an object which is passed directly to Mithril's reconciliation algorithm doesn't traverse the nested trees of the properties of That being said, I think you have a pretty good candidate for a docs PR. I wouldn't mind seeing this explained in the anti-patterns sections of the vnodes page and the "m" api page, as well as in the final section of the autoredraw page. |
We do need more information pertaining to anti-patterns. IIRC @barneycarroll has written at length about this (but I might be mistaken). The example @gjmcn gives here is actually something I've seen many folks come across over the years. |
Mithril.js version: 2.2.2
Browser and OS: Chrome, Windows 10
The following had me confused for some time:
I think the issue is that the
// does not trigger redraw
versions are resuing an object withinattrs
and I guess this is not allowed? If so, the problem is that (unlike when reusingattrs
itself) Mithril does not give a warning for the above case. Perhaps it should? Or if this is too inefficient, maybe this could be covered more in the docs? - apologies if it is and I missed it!The text was updated successfully, but these errors were encountered: