client sync
Was wondering if we want to have a mechanism to update clients that happen to be looking at the same page URL ?
The idea is that one user is changing some aspect, and when they change it, we want the other users to also see that change.
This is where NATS is pretty cool.
A few examples of where this "pattern" would be useful :
https://data-star.dev/examples/value_select where the models list was changes by 1 user, and other users can then see it change in their drop downs.
https://data-star.dev/examples/infinite_scroll which is read only, but if one of the rows changed ( due to some other user doing a mutation of the underlying data ), all other users would see it.
Why ?
Well one reason is that you get way less Transactions that fail validation rules back in your storage layer.
The other one is for Dashboards where you want real time sync.
I'll be working on a game server that shows this exact behavior between NATS and Datastar
oh great. I really hope that some of the NATS aspects get shown in the Datastar repo as examples, because I think it will help me and others.
I started using Corrosion as my DB with NATS now. It's a CRDT Sqlite DB in Rust with an elegant HTTP API. SO then its very easy to do a "select * ..." as a subscription and just feed it up to NATS and SSE with Datastar
https://github.com/superfly/corrosion
https://superfly.github.io/corrosion/api/subscriptions.html shows how easy it is.
The DB will scale out master master with nothing needed, thanks to the CRDT. It's working well for me.
I am going to write a golang API to consume easily off it and manage the subscription data to make it more robust.
I'll be working on a game server that shows this exact behavior between NATS and Datastar
Would be good if we had a basic example in this repo. Maybe chat ..
I agree that nats is the way to do it .
So I've been trying to think of a way to show this off without a lot of code.. Right now my plan for the front page is to replace the demo with a gameboy emulator that has a shared state of a game like pokemon. Everyone is playing with the same controller. I know twitch did this over 10 years ago but it would be trivial with NATS+Datastar
I don’t know that old demo you are referring too.
I just wanted a simple todo or similar ( chat ) , where all browser tabs are in sync , without hitting refresh.
it’s a very common need.
Very very simple and easy to learn from.
A game is very cool to show off how far it can be taken and is really a good idea too for the front page . But a nice simple todo / chat will help me to see how to do it :)
My only concern with chat or a to-do is is very easy to get buried with bad content, then you have to deal with considering it's spam detection type stuff, I guess I can do it and if it becomes a problem we can try something else
Cloudflare turnstile might be a good option to catch bots before they leave spam?
I don't know much about turnstile @nickchomey but I'll take a look!
Its a better, less invasive captcha https://blog.cloudflare.com/turnstile-private-captcha-alternative/
Just need to include a small js script on the page and it'll do the rest
My only concern with chat or a to-do is is very easy to get buried with bad content, then you have to deal with considering it's spam detection type stuff, I guess I can do it and if it becomes a problem we can try something else
Yeah you're right in that bad actors could put up improper content into a chat. If it does become a problem, we can add a 10 minute timer that wipes all the data.
It's just a demo though. I personally don't think anyone will start to abuse it.
I presume you are are thinking of storing the chat state in NATS ? If you want to wipe the data every 10 minutes we can add a timer counter into NATS.
This has been covered by #74