Show HN: React-hn – Supports all Hacker News API v0 item types
github.com
github.com
You'll find on other auto-updating comment systems that "x new comments" is introduced so that you don't lose the spot you were viewing and you have the choice of seeing the new comments or not.
Animations and color can be used to show the movement, appearance, and disappearance of items. This would be great for seeing how votes and positions of items are changing.
I implemented "x new comments" for Hacker New as a userscript [1]. Thinking of doing something similar by having new comments add themselves as "new" if you're already on a page and caching the max comment id seen in localStorage for when you revisit.
This API really needs something sitting with the websocket always open on the backend to do some caching, particularly for comment counts.
If top stories were being cached and data passed top-down rather than fetched individually as with this hack, you could even reuse the same React components to pre-render on the server.
[1] https://twitter.com/jbscript/status/462657449497874432/photo...
I actually have been really pleased with the combination of a few related react packages (mostly react-async) put together in this sort of quickstart repo:
https://github.com/andreypopp/react-quickstart
It's extremely easy to write a primarily client side app that still prefetches its data and renders the initial HTML on the server (which would completely eliminate the issue here).
Firebase has a node.js SDK so it's possible to do that pre-fetching server side too.
Moreover, their API is consistent between the browser and Node.js clients, so almost all the application code can be shared. Just inject the appropriate client and away you go.
I just started playing around with react pretty recently, and it definitely seems like people's opinions about how to structure things have shifted pretty quickly.
This stuff is too fun :)
He can freely render as many times as he wants (a dozen function calls won't be your bottleneck); I'd even argue it _could_ be nicer that everything's rendered gradually this way, but that's just an aesthetic choice.
Every individual item uses a ReactFireMixin method to register its own Firebase reference, binding the incoming data as an object in its state, so they pop in as the websocket receives data, then auto-update every time new data arrives.