Random UI Question for everyone: Generally speaki...
# off-topic
j
Random UI Question for everyone: Generally speaking, do you: A.) Query your data with subscriptions so that likes/votes/bookmarks (or whatever) get updated automatically on click (and always stay updated) B.) Query your data with promises and update the page optimistically on click C.) Query your data with promises, but somehow use a hybrid solution (please explain if you do this) I keep going back and forth on best practices here...
s
Interesting topic. My general approach is to query on load with
select()
, and then setup a subscription to listen to changes afterwards. Depending on your UI framework and whether it loads while scrolling (as opposed to rendering everything, including items that are offscreen), this might be the most performant option. Periodic polling might be another option as you're reducing the amount of traffic down to predictable patterns and it provides you with a great level of control of performance depending on how your backend infrastructure is handling the load. For example, if there's 4 likes on a post, and a user clicks it, what usually happens is the users UI will be updated to display 5 immediately. The user doesn't necessarily care immediately that another 2 people have liked the post, and getting that information when the next poll tick occurs a few seconds or a minute later is usually sufficient to create a smooth experience.
j
Interesting, I see youtube does not use websockets, but twitter does (and it has a transition on update). So you think grab all items, use a listener for when in view, then create subscription on item at that point? Makes sense...