swyxio / svelte-actions

prototype official actions for Svelte
MIT License
228 stars 9 forks source link

Refactor lazyload to avoid unnecessary object creation #1

Closed MacFJA closed 3 years ago

MacFJA commented 3 years ago

The current implementation create multiple IntersectionObserverCallback and IntersectionObserver, which are not needed.

swyxio commented 3 years ago

i might be wrong, but i think action function bodies are only run once? @kevmodrome. only the update() gets run multiple times.

MacFJA commented 3 years ago

I made a small example: https://svelte.dev/repl/2903aeece4524f0a9a66db758503a887?version=3.29.4 (see the console)

The main body is call on every time the action is used. The update function only if the value change after the initialisation

swyxio commented 3 years ago

awesome, thank you very much!