Merge pull request #310 from SamDuvall/fix-xml-clone
Fix XmlElement.clone and XmlFragment.clone
This commit is contained in:
		
						commit
						0ea0a35521
					
				@ -82,7 +82,7 @@ export class YXmlElement extends YXmlFragment {
 | 
				
			|||||||
      el.setAttribute(key, attrs[key])
 | 
					      el.setAttribute(key, attrs[key])
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    // @ts-ignore
 | 
					    // @ts-ignore
 | 
				
			||||||
    el.insert(0, el.toArray().map(item => item instanceof AbstractType ? item.clone() : item))
 | 
					    el.insert(0, this.toArray().map(item => item instanceof AbstractType ? item.clone() : item))
 | 
				
			||||||
    return el
 | 
					    return el
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -167,7 +167,7 @@ export class YXmlFragment extends AbstractType {
 | 
				
			|||||||
  clone () {
 | 
					  clone () {
 | 
				
			||||||
    const el = new YXmlFragment()
 | 
					    const el = new YXmlFragment()
 | 
				
			||||||
    // @ts-ignore
 | 
					    // @ts-ignore
 | 
				
			||||||
    el.insert(0, el.toArray().map(item => item instanceof AbstractType ? item.clone() : item))
 | 
					    el.insert(0, this.toArray().map(item => item instanceof AbstractType ? item.clone() : item))
 | 
				
			||||||
    return el
 | 
					    return el
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -150,3 +150,21 @@ export const testInsertafter = tc => {
 | 
				
			|||||||
    el.insertAfter(deepsecond1, [new Y.XmlText()])
 | 
					    el.insertAfter(deepsecond1, [new Y.XmlText()])
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @param {t.TestCase} tc
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					 export const testClone = tc => {
 | 
				
			||||||
 | 
					  const ydoc = new Y.Doc()
 | 
				
			||||||
 | 
					  const yxml = ydoc.getXmlFragment()
 | 
				
			||||||
 | 
					  const first = new Y.XmlText('text')
 | 
				
			||||||
 | 
					  const second = new Y.XmlElement('p')
 | 
				
			||||||
 | 
					  const third = new Y.XmlElement('p')
 | 
				
			||||||
 | 
					  yxml.push([first, second, third])
 | 
				
			||||||
 | 
					  t.compareArrays(yxml.toArray(), [first, second, third])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const cloneYxml = yxml.clone()
 | 
				
			||||||
 | 
					  t.assert(cloneYxml.length === 3)
 | 
				
			||||||
 | 
					  t.assert(cloneYxml.toJSON() === yxml.toJSON())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user