Immer: Property drilling on empty object

Created on 19 Mar 2019  ยท  1Comment  ยท  Source: immerjs/immer

๐Ÿš€ Feature Proposal

It would make it possible to do something like this

const result = produce({}, (draft) => {draft.foo.bar.baz = 2})

where result would be

{
  foo: {
    bar: {
      baz: 2
    }
  }

Motivation

It would allow creating desired objects from empty objects without boilerplate.

proposal wontfix

Most helpful comment

There are packages that already support this (nevernull from the top of
my head).

It should not be part of Immer imho for several reasons:

  1. It doesn't fit the philosophy where we leverage existing mutable
    javascript constructs to create immutable objects
  2. This wouldn't be polyfillable to ES5
  3. This is not the problem immer tries to solve, and could just as well
    solved by another package. making it available by default in produce would
    be a matter of simple composition from there.

On Tue, Mar 19, 2019 at 5:54 PM Adam Pietrasiak notifications@github.com
wrote:

๐Ÿš€ Feature Proposal

It would make it possible to do something like this

const result = produce({}, (draft) => {draft.foo.bar.baz = 2})

where result would be

{

foo: {

bar: {

  baz: 2

}

}

Motivation

It would allow creating desired objects from empty objects without
boilerplate.

โ€”
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/mweststrate/immer/issues/337, or mute the thread
https://github.com/notifications/unsubscribe-auth/ABvGhNl2atSvbxdDzHdpODju9GXx1iPzks5vYRZPgaJpZM4b8ox6
.

>All comments

There are packages that already support this (nevernull from the top of
my head).

It should not be part of Immer imho for several reasons:

  1. It doesn't fit the philosophy where we leverage existing mutable
    javascript constructs to create immutable objects
  2. This wouldn't be polyfillable to ES5
  3. This is not the problem immer tries to solve, and could just as well
    solved by another package. making it available by default in produce would
    be a matter of simple composition from there.

On Tue, Mar 19, 2019 at 5:54 PM Adam Pietrasiak notifications@github.com
wrote:

๐Ÿš€ Feature Proposal

It would make it possible to do something like this

const result = produce({}, (draft) => {draft.foo.bar.baz = 2})

where result would be

{

foo: {

bar: {

  baz: 2

}

}

Motivation

It would allow creating desired objects from empty objects without
boilerplate.

โ€”
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/mweststrate/immer/issues/337, or mute the thread
https://github.com/notifications/unsubscribe-auth/ABvGhNl2atSvbxdDzHdpODju9GXx1iPzks5vYRZPgaJpZM4b8ox6
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cakoose picture cakoose  ยท  6Comments

dfadev picture dfadev  ยท  6Comments

toli444 picture toli444  ยท  6Comments

drcmda picture drcmda  ยท  6Comments

Knacktus picture Knacktus  ยท  5Comments