Immer: Saving nested drafts

Created on 27 Dec 2018  路  6Comments  路  Source: immerjs/immer

  • [ ] Issue: Forking nested results

    • Version: 1.9.3
    • _SIMPLE_ Reproduction: https://codesandbox.io/s/lrqmlj5pwm
    • Expected behavior:
      I want to be able to save the result of a nested producer for later use.

    • Observed behavior:
      Nested result is unusable once revoked by the parent producer.

    • [ x] Occurs when using Proxies (use setUseProxies(true))

    • [ x] Occurs in the ES5 implementation (use setUseProxies(false))
question

All 6 comments

Currently, if you want a nested produce call to actually produce a __copy__, you must pass state to the original function export __before__ calling produce (example). Otherwise, your nested producer will be mutating its parent's draft (example).

The behavior without original __will change__ in the future, but using original on the draft before calling produce will (probably) always be supported.

I want the nested producer to mutate it's parent's draft and not the original state:

https://codesandbox.io/s/v0q1ljppm0

@dfadev Oh, right. My bad!

That's not currently possible! 馃槥

I might be working on a solution sometime soon. You'll find out if this gets fixed! 馃憤

Ah, just realized what I'm working on won't directly address your issue.

Is there a reason you can't structure your code this way?

I think you're right, it's better to not nest if I need those states later on. Thanks!

@aleclarson Would you mind restoring the sandbox you're pointing to in your last comment? It seems helpful to people landing on this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

atrifyllis picture atrifyllis  路  6Comments

Knacktus picture Knacktus  路  5Comments

vidarc picture vidarc  路  3Comments

mweststrate picture mweststrate  路  4Comments

FredyC picture FredyC  路  4Comments