5 ms·
For the very reasons listed in the article, I built: https://github.com/siriusastrebe/jsynchronous https://github.com/siriusastrebe/jsynchronous a library for
by swagasaurus-rex 5y ago
For the very reasons listed in the article, I built:
https://github.com/siriusastrebe/jsynchronous https://github.com/siriusastrebe/jsynchronous
a library for keeping a javascript variables synchronized between Node.js servers and clients.
Websockets work great for message passing but it struggles with data structures more complicated than what JSON can represent. Jsynchronous syncs any javascript object or array with arbitrarily deep nesting and full support for circular data structures.
If a computer goes to sleep, or disconnects, websocket connections (and their underlying TCP connections) get reset so you lose any data sent while a computer is unavailable. This is catastrophic for state-management if it's left unhandled. Jsynchronous will re-send any data clients are missing and reconstructs the shared state.
There's also a history mode that lets you rewind to past states.
- adamddev1 5y agoVery, very nice! I might use that! Just gotta wrap it a nice React hook.
- anderspitman 5y agoVery cool. I tried something similar once. Have you gone down the differential/compressed update rabbit hole yet?
- swagasaurus-rex 5y agoRight now jsynchronous message passes using custom encoding in JSON which keeps simple changes as small as an HTTP header, but with byte level encoding I think this could be halved. Some compression on top would probably do wonders for huge volumes of changes, though more browsers are supporting compression on the websocket level. I'm not familiar with the name differential update. Instead of passing potentially large states back and forth, Jsynchronous numbers each change to your synchronized data and shares these changes with all connected clients. This is called Event Sourcing, and it enables jsynchronous to rewind to previous states by running the changes from start to any intermediate state.