Subtree rendering proposal #2944
Replies: 22 comments
-
We also could (and should) make |
Beta Was this translation helpful? Give feedback.
-
Just wondering out loud, and probably a separate issue, but what to do with event listeners within these subtrees (which would trigger global redraws.) EDIT: I guess my question is, is there an advantage to this over using |
Beta Was this translation helpful? Give feedback.
-
@spacejack It may be viable to make them only redraw the subtree they were defined in. It's pretty rare not to, and IMHO it's pretty odd that we currently do auto-redraw roots whose event handlers never fired.
Yes: you can define subtrees without having to manually redraw everything yourself. In addition, see the first part of this response for a suggested perf fix (which should affect relatively few cases). |
Beta Was this translation helpful? Give feedback.
-
There may also be cases where you do want to trigger a global redraw. Is this how it would work?
|
Beta Was this translation helpful? Give feedback.
-
Yes, but it wouldn't avoid a redundant subtree redraw. (It'll be the existing dumb |
Beta Was this translation helpful? Give feedback.
-
How about
and In our architecture we have (unavoidable, I think?) fat controllers that pipe mbs of data over websockets and then call redraws from the top-level controllers (via callback from service) when data arrives. We already debounce the mithril internal renders by about 300ms otherwise it halts up the app quite badly with the amount of data coming in, so subtree renders would be a nice to have Our app could very well be the largest and most un-web thing built in mithril ever so I could be biased to a use-case nobody has (?). We are still running the 0.* version stream FYI because the 1.* refactor was too costly - for example we used m.prop religiously |
Beta Was this translation helpful? Give feedback.
-
@kvanberendonck There's a few problems you might not notice about that at first glance:
Mithril v1 is less web-dependent, actually. It was designed from the start to be less web-dependent for a better testing experience.
You may appreciate
Oh, and trust me: many of us overused props in 0.2.x. As for other things, the hardest part to migrate will likely be
|
Beta Was this translation helpful? Give feedback.
-
Regarding a workaround for this...I just came up with this on Gitter (and here's a packaged gist): // How to structure a self-sufficient component
const Comp = {
// Real inner view
render(vnode) { /* ... */ },
// View replacement - note that this *must* be a single DOM node
view(vnode) { return m("div", this.render(vnode) },
// `m.redraw` replacement
redraw(vnode) { m.render(vnode.dom, this.render(vnode)) },
} Note that it does have potential safety/batching issues, though. |
Beta Was this translation helpful? Give feedback.
-
The (vnode | this).redraw() Idea seems great. I don't think it would cause a breaking change to the api, and it would take care of most of the slow redraw issues in larger trees. Just diff the subtree associated with the vnode. |
Beta Was this translation helpful? Give feedback.
-
@isiahmeadows I tried out your Curious, I manually called |
Beta Was this translation helpful? Give feedback.
-
@mnichols You might want to check this out:
https://github.com/isiahmeadows/mithril-helpers
In particular, it has a `SelfSufficient` class in
`mithril-helpers/self-sufficient`. (I made this with the sole purpose of
having a single accessible set of useful utilities)
Note the unusual install commands: you install it from the GitHub repo
directly rather than from the registry.
…On Sun, Sep 17, 2017, 12:38 Mike Nichols ***@***.***> wrote:
@isiahmeadows <https://github.com/isiahmeadows> I tried out your Comp
structure above and found that after calling redraw(vnode) on the
component subsequent calls to m.render(topLevelDom, AppComponent) would
not update the DOM although the new attrs would be inside the input vnode.
Curious, I manually called this.redraw(vnode) inside the onupdate method
and the DOM would update as expected. It's almost like when you call
render on a DOM node that is part of a tree mithril rendered previously
mithril doesnt reconcile its DOM anymore.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1907 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AERrBNHUQvPRvB1daGjslgiVhpR8OVZmks5sjUrrgaJpZM4Oc7bV>
.
|
Beta Was this translation helpful? Give feedback.
-
Thanks @isiahmeadows ! I tried using SelfSufficient and it has the same issue I experienced earlier. I spun up a codepen here to demonstrate: https://codepen.io/nicholsmike/pen/pWjGoM?editors=1000. |
Beta Was this translation helpful? Give feedback.
-
Ok. File a bug there, and I'll take a look at it. I mostly mimicked
Mithril's behavior in writing it.
…On Mon, Sep 18, 2017, 02:45 Mike Nichols ***@***.***> wrote:
Thanks @isiahmeadows <https://github.com/isiahmeadows> ! I tried using
SelfSufficient and it has the same issue I experienced earlier. I spun up a
codepen here to demonstrate:
https://codepen.io/nicholsmike/pen/pWjGoM?editors=1000.
Notice that clicking the button changes the vnode.attrs.model state but
the DOM doesnt update until you move the mouse again (causing another
redraw).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1907 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AERrBCiS4vr6N3A0b2gVZc1fJx3aku1iks5sjhFvgaJpZM4Oc7bV>
.
|
Beta Was this translation helpful? Give feedback.
-
@isiahmeadows Done! dead-claudia/mithril-helpers#1 |
Beta Was this translation helpful? Give feedback.
-
I made a prototype of something similar: It's basically an option for a rendering mode similar to (but better than) React's; requires manual change tracking (à la setState), but won't rebuild the entire vdom each redraw. |
Beta Was this translation helpful? Give feedback.
-
While out away from things, I came up with another idea:
This would entail some other internal changes with major public-facing ramifications:
Here's a few other side effects it could have in the future:
|
Beta Was this translation helpful? Give feedback.
-
Couple other clarifications:
|
Beta Was this translation helpful? Give feedback.
-
(1) Is it possible to avoid
(2) What about caching the (3) What sorts of things could (4) Would |
Beta Was this translation helpful? Give feedback.
-
I am 100% against any solution that makes global redraw any more difficult than it is right now. IMO it's one of Mithril's most valuable features. Being able to opt into more granular drawing is fine, but I don't want to be forced to do that. |
Beta Was this translation helpful? Give feedback.
-
@tivac Understandable, and I personally started having concerns over it getting unwieldy now that I'm re-reading it. 😄 I do have a question, though: should my utility (link) be considered the ideal workaround, much like
Basically, I just need a way to define an island. This would make my (and my library's users') life much easier, since I would no longer need |
Beta Was this translation helpful? Give feedback.
-
Apart from that, a way to reuse the throttler to (un)schedule simple tasks with associated vnodes would also be nice. You can look at the source and see that ~40% of it is just reimplementing |
Beta Was this translation helpful? Give feedback.
-
So here's the status of what I need to hook into Mithril's redraw system for my
|
Beta Was this translation helpful? Give feedback.
-
Edit: clarification
Edit 2:
See here for an update.Edit 3: Bad idea. Back to square one...(follow-up for #1847)
/cc @pygy @tivac (and others interested)
Here's my current idea for subtree rendering:
m.mount(vnode.dom, ...)
to set up a subtree. (Possible today)m.redraw(root)
,m.redraw.sync(root)
- Redraw just this root, rather than all roots.render/render.js
usingroot.contains(current)
.This should be pretty easy to implement and should cover the general use case.
Beta Was this translation helpful? Give feedback.
All reactions