Fixed array/object not being rendered empty when removing the last item

This commit is contained in:
jos 2016-08-21 13:12:47 +02:00
parent c5a68b1da3
commit b6d622e0d0
2 changed files with 33 additions and 28 deletions

View File

@ -71,21 +71,24 @@ export default class JSONNode extends Component {
]
if (data.expanded) {
const props = data.props.map(prop => {
return h(JSONNode, {
parent: this,
prop: prop.name,
data: prop.value,
options,
events
if (data.props.length > 0) {
const props = data.props.map(prop => {
return h(JSONNode, {
parent: this,
prop: prop.name,
data: prop.value,
options,
events
})
})
})
if (props.length === 0) {
props.push(this.renderAppend('(empty object)'))
contents.push(h('ul', {key: 'props', class: 'jsoneditor-list'}, props))
}
else {
contents.push(h('ul', {key: 'append', class: 'jsoneditor-list'}, [
this.renderAppend('(empty object)')
]))
}
contents.push(h('ul', {class: 'jsoneditor-list'}, props))
}
return h('li', {}, contents)
@ -103,21 +106,23 @@ export default class JSONNode extends Component {
]
if (data.expanded) {
const items = data.items.map((child, index) => {
return h(JSONNode, {
parent: this,
prop: index,
data: child,
options,
events
if (data.items.length > 0) {
const items = data.items.map((child, index) => {
return h(JSONNode, {
parent: this,
prop: index,
data: child,
options,
events
})
})
})
if (items.length === 0) {
items.push(this.renderAppend('(empty array)'))
contents.push(h('ul', {key: 'items', class: 'jsoneditor-list'}, items))
}
else {
contents.push(h('ul', {key: 'append', class: 'jsoneditor-list'}, [
this.renderAppend('(empty array)')
]))
}
contents.push(h('ul', {class: 'jsoneditor-list'}, items))
}
return h('li', {}, contents)
@ -141,7 +146,7 @@ export default class JSONNode extends Component {
* @return {*}
*/
renderAppend (text) {
return h('li', {}, [
return h('li', {key: 'append'}, [
h('div', {class: 'jsoneditor-node'}, [
this.renderPlaceholder(),
this.renderAppendContextMenuButton(),

View File

@ -142,7 +142,7 @@ export function append (data, path, type) {
* @return {JSONData}
*/
export function duplicate (data, path, prop) {
console.log('duplicate', path)
console.log('duplicate', path, prop)
const dataPath = toDataPath(data, path)
const object = getIn(data, dataPath)
@ -181,7 +181,7 @@ export function duplicate (data, path, prop) {
* @return {JSONData}
*/
export function remove (data, path, prop) {
console.log('remove', path)
console.log('remove', path, prop)
const object = getIn(data, toDataPath(data, path))