question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

calling DOM methods

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
timwiscommented, Aug 29, 2016

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 <div> each time it runs, and you save a reference to that <div> inside your view and refer to it in a setTimeout callback, it will only work on the first render. Because future renders simply patch the existing <div> with the one they created.

Example: http://requirebin.com/?gist=7721c651eb58622669112c9391d9c1b8

1reaction
pekelercommented, Aug 27, 2016

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript DOM Methods - W3Schools
HTML DOM methods are actions you can perform (on HTML Elements). HTML DOM properties are values (of HTML Elements) that you can set...
Read more >
Introduction to the DOM - Web APIs | MDN
The Document Object Model (DOM) is the data representation of the objects that comprise the structure and content of a document on the...
Read more >
How to call multiple functions with DOM and Javascript
I have created multiple functions and am having trouble calling each one. The first one is the only one that will call. The...
Read more >
Calling DOM methods from Elm - Learn
Unfortunately elm/html does not have a DOM method primitive. The problem with using Html.Attributes.property "setCustomValidity" (JSON.Encode.
Read more >
Top 10 Essential JavaScript DOM methods List
Top 10 Essential JavaScript DOM methods List · 1) getElementId. getElementId is a method to access any element virtually. · 2) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found