DEV Community

Discussion on: I am the author of Elm in Action. Ask Me Anything!

Collapse
 
joeandaverde profile image
Joe Andaverde

Richard,

I use some jQuery plugins, d3, and react in my application. We use a ton of Elm too!

We are having trouble embedding components in our Elm applications. Working with ports is a great abstraction to help us protect the purity of our lovely Elm world. However, many of the projects I embed in my Elm project hook up event listeners to DOM elements. This causes memory leaks because there's no way for the component to know it's being unloaded.

You seem to have some experience with this at NoRedInk - the jQuery Datepicker plugin by XD Soft.

Do you know if there's any intent on providing a mechanism for the modules we embed in our Elm app and interact with through ports to be notified when the DOM is being recreated or going away?

This is our last major hurdle for converting ALL of our frontend code to Elm. If we try to embed our D3 graphics in Elm it would cause MAJOR performance issues. I understand I could write this in Elm but it works great and would be costly to reimplement.

Collapse
 
rtfeldman profile image
Richard Feldman

We haven't run into performance problems around this, but thank you for surfacing it! There was some discussion around whether this was needed, and the consensus was "in theory it would be useful, but in practice, who knows if it's actually necessary?"

Seems like you've found a case where it is! I'd post specifics of your use case on github.com/elm-lang/virtual-dom/is... - ideally with a link to the D3 code in question.