Open Enteee opened 5 years ago
We did something similar. Our implementation:
export function fromJSGreedy(js) {
switch (true) {
case ((typeof js) !== "object"): // primitive or function
case (js === null):
case (js instanceof Date): // Date objects should not be converted
case (Record.isRecord(js)): // Immutable Record
return js;
case (isCollection(js)):
return js.map(fromJSGreedy); // Immutable Collection (Map/List/Set/Seq/etc)
case (Array.isArray(js)): // turn arrays into Lists
return Seq(js).map(fromJSGreedy).toList();
default: // turn POJOs and class instances into Maps
return Seq(js).map(fromJSGreedy).toMap();
}
}
I would suggest changing the
fromJSGreedy
/fromJSOrdered
functions, documented in the wiki, to exclude immutable collections provided by this module. This is in order to preserve value identity on subsequent calls.Suggestion: