mpk-ttss
mpk-ttss copied to clipboard
Local countdown
- Add local countdown if departure is close enough (so we get a smooth second-by-second cooldown before the next refresh)
- Fix ttss_base if project is not installed in web root (a dot for relative path)
- Fix in map.js for green border if tram is already on stop/loop (as it was done in previous pull request in index.js, didn't notice the one in map.js)
Please review.
I would like to see such changes:
- do not call
loadTimes
insidesetInterval
function - this may cause weird behavior if many trains should arrive in succession (eg. in 2, 4 and 6 seconds - it may result in three calls each canceling the preceding one), - IMHO the way to go should be to keep references to
<tr>
and relevant<td>
elements along withactualRelativeTime
(maybe use td.dataset), - go through all the elements every second and only update text content (plus
className
), optionally on-demand (ie. compare what is generated with current value andsetText
if required - but I am not sure how much of a performance hit will incur from not doing it, if any). This would also makeshould_activate_smooth_timer
obsolete.
This would lower both number of modifications and additional code required - pretty much only function for setting status text and proper className should be extracted and used).
As you have stated - updating half of the DOM tree every second is no good.
It would also be unnecessary DOM updating every second without any visual change.
Thanks for the contribution!