Skip to content

Don't default missing key on set #25

@stramel

Description

@stramel

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 []

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions