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

Don't default missing key on set #25

Open
stramel opened this issue May 11, 2018 · 0 comments
Open

Don't default missing key on set #25

stramel opened this issue May 11, 2018 · 0 comments

Comments

@stramel
Copy link

stramel commented May 11, 2018

currently, if I have

const state = {}

and I attempt to update the state with devices like so,

const id = '123'
dotProp.set(state, 'devices', list => [...list, id])

I will get an error because list is being defaulted to an object. Instead it would be nice to leave that as undefined for the user to be able to use default params to have better control. So instead it would look like this,

const id = '123'
dotProp.set(state, 'devices', (list = []) => [...list, id])

or if I want my devices to be an object keyed on the ids I could do something like,

const device = {id:'123'}
dotProp.set(state, 'devices', (devices = {}) => {...devices, device})

An alternative approach would be to have a optional parameter at the end to change the default value from {} to []

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

1 participant