Skip to content

Conversation

@Limycuk
Copy link

@Limycuk Limycuk commented May 17, 2019

JavaScript Object needs method "unset" for immutable removing property from object

@roginvs
Copy link

roginvs commented May 20, 2019

You can use rest operator in objects:

const {
  removedProp,
  ...restProps
} = myObject;

@Limycuk
Copy link
Author

Limycuk commented May 20, 2019

You can use rest operator in objects:

const {
  removedProp,
  ...restProps
} = myObject;

And you will have eslint error "'removedProp' is defined but never used eslint (no-unused-vars)"
It's not a solution, it's way to hack

And if you need delete deep property, your solution doesn't short and usable

@roginvs
Copy link

roginvs commented May 20, 2019

And you will have eslint error "'removedProp' is defined but never used eslint (no-unused-vars)"

ESLint is right. If you need to remove prop without using it then you probably doing something wrong.

@Limycuk
Copy link
Author

Limycuk commented May 20, 2019

And you will have eslint error "'removedProp' is defined but never used eslint (no-unused-vars)"

ESLint is right. If you need to remove prop without using it then you probably doing something wrong.

For example, your application is Chat like Telegram. You have stored normalized list of contacts in Redux (immutable store)

var contacts = {
  153: { id: 154, username: ... },
  245: { id: 245, username: ... },
  ...
  455: { id: 455, username: ...},
}

And if you want to remove contact by id, how do you can to do it?

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.

2 participants