loganlinn / tesseract

A React.js in pure ClojureScript
0 stars 0 forks source link

Need function to get component's DOM node #1

Open loganlinn opened 10 years ago

loganlinn commented 10 years ago

Need a function like (get-dom container) that returns DOMNode within the mounted container that co-responds to component. It can inspect cursor metadata to lookup container and QSA, but we'll want a faster access pattern such as generated ids

scottrabin commented 10 years ago

Shouldn't we be able to do (get-in container (interpose .-children (cursor component)))?

loganlinn commented 10 years ago

The cursor, at the moment, consists of the children offsets in the virtual dom. Meaning, it includes composite components that don't have concrete DOMNodes. We are doing the virtual dom equivalent of what you suggest here: https://github.com/loganlinn/tesseract/blob/4c921165483b919dd0779f29b49153c5bdc56c47/src/cljx/tesseract/core.cljx#L55-L61

I am using that cursor to get the current version of the component out of the mount-env because it stores the built root component. We need the ability to get the 'canonical' component because a component could change by the time set-state! processes.

Side-note: get-in wouldn't work for traversing DOMNodes like that AFAIK, but it would be trivial to write such a function.

loganlinn commented 10 years ago

One route might be to make cursors a little more intelligent to be able to additionally support traversals like you suggest, or consider lookups via data-tesseract-id with a generated id (based on vdom cursor).