Closed tivac closed 7 years ago
That seems like a great idea! Something like newGraph = oldGraph.clone()
.
It would have to do a deep-copy of the nodes as arbitrary data can be stored there as of the latest release.
Do you want to implement it and submit a PR? Otherwise, I'll can probably take a look in a few days!
I don't have a ton of free time for a PR right now, I've just gone ahead and built a simplified version for my use-case (where I don't store arbitrary node data).
https://github.com/tivac/modular-css/blob/master/src/lib/clone-graph.js
Cloning the arbitrary data storage part is gonna complicate things, I wonder what the right approach there would even be?
Probably something similar to the Structured Clone Algorithm - though that's pretty complex.
I might just start with a clone implementation that doesn't copy the data (or just does a shallow copy of the data) that has a caveat in the API docs.
Based on my needs that sounds like a great first step!
Finally got around to this - it's in version 0.6.0
@jriecken oh awesome! I got my workaround in and kinda forgot about this issue, for which I apologize. I'll give 0.6.0 a whirl when I can, thanks!
First, I :heart:
dependency-graph
and thank you so much for making it. :+1: x :100:I've got a use-case where I need to create a copy/clone of an existing graph. It'd be really handy to that built-in so I'm not accessing private-ish properties on the graph to manually create clones of them. Thoughts?