javascript - Can you use Immutable fromJS() on an object that already partially contains Immutable objects? -
i have plain javascript object want convert immutable map using "fromjs()". however, want 1 of fields, supplier.selectedindices
set()
. default, fromjs() converts list()
. can following in plain javascript object, initiate set()
object?
is practice? please advise. thanks!
export const initialstate = fromjs({ inventory: { inventory: [], selectedinventory: [], }, supplier: { suppliers: [], selectedindices: set(), }, });
to answer title, using fromjs
on mixed objects safe. docs sort of mention that:
fromjs conservative in conversion. convert arrays pass array.isarray lists, , raw objects (no custom prototype) map.
immutable collections don't match criteria.
to answer body of question, fromjs
provides reviver
:
if reviver optionally provided, called every collection seq (beginning nested collections , proceeding top-level collection itself), along key refering each collection , parent js object provided this. top level, object, key "". reviver expected return new immutable collection, allowing custom conversions deep js objects. finally, path provided sequence of keys value starting value.
the reviver
function should able detect field (either using value type or path provided immutable) , create set
.
Comments
Post a Comment