Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't delete nested object from store #23

Open
btzr-io opened this issue Mar 7, 2019 · 2 comments
Open

Can't delete nested object from store #23

btzr-io opened this issue Mar 7, 2019 · 2 comments

Comments

@btzr-io
Copy link

btzr-io commented Mar 7, 2019

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)

Edit Unistore Demo

@btzr-io
Copy link
Author

btzr-io commented Mar 7, 2019

Is there any workaround on this issue ?

@developit
Copy link
Owner

@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 } };
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants