A bit more refactoring

This commit is contained in:
jos 2017-01-05 11:18:38 +01:00
parent 9f81dfb2f6
commit afcf19bac5
2 changed files with 27 additions and 28 deletions

View File

@ -30,7 +30,8 @@
"javascript-natural-sort": "0.7.1", "javascript-natural-sort": "0.7.1",
"lodash": "4.17.2", "lodash": "4.17.2",
"react": "15.4.1", "react": "15.4.1",
"react-dom": "15.4.1" "react-dom": "15.4.1",
"react-scroll": "1.4.4"
}, },
"devDependencies": { "devDependencies": {
"ava": "0.17.0", "ava": "0.17.0",

View File

@ -1,7 +1,7 @@
// @flow weak // @flow weak
import { createElement as h, Component } from 'react' import { createElement as h, Component } from 'react'
import { Element as ScrollElement } from 'react-scroll' //import { Element as ScrollElement } from 'react-scroll'
import ActionButton from './menu/ActionButton' import ActionButton from './menu/ActionButton'
import AppendActionButton from './menu/AppendActionButton' import AppendActionButton from './menu/AppendActionButton'
@ -41,16 +41,15 @@ export default class JSONNode extends Component {
renderJSONObject ({prop, index, data, options, events}) { renderJSONObject ({prop, index, data, options, events}) {
const childCount = data.props.length const childCount = data.props.length
const contents = [ const node = h('div', {key: 'node', className: 'jsoneditor-node jsoneditor-object'}, [
h('div', {key: 'node', className: 'jsoneditor-node jsoneditor-object'}, [
this.renderExpandButton(), this.renderExpandButton(),
this.renderActionMenuButton(), this.renderActionMenuButton(),
this.renderProperty(prop, index, data, options), this.renderProperty(prop, index, data, options),
this.renderReadonly(`{${childCount}}`, `Array containing ${childCount} items`), this.renderReadonly(`{${childCount}}`, `Array containing ${childCount} items`),
this.renderError(data.error) this.renderError(data.error)
]) ])
]
let childs
if (data.expanded) { if (data.expanded) {
if (data.props.length > 0) { if (data.props.length > 0) {
const props = data.props.map(prop => { const props = data.props.map(prop => {
@ -65,32 +64,31 @@ export default class JSONNode extends Component {
) )
}) })
contents.push(h('ul', {key: 'props', className: 'jsoneditor-list'}, props)) childs = h('ul', {key: 'childs', className: 'jsoneditor-list'}, props)
} }
else { else {
contents.push(h('ul', {key: 'append', className: 'jsoneditor-list'}, childs = h('ul', {key: 'childs', className: 'jsoneditor-list'},
h('li', {}, h('li', {},
this.renderAppend('(empty object)') this.renderAppend('(empty object)')
) )
)) )
} }
} }
return h('div', {}, contents) return h('div', {}, [node, childs])
} }
renderJSONArray ({prop, index, data, options, events}) { renderJSONArray ({prop, index, data, options, events}) {
const childCount = data.items.length const childCount = data.items.length
const contents = [ const node = h('div', {key: 'node', className: 'jsoneditor-node jsoneditor-array'}, [
h('div', {key: 'node', className: 'jsoneditor-node jsoneditor-array'}, [
this.renderExpandButton(), this.renderExpandButton(),
this.renderActionMenuButton(), this.renderActionMenuButton(),
this.renderProperty(prop, index, data, options), this.renderProperty(prop, index, data, options),
this.renderReadonly(`[${childCount}]`, `Array containing ${childCount} items`), this.renderReadonly(`[${childCount}]`, `Array containing ${childCount} items`),
this.renderError(data.error) this.renderError(data.error)
]) ])
]
let childs
if (data.expanded) { if (data.expanded) {
if (data.items.length > 0) { if (data.items.length > 0) {
const items = data.items.map((child, index) => { const items = data.items.map((child, index) => {
@ -104,18 +102,18 @@ export default class JSONNode extends Component {
}) })
) )
}) })
contents.push(h('ul', {key: 'items', className: 'jsoneditor-list'}, items)) childs = h('ul', {key: 'childs', className: 'jsoneditor-list'}, items)
} }
else { else {
contents.push(h('ul', {key: 'append', className: 'jsoneditor-list'}, childs = h('ul', {key: 'childs', className: 'jsoneditor-list'},
h('li', {}, h('li', {},
this.renderAppend('(empty array)') this.renderAppend('(empty array)')
) )
)) )
} }
} }
return h('div', {}, contents) return h('div', {}, [node, childs])
} }
renderJSONValue ({prop, index, data, options}) { renderJSONValue ({prop, index, data, options}) {