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,6 +71,7 @@ export default class JSONNode extends Component {
] ]
if (data.expanded) { if (data.expanded) {
if (data.props.length > 0) {
const props = data.props.map(prop => { const props = data.props.map(prop => {
return h(JSONNode, { return h(JSONNode, {
parent: this, parent: this,
@ -81,11 +82,13 @@ export default class JSONNode extends Component {
}) })
}) })
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,6 +106,7 @@ export default class JSONNode extends Component {
] ]
if (data.expanded) { if (data.expanded) {
if (data.items.length > 0) {
const items = data.items.map((child, index) => { const items = data.items.map((child, index) => {
return h(JSONNode, { return h(JSONNode, {
parent: this, parent: this,
@ -112,12 +116,13 @@ export default class JSONNode extends Component {
events events
}) })
}) })
contents.push(h('ul', {key: 'items', class: 'jsoneditor-list'}, items))
if (items.length === 0) { }
items.push(this.renderAppend('(empty array)')) 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) 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))