-
Notifications
You must be signed in to change notification settings - Fork 597
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
calling DOM methods #236
Comments
Seems like Elm has a similar issue: evancz/elm-architecture-tutorial#49. |
Sounds like you probably want to do some finite state machinery around this; the |
Thanks. Bel's hooks look useful for some use cases. I'm thinking a generic view callback would cover all use cases. Would something like this be terrible: const MyView(state, prev, send) => html`
<div>
${tallThing1}
${tallThing2}
</div>
`
MyView.domCallback = (state, prev, rootElement) => {
// called every time after MyView has been called and morphed into the DOM
// rootElement is the div in this example
if (state.currentThing !== prev.currentThing) {
rootElement.childNodes[state.currentThing].scrollIntoView();
}
} |
You could do that in a edit: should def double check tho; not 100% sure, but think generally they do hmmmm |
Oh, cool. The timeout callback doesn't give me the parentElement sugar but is good enough. Coming from React, I assumed DOM updates in Choo are also asynchronous. |
Note that you'll have to use query selectors in timeouts because once the view is patched onto the dom, there's no guarantee the element created by the view will still exist. Because choo uses morphdom to apply dom updates, if an element already exists in the dom, it simply gets updated rather than replaced. So if your view creates a Example: http://requirebin.com/?gist=7721c651eb58622669112c9391d9c1b8 |
If an element gets rendered by a choo view, and I need to invoke a method on that element in response to an action, what is the proper way for making that call?
For example
scrollIntoView()
,focus()
,normalize()
,select()
, etc.In React, I'd use lifecycle methods for this. Would it make sense to add similar hooks to choo?
The text was updated successfully, but these errors were encountered: