Merge 38bd3a35c5f4078454d573f9815377e799cfb599 into ad0d915794713a4cfb6c0fc32a3b998278301b36
This commit is contained in:
commit
2e79ded620
@ -25,7 +25,7 @@ import {
|
||||
* * An YXmlElement has attributes (key value pairs)
|
||||
* * An YXmlElement has childElements that must inherit from YXmlElement
|
||||
*
|
||||
* @template {{ [key: string]: ValueTypes }} [KV={ [key: string]: string }]
|
||||
* @template {{ [key: string]: ValueTypes }} [KV={ [key: string]: string | number }]
|
||||
*/
|
||||
export class YXmlElement extends YXmlFragment {
|
||||
constructor (nodeName = 'UNDEFINED') {
|
||||
@ -94,7 +94,7 @@ export class YXmlElement extends YXmlFragment {
|
||||
const el = new YXmlElement(this.nodeName)
|
||||
const attrs = this.getAttributes()
|
||||
object.forEach(attrs, (value, key) => {
|
||||
if (typeof value === 'string') {
|
||||
if (typeof value === 'string' || typeof value === 'number') {
|
||||
el.setAttribute(key, value)
|
||||
}
|
||||
})
|
||||
@ -226,8 +226,8 @@ export class YXmlElement extends YXmlFragment {
|
||||
const attrs = this.getAttributes()
|
||||
for (const key in attrs) {
|
||||
const value = attrs[key]
|
||||
if (typeof value === 'string') {
|
||||
dom.setAttribute(key, value)
|
||||
if (typeof value === 'string' || typeof value === 'number') {
|
||||
dom.setAttribute(key, String(value))
|
||||
}
|
||||
}
|
||||
typeListForEach(this, yxml => {
|
||||
|
@ -195,6 +195,25 @@ export const testClone = _tc => {
|
||||
t.compare(cloneYxml.toJSON(), yxml.toJSON())
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {t.TestCase} _tc
|
||||
*/
|
||||
export const testCloneElementAttributes = _tc => {
|
||||
const ydoc = new Y.Doc()
|
||||
const yxml = ydoc.getXmlFragment()
|
||||
const first = new Y.XmlText('text')
|
||||
const second = new Y.XmlElement('p')
|
||||
second.setAttribute('answer', 42)
|
||||
const third = new Y.XmlElement('p')
|
||||
third.setAttribute('question', 'unknown')
|
||||
yxml.push([first, second, third])
|
||||
t.compareArrays(yxml.toArray(), [first, second, third])
|
||||
const cloneYxml = yxml.clone()
|
||||
ydoc.getArray('copyarr').insert(0, [cloneYxml])
|
||||
t.assert(cloneYxml.length === 3)
|
||||
t.compare(cloneYxml.toJSON(), yxml.toJSON())
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {t.TestCase} _tc
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user