Skip to content

Add delete mutability helper #2906

@flying-sheep

Description

@flying-sheep

JS sparse arrays have some advantages.

Setting elements to undefined isn’t the same as deleting them, e.g. [1,,,3].map(console.log) only prints 1 3, not 1 undefined undefined 3.

Therefore there should be a mutability helper that returns a copy with a deleted entry:

{ update } = React.addons

let a = [1,,,2,,3]
let b = update(a, {$delete: 1})

console.log(a)  // → [1, undefined×2, 2, undefined×1, 3]
console.log(b)  // → [1, undefined×4, 3]

PS: the same of course also applies to objects: {foo: undefined} isn’t the same as {}.

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