stockroom
stockroom copied to clipboard
Can't delete nested object from store
When used with unistore
is impossible to delete / remove a nested object or property.
See the following example ( This code only works using unistore
without stockroom
)
// Store
const state = {
collections: {
items: {
a: { ... },
b: { ... },
c: { ... },
}
// ...
}
// ...
}
// Action
removeItem({ collections }, id) {
let items = collections.items;
// Remove item
if (items[id]) {
const { [id]: removed, ...rest } = items;
items = rest;
}
return { collections: { ...collections, items } };
},
Unistore only example (working demo)
Is there any workaround on this issue ?
@btzr-io the workaround would be to set the property's value to undefined
:
// Action
removeItem({ collections }, id) {
let items = { ...collections.items };
items[id] = undefined;
return { collections: { ...collections, items } };
},