filter y-xml when domFilter is set

This commit is contained in:
Kevin Jahns
2017-12-21 16:05:50 +01:00
parent 8f3bd7170a
commit f5d17e6236
2 changed files with 20 additions and 3 deletions

View File

@@ -143,6 +143,23 @@ export default class YXmlFragment extends YArray {
}
setDomFilter (f) {
this._domFilter = f
let attributes = new Map()
if (this.getAttributes !== undefined) {
let attrs = this.getAttributes()
for (let key in attrs) {
attributes.set(key, attrs[key])
}
}
let result = this._domFilter(this.nodeName, new Map(attributes))
if (result === null) {
this._delete(this._y)
} else {
attributes.forEach((value, key) => {
if (!result.has(key)) {
this.removeAttribute(key)
}
})
}
this.forEach(xml => {
xml.setDomFilter(f)
})