nanocomponent icon indicating copy to clipboard operation
nanocomponent copied to clipboard

How to get nanocomponent instance reference from root node?

Open YerkoPalma opened this issue 7 years ago • 3 comments

Hi :wave:

I have a situation where I have many components and some external libraries which manipulates the DOM. So, those libraries transform the root node of my components, and I need to run functions from the components after they are manipulated but I can't figure out how to get reference to that instance from the node manipulated for this library.

In other words, what I would like is the inverse of the element property of nanocomponent, perhaps a function that given a DOM element returns the actual nanocomponent tied to it. Is this possible?

Thanks :)

YerkoPalma avatar Apr 24 '18 14:04 YerkoPalma

perhaps a function that given a DOM element returns the actual nanocomponent tied to it

Not at the moment, no. Appending properties to prototypes on the fly greatly reduces performance, so maybe that's not the solution. Perhaps you could share a cache instance around, and read the key from the DOM element to find the right instance?

yoshuawuyts avatar Apr 24 '18 16:04 yoshuawuyts

I wasn't suggesting to change prototype on the fly, because I had no idea how to achieve what I was asking for :)

Now I think I will keep a global object referencing the components I need. Thanks for the feedback :v:

YerkoPalma avatar Apr 24 '18 17:04 YerkoPalma

DOM Nodes created by nanocomponent shouldn't be externally modified (given the way thing work now). If you must, pass the data changes into the component through render or add additional class methods and handle the internal mutation at the component level.

If you see something nanocomponent can do internally to be more accommodating I'm open to ideas.

bcomnes avatar Apr 24 '18 18:04 bcomnes