Better HN
topnewbestaskshowjobs
Log inSign up

andersmurphy

1,011 karma · joined Feb 22, 2019 (7y ago) · 496 submissions

https://andersmurphy.com
Submissions

comment 1y ago · link · parent

Why? What's stopping you putting some state on the client with datastar. Just because it's discouraged doesn't mean you can't.

It has a whole client side signal system.

comment 1y ago · link · parent

1. You should be using CSS for animations

2. You should be using data-on to listen to the window level resize event (which doesn't require a pro plugin).

3. Scroll element into view can be replicated with data-on-load="el.scrollIntoView()"

The main benefit of pro is supporting the project.

comment 1y ago · link · parent

I mean in practice you rarely target individual elements in datastar. You can sure. But targeting the main body with the entirety of the new content is way simpler. Morph sorts out the rest

comment 1y ago · link · parent

It's the high performance way to use Datastar and personally I think it's the best DX.

1. It's much better in terms of compression and latency. As with brotli/zstd you get compression over the entire duration of the connection. So you keep one connection open and push all updates down it. All requests return 204 response. Because everything comes down the same connection brotli/zstd can give you 1000-8000x compression ratios. So in my demos for example, one check is 13-20bytes over the wire even though it's 140k of HTML uncompressed. Keeping the packet size around 1k or less is great for latency. Redirect also has to do more trips.

2. The server is in control. I can batch updates. The reason these demo's easily survive HN is because the updates are batched every 100ms. That means at most a new view gets pushed to you every 100ms, regardless of the number of users interacting with your view. In the case of the GoL demo the render is actually shared between all users, so it's only rendering once per 100ms regardless of the number of concurrent users.

3. The DX is nice and simple good old View = f (state), like react just over the network.

365.

Blinksy(play.putyourlightson.com ↗)

17 points · by andersmurphy · 1y ago · 9 comments

comment 1y ago · link · parent

I mean Datastar is pretty flexible. I'd say CQRS is pretty idiomatic if you want to do multiplayer/realtime stuff. As you mentioned, once you've se that up, the mental model is much simpler. That being said the initial set up is more involved than req/response Datastar.

Yes we are building complex accounting software at work with Datastar and use the same model. "Real UI" is often more complex, but a lot less heavy less divs, less data, fewer concurrent users, etc compared to these demos. Checkboxes are a lot more div dense than a list of rows for example.

comment 1y ago · link · parent

Currently zoom the page web cmd+/-. At some point I'll add buttons and to proper quantised views.

comment 1y ago · link · parent

Sorry, yes it was sarcasm (I should have indicated that explicitly). I'm happy to fund a tool that I really enjoy using, even if I don't use any of the PRO features.

comment 1y ago · link · parent

The inspector is great, but it's too much work to swap out the free bundle for the pro bundle every time I want to use it.

comment 1y ago · link · parent

It gets worse.

I payed the one off 299$ for a pro license but have yet to find a reason to use any of the pro features.

I was hoping to need them for the google sheets clone [1] I was building but I seem to be able to do it without PRO features.

- [1] https://cells.andersmurphy.com/

comment 1y ago · link · parent

The calling page knows nothing, you do an action on the client, the server might return an update view of the entire page. That's it.

You send down the whole page on every change. The client just renders. It's immediate mode like in video games.

comment 1y ago · link · parent

I'd love to hear what those limitations are as someone who came from Hotwire and moved to Datastar.

comment 1y ago · link · parent

Good for you!

I don't use anything from pro and I use datastar at work. I do believe in making open source maintainable though so bought the license.

The pro stuff is mostly a collection of foot guns you shouldn't use and are a support burden for the core team. In some niche corporate context they are useful.

You can also implement your own plugins with the same functionality if you want it's just going to cost you time in instead of money.

I find devs complaining about paying for things never gets old. A one off life time license? How scandalous! Sustainable open source? Disgusting. Oh a proprietary AI model that is built on others work without their consent and steals my data? Only 100$ a month? Take my money!

comment 1y ago · link · parent

Thank you for the kind words.

I think for me the key thing is Datastar lets me keep most of my state on the backend, which makes the backend much simpler to write. It also lets me do immediate mode streaming of the HTML, which again is non trivial in something like react without a lot of added complexity.

So it's an enabler in that sense. But, yes it's totally possible to write a backend that falls over with datastar like any technology.

I also agree, that Datastar does benefit from backend experience and if you don't have that experience it can to some extent feel like:

"Draw some circles. Now draw the rest of the Owl".

comment 1y ago · link · parent

It's global multiplayer, you can see everyone changes simultaneously. There's no client side state for the checkboxes they are all on the server.

comment 1y ago · link · parent

Sure. You're not wrong. I'd argue Datastar's fat morph model is what lets me write a much simpler backend that's amenable to batching/better compression. It's also fast enough on the client that this immediate mode style rendering of HTML is actually possible.

I'm also not doing anything fancy on the backend, I'm using a dynamic language not known for it's speed (Clojure). Really, most of the work here is being done by SQLITE, batching, and brotli compression, which you can all use from any language.

I will concede that languages with access to real threads (GO, JAVA, C# etc) do better out of the box for this kind of CQRS architecture.

comment 1y ago · link · parent

For those of you who don't think Datastar is good enough for realtime/collaborative/multiplayer and/or think you need any of the PRO features.

These three demos each run on a 5$ VPS and don't use any of the PRO features. They have all survived the front page of HN. Datastar is a fantastic piece of engineering.

- https://checkboxes.andersmurphy.com/

- https://cells.andersmurphy.com/

- https://example.andersmurphy.com/ (game of life multiplayer)

On both the checkboxes/cells examples there's adaptive view rendering so you can zoom out a fair bit. There's also back pressure on the virtual scroll.

comment 1y ago · link · parent

Fantastic write up!

For those of you who don't think Datastar is good enough for realtime/collaborative/multiplayer and/or think you need any of the PRO features.

These three demos each run on a 5$ VPS and don't use any of the PRO features. They have all survived the front page of HN. Datastar is a fantastic piece of engineering.

- https://checkboxes.andersmurphy.com/

- https://cells.andersmurphy.com/

- https://example.andersmurphy.com/ (game of life multiplayer)

On both the checkboxes/cells examples there's adaptive view rendering so you can zoom out a fair bit. There's also back pressure on the virtual scroll.

comment 1y ago · link · parent

Sqlite does this automatically [1] https://www.sqlite.org/optoverview.html#or_optimizations

comment 1y ago · link · parent

Fun read.

I've been tripped up by the where in partial indexes before. Same goes for expression indexes.

comment 1y ago · link · parent

So you'd prefer if it was free and GPL?

comment 1y ago · link · parent

You get the entire source with pro. Nothing is stopping you maintaining your own private fork for use in your commercial product. If datastar the non profit disappear tomorrow you would still have the source. So where is the problem?

comment 1y ago · link · parent

Don't forget Jruby and Groovy.

comment 1y ago · link · parent

And Clojure and Scala. So really Clojure is number 2. :-)

comment 1y ago · link · parent

I mean the definition of death is when the light fades right? Everything else is just an approximation. Would be wild if true.

comment 1y ago · link · parent

A "good chunk of functionality" is a mischaracterisation. I don't use anything from pro and I use datastar at work. I do believe in making open source maintainable though so bought the license.

The pro stuff is mostly a collection of foot guns you shouldn't use and are a support burden for the core team. In some niche corporate context they are useful. You can also implement your own plugins with the same functionality if you want it's just going to cost you time in instead of money.

I find devs complaining about paying for things never gets old. A one off life time license? How scandalous! Sustainable open source? Disgusting. Oh a proprietary AI model that is built on others work without their concent and steals my data? Only 100$ a month? Take my money!

comment 1y ago · link · parent

Datastar uses SSE. In practice you almost always want SSE rather than websockets or your own UDP protocol. Websockets are an operational nightmare once you get off the happy path.

comment 1y ago · link · parent

Thank you! I've been meaning to write one on the nitty gritty of virtual scroll, hopefully I'll find some time next month.

comment 1y ago · link · parent

It does require a mind shift as generally you have one connection morphing in all your updates and do CQRS.

The connection per component model that mesh uses is fine until you have concerns that cross across components (this was an issue hotwire also ran into before they introduced morph/refresh).

Instead you have one endpoint per page re-render the whole page via morph on every change. You still have backend components they just send requests up and get their updates via the sse connection for that page. Kinda like view = f (state) just over the network.

1
121314
17