Mobx: toJS make set obj to array

Created on 15 Oct 2020  Â·  3Comments  Â·  Source: mobxjs/mobx

Intended outcome:
toJS make set to array

Actual outcome:
expect set obj

How to reproduce the issue:

let mobx = require("mobx");
let a = mobx.observable(new Set());
console.log(mobx.toJS(a)); // []  expect Set {}

Versions
Mobx:4.15.7

💀 wontfix

Most helpful comment

Actually, it's working correctly in V6, so if need this, you have to upgrade ;)

https://codesandbox.io/s/heuristic-fire-z2szs?file=/src/index.js

All 3 comments

Just to note here if turns out to be a bug (I am not sure), you will need to upgrade to MobX 6, we no longer support previous versions.

Actually, it's working correctly in V6, so if need this, you have to upgrade ;)

https://codesandbox.io/s/heuristic-fire-z2szs?file=/src/index.js

Note that in v4 / v5 it is possible to set exportMapsAsObjects option, that achieves the same (despite the name also works for sets). https://github.com/mobxjs/mobx/blob/mobx4and5/docs/refguide/tojson.md

Was this page helpful?
0 / 5 - 0 ratings