-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
Hi! This seems like a really promising library for debugging complex JS applications :) Or serialising complex JS objects.
In our code, we often use Map
, but references in there get copied by value. Is there a way to generate JS code that will construct the full JS object?
var serialize = require('serialize-to-js')
var fooBar = {foo:"bar"}
let m = new Map()
m.set('key1', fooBar)
m.set('key2', fooBar)
var obj = {
ref1: fooBar,
ref2: fooBar,
ref3: fooBar,
m: m,
}
var opts = { reference: true }
var withoutRefs = serialize(obj, opts)
console.log(opts.references)
var refsCode = "var tmp = " + withoutRefs + ";\n"
for(var i = 0; i < opts.references.length; i+= 1){
var entry = opts.references[i];
refsCode += "tmp" + entry[0] + " = tmp" + entry[1] + ";\n"
}
console.log(refsCode)
// var tmp = {ref1: {foo: "bar"}}
// tmp.ref2 = tmp.ref1;
// tmp.ref3 = tmp.ref1;
// The refs in the map are missing :(
Metadata
Metadata
Assignees
Labels
No labels