I have a specific app which should do the following:
- You have a list of jobs to inspect
- When you click a job you get a detail view
- The detail view will poll the API to see live progress updates
I did a basic implementation in the following REPL: https://svelte.dev/repl/fcdce26dc0d843dbb4b394dcd2c838af?version=3.20.1
There are a couple of issues with this approach:
- The
Job.svelte
view should basically reset when you provide a new id, and clear out any previous poller, but now it's super awkward with a reactive statement at the bottom - Because the poller does an asynchronous fetch it can happen that the timeout handler
poller
is cleared even though the handler is executing already. This causes multiple poller loops to occur (you can reproduce this by clicking through the job list at random intervals between 0 and 2 seconds) - The current approach is not developer friendly and is easily broken. The 'bug' above can be fixed by keeping track of a reference/lock kind of thing but then it's even harder to wrap your head around.
For this use case, what is a better way of implementing it (in Svelte)?
Thanks a lot!