4 ms·
Have you thought about adding polling functionality, so that a given element can check with the server for updates at a set interval?
by replwoacause 3y ago
Have you thought about adding polling functionality, so that a given element can check with the server for updates at a set interval?
- josephernest 3y agoThanks for looking at the lib! Polling is typically the kind of thing I usually prefer to handle fully manually in JS. That's what I do for my own web apps. Even if I added a specific HTML tag attribute for polling, at the end, there will always be a missing something, and I'll end up writing JS anyway. So for this kind of thing, I don't think a lib is necessary: you just setTimeout / setInterval in the script that runs when the view is loaded: Swap.loaders[".my_view_with_polling"] = () => { update_task = setTimeout(do_polling, 1000); ... return () => { // unloader function when we quit this view clearTimeout(update_task); }; }; For a real example, see my email client demo: when you open an email, there is a timer. Here it's done: https://github.com/josephernest/Swap/blob/main/demo3-email/app.js https://github.com/josephernest/Swap/blob/main/demo3-email/a...
- replwoacause 3y agoAh makes sense, thanks for the example!