cuire / svelte-grid-extended

A draggable and resizable grid layout, for Svelte
https://svelte-grid-extended.vercel.app
MIT License
78 stars 9 forks source link

[Feature] Support stores #20

Closed joakim closed 1 year ago

joakim commented 1 year ago

I have a store that's an array of objects representing items in the grid.

It would be really nice to be able to do just this and have the grid reflect any changes reactively:

<script>
  import Thing from './Thing.svelte'
  import { things } from '../stores/things'
  let items = derived(things, mapThingsToItems)
</script>

<Grid {items} cols={10} rows={10} let:item>
  <Thing data={item.data} />
</Grid>
joakim commented 1 year ago

Sorry, I'm obviously still a n00b when it comes to Svelte. Didn't realize I could do this:

<Grid items={$items} …
cuire commented 1 year ago

@joakim, I think you will find it useful, that you can also bind the store to items, so the grid component updates store value, when grid changes. https://svelte.dev/repl/7a08b5f150dc432480ae321147324d43?version=3.55.1

joakim commented 1 year ago

Thanks, @cuire! It's exactly what I was working on, so that was very useful indeed :)