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

[Docs] ArrayRemove: a note about non-primitive values #280

Open
louisameline opened this issue Nov 29, 2019 · 0 comments
Open

[Docs] ArrayRemove: a note about non-primitive values #280

louisameline opened this issue Nov 29, 2019 · 0 comments

Comments

@louisameline
Copy link
Collaborator

louisameline commented Nov 29, 2019

Something which is pretty obvious for someone a little experience, but still might be worth a note in the docs:

state.array = [{ a: 1, b: 1 }]
dispatch('module/patch', { array: arrayRemove({ a: 1, b: 1 })})

Will remove the object at Firestore, but not locally, hence creating a sync issue.
This is how to do it:

state.array = [{ a: 1, b: 1 }]
dispatch('module/patch', { array: arrayRemove(state.array[0]) })

Same goes for arrayUnion, it is up to the user to check if the array doesn't already contain the value before triggering the action:

state.array = [.......]
const el = state.array.find(v => (v.a === 1 && v.b === 1)) || { a: 1, b: 1 }
dispatch('module/patch', { array: arrayRemove(el) })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant