starfederation / datastar

A real-time hypermedia framework.
https://data-star.dev/
MIT License
698 stars 37 forks source link

Iterating over store array variables #195

Closed jfpalacios closed 3 weeks ago

jfpalacios commented 3 weeks ago

I am trying to do some client side list manipulation before sending to the backend. I see I can update the ds store client side, but is there a way to display a list of items from the store dynamically on the client side?

bencroker commented 3 weeks ago

You can access the store programmatically with ds.store.

jfpalacios commented 3 weeks ago

Yes, but are there any directives or client side libraries to display a list of items from the store?

bencroker commented 3 weeks ago

Not that I know of, besides looping over them. Maybe @delaneyj can confirm/deny?

blinkinglight commented 3 weeks ago

are we talking about <div data-text="JSON.stringify(ctx.store(), null, 2)"></div> ?

jfpalacios commented 3 weeks ago

No not exactly, something like alpine x-for :

<template x-for="post in posts">
  <h2 x-text="post.title"></h2>
</template>

I realize this would usually be done on the backend but in some cases It would be useful to display some state on the client without sending the store on every request. Or if we were streaming store updates to the client and wanted to display these updates

blinkinglight commented 3 weeks ago

no. but you can use webcomponents here to render that

delaneyj commented 3 weeks ago

Do not be afraid to go the server for your state. Embrace Hypermedia and don't accidentally recreate SPA on the frontend. If you truly have complicated state you can do as @blinkinglight says and make a webcomponent. Most likely you are over complicating it. I'm doing real-time daskboards and it's all backend drive.