src/dag/index.js
function copy() {
  const nodes = [];
  const cnodes = [];
  const mapping = {};
  this.each((node) => {
    nodes.push(node);
    const cnode = new Node(node.id, node.data);
    cnodes.push(cnode);
    mapping[cnode.id] = cnode;
  });

  cnodes.forEach((cnode, i) => {
    const node = nodes[i];
    cnode.children = node.children.map((c) => mapping[c.id]);
  });

  if (this.id === undefined) {
    const root = new Node(undefined, undefined);
    root.children = this.children.map((c) => mapping[c.id]);
  } else {
    return mapping[this.id];
  }
}
function copy() {
  const nodes = [];
  const cnodes = [];
  const mapping = {};
  this.each((node) => {
    nodes.push(node);
    const cnode = new Node(node.id, node.data);
    cnodes.push(cnode);
    mapping[cnode.id] = cnode;
  });

  cnodes.forEach((cnode, i) => {
    const node = nodes[i];
    cnode.children = node.children.map((c) => mapping[c.id]);
  });

  if (this.id === undefined) {
    const root = new Node(undefined, undefined);
    root.children = this.children.map((c) => mapping[c.id]);
  } else {
    return mapping[this.id];
  }
}
function copy ( ) { const nodes = [ ] ; const cnodes = [ ] ; const mapping = { } ; this . each ( ( node ) => { nodes . push ( node ) ; const cnode = new Node ( node . id , node . data ) ; cnodes . push ( cnode ) ; mapping [ cnode . id ] = cnode ; } ) ; cnodes . forEach ( ( cnode , i ) => { const node = nodes [ i ] ; cnode . children = node . children . map ( ( c ) => mapping [ c . id ] ) ; } ) ; if ( this . id === undefined ) { const root = new Node ( undefined , undefined ) ; root . children = this . children . map ( ( c ) => mapping [ c . id ] ) ; } else { return mapping [ this . id ] ; } }
Must be internal for new Node creation Copy this dag returning a new DAG pointing to the same data with same structure.
Must be internal for new Node creation Copy this dag returning a new DAG pointing to the same data with same structure .