support undefined as an attribute value

This commit is contained in:
Kevin Jahns
2017-11-10 18:41:10 -08:00
parent c51e8b46c2
commit 290d3c8ffe
3 changed files with 39 additions and 2 deletions

View File

@@ -20,7 +20,13 @@ export default class ItemJSON extends Item {
this._content = new Array(len)
for (let i = 0; i < len; i++) {
const ctnt = decoder.readVarString()
this._content[i] = JSON.parse(ctnt)
let parsed
if (ctnt === 'undefined') {
parsed = undefined
} else {
parsed = JSON.parse(ctnt)
}
this._content[i] = parsed
}
return missing
}
@@ -29,7 +35,14 @@ export default class ItemJSON extends Item {
let len = this._content.length
encoder.writeVarUint(len)
for (let i = 0; i < len; i++) {
encoder.writeVarString(JSON.stringify(this._content[i]))
let encoded
let content = this._content[i]
if (content === undefined) {
encoded = 'undefined'
} else {
encoded = JSON.stringify(content)
}
encoder.writeVarString(encoded)
}
}
_logString () {

View File

@@ -136,6 +136,26 @@ export function applyChangesFromDom (dom) {
}
export function reflectChangesOnDom (events) {
// Make sure that no filtered attributes are applied to the structure
// if they were, delete them
events.forEach(event => {
const target = event.target
const keys = this._domFilter(target.nodeName, Array.from(event.keysChanged))
if (keys === null) {
target._delete()
} else {
const removeKeys = new Set() // is a copy of event.keysChanged
event.keysChanged.forEach(key => { removeKeys.add(key) })
keys.forEach(key => {
// remove all accepted keys from removeKeys
removeKeys.delete(key)
})
// remove the filtered attribute
removeKeys.forEach(key => {
target.removeAttribute(key)
})
}
})
this._mutualExclude(() => {
events.forEach(event => {
const yxml = event.target