lukeed / dset

A tiny (194B) utility for safely writing deep Object values~!
MIT License
754 stars 22 forks source link

Strange bug using dset with mobx #27

Open filippodossena-mozart opened 2 years ago

filippodossena-mozart commented 2 years ago

I noticed that there is a weird bug when using dset with mobx:

dset(data, "a.b.c", 1)

If data is an mobx observable (a deep and proxied one), dset will set only the first key a with an empty object. The result will be:

{ a: {} }

instead of

{ a: { b: { c: 1 } } }

It happens only when using deep and proxy options in mobx (that are the default options).

Struggling with it, I found out that it is the multiple assignment used in dset function that breaks it. It can be fixed splitting the multiple assignment into 2 different lines.

I created a sandbox that shows everything I state here (fix included): https://codesandbox.io/s/dset-mobx-issue-x99gw