-
-
Notifications
You must be signed in to change notification settings - Fork 924
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
Redraw proposal #1847
Comments
I much prefer I'm envisioning a lot of code like
Could we have a separate function for vnode specific redraws? E.g. The naming could be anything, I'm just looking for a specific function. |
@isiahmeadows 👎 on A.2 and A.4, you said in #1765 that you had changed your mind about having For A.3, I'm also ambivalent about returning Promises (having once championed such hooks). You can achieve similar results from the views an hooks, in a way that is often more declarative. |
First, I'll start out by saying that this proposal is where I stand right now. My views have changed over time and this best represents where I stand now. I have taken previous points and suggestions, and I have backed off some of my previous opinions because of concerns that you and others brought up. I'd rather have someone tell me where I went wrong over building something that's broken by design.
Let me clarify why I wanted to disallow it: It could lead to race conditions and leave Mithril in an invalid state, just like in nested I think that if throwing is a problem, we should just be more robust against thrown errors in the first place. They might be exceptional for the end-user, but internally, they're a very normal result for us, something we should account for.
Note that I said render/redraw, without preference on what method is used. I agree that we should only render; I only lumped the two together to emphasize the timing.
I know this. We could also optionally accept a callback, but there is the small legitimate use case of needing to know when it finishes. It primarily shows up in the case of interactive components, where you need to redraw on user input, and you have further work to do afterwards on the updated DOM. It's not common at all, but we should still enable it. Although, now that I think of it, most of those uses could just use |
I'm assuming that would look like this:
I'm okay with it. Just more of a +0, since we can just assert that |
Where are we with this proposal? Have we decided the new api for |
@ludbek I'm awaiting @pygy's response to this comment, and hoping for some feedback from @tivac and/or @lhorie if possible. |
@isiahmeadows if you don't mind, I'm going to implement #1592 and The intermediate |
I'm good with you going ahead and implementing it.
Yeah, I was just suggesting that as more of a big-picture thing to ensure that if/when it gets implemented, we have an API in the end for that feature that makes sense. |
Although |
Given the lack of progress/discussion on this I'm closing it out for now. |
/cc @pygy @tivac @lhorie
Building on #1765, #1776, #1165, #1837, among others, I'm making a more universal proposal that:
m.redraw()
,m.redraw.sync()
, and granular redrawsThis should hopefully catch all three in a way that makes sense and has much better defined behavior.
m.redraw(vnode?)
schedules an async redraw, with all roots by default or optionally with just a singlevnode
, and returns a Promise resolved when done.m.redraw.sync(vnode?)
performs a sync redraw, with all roots by default or optionally with a singlevnode
, and blocks until done. If we are currently rendering any root, calls to this will throw an error, even ifvnode
or its parents were not scheduled to be updated this iteration.m.mount(elem, component?)
always performs a sync render/redraw. It's uncommon that this is called more than once in the same frame, and it allows us to batch the usually first render at the same time as the browser's first or (if delayed withDOMContentLoaded
) second paint. In addition, it'll make it easier for people to test the state of their DOM in unit and integration tests.m.redraw.sync()
, called without the vnode.m.redraw.safe()
returns whether it's safe for a sync redraw. This returnsfalse
if and only if we are currently rendering any root, and allows people to know ifm.redraw.sync
is safe to run without resorting to an unsafetry-catch
that may catch other legitimate errors.In the event
m.redraw
is called with a vnode:In the event
m.redraw
is called without a vnode:Does this help in making the redraw story more consistent, more powerful, and easier to understand? Also, did I miss anything glaring with this?
The text was updated successfully, but these errors were encountered: