How does Nordcraft handle cleaning up event listeners?
I tried to analyse the memory tab to the best of my knowledge , but I 'd like to know how Nordcraft cleans up unused elements and event listeners . For example , if I add a scroll event listener on a div , then use the hide /show feature to remove it from the DOM - what happens to the scroll event listener ? And in comparison to that , i actually use a passive scroll event listener using a small custom action , does Nordcraft do anything to that if it 's a custom action ? Thanks for your help ! The Nordcraft engine just removes the element on show /hide to clean up events such as scroll listeners on the element self . However , some extra steps may happen just before : - An abort trigger is sent to all pending APIs . This just tells the browser to stop anything that can still be cancelled . - Secondly all previously active actions with a cleanup callback have their cleanup called . You can create a cleanup function in code formulas by making it return a function . It should be documented in the docs . Some of the standard actions does cleanup such as cancelling timeouts in the “Sleep ” action etc . ❤️1It is whatever optional argumentless function that is returned . The syntax is like here for example : https://editor.nordcraft.com/projects/silver_wat_tambor_remote_alligator/branches/start/actions/actionWithCleanupFunction?mode=design&rightpanel=attributes&canvas-width=800&canvas-height=800 You can try the example here where you try to show /hide the component with the toggle button . The cleanup function is called when the element is destroyed : https://start-silver_wat_tambor_remote_alligator.toddle.site/ ❤️1I sometimes have had the need for a pure cleanup action to perform something just before a component is removed . Like saving state to local -storage etc . https://editor.nordcraft.com/projects/silver_wat_tambor_remote_alligator/branches/start/actions/onUnmount?mode=design&rightpanel=attributes&canvas-width=800&canvas-height=800 🙏1