@stevekwak, is it possible to convert this topic to feature request? Suggested library seems to be an overhead way to convert objects tree into json (e.g. if properties list change library should be adjusted as well).
As quick fix it might be:
make properties enumerable;
adjust types (by some reason typeof removeFromParent is object).
In general it will be great to have toJson method which will do all the job in async manner.
For now serializing of default document (which goes with xd to show functionality) to json takes 118 secs and make xd unresponsive. Is there any way to call it async right now? And it’s just 9 artboards. How it will work if it will be 70 artboards with much more complex layout?
As the next step I need to export artboards previews and zip them. I’m afraid all these operations will put Xd on freeze for a much longer time.
UPD: It seems that the slowest operation in my case was console.log. I dropped mostly all of them and time reduced to couple seconds
OK I’ve improved the code a bit to prevent the loops - it now only considers plain types from Object.keys which I think is what we want. I added the following at line 43:
// also pull any plain types from Object.keys - be careful of initite loops!
for(const key of Object.keys(value)){
if (skipFields.indexOf(key) > -1 || key[0] === "_" || !isPlainType(value[key])) {
continue;
}
json[key] = value[key];
}
Thank you! Very good point! I made slightly different fix based on the points of inheritance and magic XD crashes. I just do not iterate over elements which extends Objects or something weird called “” (empty string). So plain type check now looks like:
return (!value
|| ["object", "function"].indexOf(typeof value) === -1
|| value instanceof Date
|| ["Object", ""].indexOf(Object.getPrototypeOf(value).constructor.name) > -1);
You are completely right! I made another attempt by including Object.keys into getDescriptors as value might be complex object (e.g. color stops for linear gradient) and will be filtered out by isPlainType.
I removed your new plain type thing (line 72) and then tracked down the infinite loop. It’s in the key triggeredInteractions, so I added that to skipFields. Seems to be running OK now, until we find the next problem
edit: I’ve added incomingInteractions and selected to skipFields too. How would you feel about open sourcing this to github/npm @gdreyv? Just so we don’t have to post here every time we find something I’m happy to host on https://github.com/zeroheight if you don’t have time to put it up
What about selected field? How can I reproduce it? The point about interaction is to replace real nodes with references to keep data but prevent infinite loops.
yeah sorry, selected is fine. For my particular use-case it’s irrelevant because I’m trying to see if the node has changed or not (which isn’t affected by whether it’s selected or not).
yeah I think we can fix the infinite loops if we add a bit more logic - we just need to ensure that Action is properly handled so destination or overlay don’t get fully expanded. Obviously we are trying to avoid “special cases”, as that’s the whole point of doing it this way vs. manually mapping all the classes, but yeah I see your related discussion in typeof(scenegraph.SceneNode) is undefined - #7 by gdreyv so hopefully we can find something generic
heh yeah but I guess we don’t know how long “temporary” is. I don’t personally use Typescript so it would need a bit more work to make it ingestible in my plugin - will PR if I get any time
@kerrishotts do you have any updates on that? It’s weird that we can’t serialize js objects into json.
For I’m facing multiple exceptions on custom serialization e.g. trying to access horizontalConstraints on Symbol throws parent not defined error.