unjs / unstorage

💾 Unstorage provides an async Key-Value storage API with conventional features like multi driver mounting, watching and working with metadata, dozens of built-in drivers and a tiny core.
https://unstorage.unjs.io
MIT License
1.83k stars 135 forks source link

How to perform mutations inside a store #453

Open Rednas83 opened 5 months ago

Rednas83 commented 5 months ago

Something like

store.patch({
  count: store.count + 1,
  age: 120,
  name: 'DIO',
})

OR

store.patch((state) => {
  state.items.push({ name: 'shoes', quantity: 1 })
  state.hasChanged = true
})
Rednas83 commented 5 months ago

Sorry, just found it in the docs. Even possible with setItem I see. That's cool🚀 image

Not sure yet how to push to an array yet.

Something like this

store.patch((state) => {
  state.items.push({ name: 'shoes', quantity: 1 })
  state.hasChanged = true
})

Is that also possible?

Rednas83 commented 4 months ago

Any thoughts?