Live data from Hacker News

Datastar: Lightweight hypermedia framework for building interactive web apps

data-star.dev

261–270 of 298 posts

Re: Datastar: Lightweight hypermedia framework for building interactive web apps

#261

Docs mention absolutely nothing about offline use, service workers, or PWAs. How am I supposed to build a modern web app with that? Rely on always having internet?

I'm extremely interested in this sort of use case and am regularly disappointed to find that very few others are. And even fewer are interested in doing it in a hypermedia-first way.

There's two ways this could be approached.

1. Just cache the backend-generated html that has datastar attributes in it, and serve it from a service worker. Datastar library in the main thread won't know or care whether it came from service worker, edge worker or your backend.

2. If there's a need for dynamic data/templating (eg user-specific into), you can do so in the service worker - if you've stored the templates and data already. But that has little to do with datastar - you'd have to do that in any case.

However, service workers have limitations with regards to things like dynamic script imports, using es modules etc. You can send messages to a dedicated web worker which handles rendering and returns the html, but it does get complicated. Sharedworker would be even better but android chromium still doesn't support it - but they're finally trialing it and hopefully it'll be available in 6 months.

The only datastar-specific consideration is if you want to do something like stream sse events from the "backend" to the datastar library in the main thread/dom. The TypeScript/JavaScript sdk works just fine in the service worker as well, and can maintain a long-lived connection to periodically stream new messages. Of course, service worker lifecycle is somewhat of a black box and out of your control, but that has nothing to do with d*.

So, overall, yes you can use datastar offline. But it comes with all the issues that you'd face with another approach.

Re: Datastar: Lightweight hypermedia framework for building interactive web apps

#262

Is there a good Datastar tutorial creating a small project that shows off Datastar's strengths and how the DX feels like? I saw the game of life and checkbox examples but I've never used Clojure

Yeah. That's the real rug pull all my code is in Clojure. Which is rough if you're not familiar with reading lisp.

There's a few examples in typescript and go floating around.

Here's one:

https://github.com/Mortalife/datastar-chat-example-ts

Re: Datastar: Lightweight hypermedia framework for building interactive web apps

#263

Interesting, but do I understand correctly that: - this would mostly work if the sole consumer of your API is the frontend, since it returns HTML, rather than, eg JSON that would be consumed by a CLI, some streaming tools, clients, etc - this would not really be suited to some Capacitor app?

Yeah it assumes your building a full stack app driven by the backend. So the client and backend are tightly coupled and built for each other.

Re: Datastar: Lightweight hypermedia framework for building interactive web apps

#264
post #160

Earlier quoted context omitted.

You basically can't refactor reliably without static types, you can't navigate the codebase quickly without static types, and it makes it more difficult to understand other people's code without static types. What a great interview test. I’d absolutely not hire someone that can’t do that. It also doesn’t make any sense. That’s like saying entire codebases without types can’t be worked on. Huh? Those are basic things…

I said reliably . Without static types in large codebases you are likely to miss things. E.g. you rename a variable but don't catch everywhere you should have updated it. Don't say "but tests".

If your data model is open and not closed you only need to change the location you are changing. This is how the internet works. Types that don't support this model actively hinder refactoring.

Re: Datastar: Lightweight hypermedia framework for building interactive web apps

#265
post #215

Anything that’s using server side rendering gets my vote. But isn’t HTMX+Websocket basically the same as datastar?

Not at all, for many reasons.

HTMX doesn't do any client side interactivity. You need something like alpinejs for that. And alpine doesn't have signals, which are super useful (when used judiciously)

Datastar uses sse rather than websockets, which is simpler and more compatible http,web standards etc. Htmx can use either sse or ws, but both are a separate plugin.

Consequently, datastar does much more than htmx+alpine+ws/sse, in a fraction of the js size.

Htmx (and alpine, I think) introduces it's own html attributes whereas datastar uses spec-compliant data-* attributes (hence the name)

Htmx's api is much more complicated due to all of the extra attributes. Datastar is more concise.

Datastar has backend SDKs for all popular languages, to make it easy to send html fragment and signals updates via sse.

There's lots more as well. Very worth checking out.

Re: Datastar: Lightweight hypermedia framework for building interactive web apps

#266
post #25

Earlier quoted context omitted.

I just think you are wrong. It mostly takes mindshare from rookie developers that are insecure and need to cover all their bases lest they be called bad at being a developer. Many grow out of this insecurity and see things for what they are. TS is OKAY, but it's not worth my time.

Well I'm objectively correct about it preventing bugs. This is one of the few things that has been fairly conclusively shown by studies. As for productivity, maybe it doesn't matter on tiny projects or short-lived one-man projects, but for anything else I don't see how you can argue it. You basically can't refactor reliably without static types, you can't navigate the codebase quickly without static types, and it mak…

Care to share one of your projects with zero bugs?

Re: Datastar: Lightweight hypermedia framework for building interactive web apps

#267

Earlier quoted context omitted.

I've commented above that this seems like a bad approach, but it sure feels like a lack of awareness vs. an intentional dark pattern. The internet makes it so easy to assume the worst but I think this is a case where we should start with the most charitable interpretation.

Dark pattern? Pro plugins are built in the same way as is accessible to any user. What's the real issue?

That you have to go looking, actively, to realise there is a paid option.

Re: Datastar: Lightweight hypermedia framework for building interactive web apps

#268
post #160

Earlier quoted context omitted.

You basically can't refactor reliably without static types, you can't navigate the codebase quickly without static types, and it makes it more difficult to understand other people's code without static types. What a great interview test. I’d absolutely not hire someone that can’t do that. It also doesn’t make any sense. That’s like saying entire codebases without types can’t be worked on. Huh? Those are basic things…

I said reliably . Without static types in large codebases you are likely to miss things. E.g. you rename a variable but don't catch everywhere you should have updated it. Don't say "but tests".

Ifv you include the artificial restriction of not "use the correct tool/tests", then maybe you are right.

Re: Datastar: Lightweight hypermedia framework for building interactive web apps

#269

Earlier quoted context omitted.

Basic decency of being upfront about your business model, and in general being upfront and not being deceitful in life. Anyways, constructively, they should add a usual pricing page with a nav for that at the top of the landing page. It makes it clear that something is priced, right on the landing page. In the pricing page the cards better make the costs super clear.

I'm confused. Datastar is a free open source framework that you can choose to use or not. It's weird to call them out as indecent and deceitful for not actively marketing features that they really don't think you need. Even when you think you need it, they've actively encouraged people to analyze their problems to identify if it's a real need or a gap in hypermedia fundamentals knowledge. Also, the top nav has a Pro…

”Ready for liftoff?” should have a go-pro button. That’s all that is needed.

Re: Datastar: Lightweight hypermedia framework for building interactive web apps

#270

Earlier quoted context omitted.

op: copies information from the website you: "How dare you!!!!!"

There's a such thing as context and intent which are separate from content, and this is directed as much at the people who upvoted this particular content to the top comment as it is to the OP. The conversation on this post is now centered around the fact that they have some premium features for sale. Edit: Now there’s another post on the front page of HN accusing the datastar team of being greedy. https://news.ycomb…

> The conversation on this post is now centered around the fact that they have some premium features for sale.

Oh the horror!!!!!!

Post reply on HN