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

View File

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