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

Remove deep property for REMOVE action instead of setting it to undefined #313

Merged
merged 3 commits into from Oct 29, 2017

Conversation

fej-snikduj
Copy link
Collaborator

Description

setWith sets the value to undefined, but the key remains an enumerable
property on the object. This can cause problems when your UI iterates
over keys of an object and renders based on the key’s existence. Using
unset, the key is removed.

Check List

If not relevant to pull request, check off as complete

  • All tests passing
  • Docs updated with any changes or examples if applicable
  • Added tests to ensure new feature(s) work properly

Relevant Issues

setWith sets the value to undefined, but the key remains an enumerable
property on the object. This can cause problems when your UI iterates
over keys of an object and renders based on the key’s existence. Using
unset, the key is removed.
Imagine that we have a deeply nested property
`users/userId/permissions/writeAcces` = `true`.  Then we call remove on
that permission.  `unset` will remove the `writeAccess` property.
However, the `permissions` property will remain on the `userId` object,
*regardless* of if there are any other properties on that object.  In
the case that there was no other property in `permissions`, there will
be an empty `{}` in redux-state for permissions.  *However*, in
firebase - `permissions` will not even exist.  By recursively unsetting
the property, we make sure the parent properties are also removed if
necessary.
@prescottprue
Copy link
Owner

Great work, the recursiveUnset function is nice. Going to still make dispatchRemoveAction: false the default. That way it would require a listener on a given path in order to have data removed, unless this option is enabled. It will more closely match v1.

@prescottprue prescottprue merged commit 77220df into v2.0.0-beta.14 Oct 29, 2017
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

Successfully merging this pull request may close these issues.

None yet

2 participants