Fork me on GitHub
#fulcro
<
2022-10-18
>
Quentin Le Guennec08:10:37

Hello, what exactly does “dropping component from index” mean? Is it a remount? Does it impact performance?

Jakub Holý (HolyJak)11:10:40

I guess when it is unmounted it's removed from the index as well. Why do you need to know it?

tony.kay19:10:17

Fulcro indexes all on-screen components. That is just an internal debug message. The indexes allow you to do fancy things by being able to look up the actual react instance that is mounted (by type, ident, etc).

tony.kay19:10:50

Optimized renderers, for example, can look up all of the components that are on-screen for a given ident, and then tunnel updates to them without having to do a root refresh.

tony.kay19:10:38

External tools can also leverage that for things like “auto-scrolling” to a particular thing on-screen (assuming it is a Fulcro component). Say you implemented an advanced form field as a component, and came up with an ident strategy where the form field’s ident was like [:person/id {:id 42 :field :person/name}] (and yes, that IS a legal ident). Then if you wanted to do something related to that field, say due to a validation error, you could look it up by that ident to get the react instance and work with it from there.

tony.kay19:10:09

on current versions of React you’d need to put a DOM refs as well if you wanted to access the DOM element…as discussed here https://stackoverflow.com/questions/38093760/how-to-access-a-dom-element-in-react-what-is-the-equilvalent-of-document-getele) In Fulcro :initLocalState is called within the low-level constructor, so that’s where you could do the createRef stuff. (along with a (set! (.-myRef this) ….) . Of course you can leverage refs in a more transparent way as well, but when you’re in a mutation, for example, the indexes are a convenient data-oriented way to work with the live DOM.

Quentin Le Guennec06:10:03

Ok. Thank you, that’s helpful.