Implementing a live leaderboard
Another nice feature of amp-live-list
is that updates can be applied automatically, without the need to click or tap a button. This is very useful for live-updating of scores that you might find in sport, such as football scores, or leaderboard style rankings that you would find in racing and election results.
Let's implement a live Grand Prix position leaderboard. To get the list items to update without having to press the update button, we need to make sure that we do the following:
- Don't change any item IDs after initial load: If you introduce new IDs, then the update button will be displayed.
- Include the
data-update-time
attribute: If the latest server update contains a value higher than the current value in the DOM for any item, thenamp-live-list
will replace the item with the new content.
Note
Note that amp-live-list
won't re-sort already rendered items, even if you change the data-sort-time
; data-sort-time
is only used for new insertions.
On the initial...