Removed `name` from global options

This commit is contained in:
jos 2016-09-16 20:37:07 +02:00
parent 3d467e65e1
commit 611db9c431
2 changed files with 5 additions and 7 deletions

View File

@ -2,8 +2,7 @@ import { h, Component } from 'preact'
import { setIn, updateIn } from './utils/immutabilityHelpers' import { setIn, updateIn } from './utils/immutabilityHelpers'
import { import {
expand, expand, jsonToData, dataToJson, toDataPath, patchData, compileJSONPointer
jsonToData, dataToJson, toDataPath, patchData, compileJSONPointer
} from './jsonData' } from './jsonData'
import { import {
duplicate, insert, append, changeType, changeValue, changeProperty, sort duplicate, insert, append, changeType, changeValue, changeProperty, sort
@ -16,15 +15,12 @@ export default class TreeMode extends Component {
constructor (props) { constructor (props) {
super(props) super(props)
// TODO: don't put name and expand like this in the constructor
const name = this.props.options && this.props.options.name || null
const expand = this.props.options && this.props.options.expand || TreeMode.expand const expand = this.props.options && this.props.options.expand || TreeMode.expand
const data = jsonToData([], this.props.data || {}, expand) const data = jsonToData([], this.props.data || {}, expand)
this.state = { this.state = {
options: { options: {
name name: null
}, },
data, data,
@ -248,10 +244,11 @@ export default class TreeMode extends Component {
* @param {SetOptions} [options] * @param {SetOptions} [options]
*/ */
set (json, options = {}) { set (json, options = {}) {
const name = options && options.name || null // the root name
const data = jsonToData([], json, options.expand || TreeMode.expand) const data = jsonToData([], json, options.expand || TreeMode.expand)
this.setState({ this.setState({
options: setIn(this.state.options, ['name'], options && options.name || null), options: setIn(this.state.options, ['name'], name),
data, data,
// TODO: do we want to keep history when .set(json) is called? // TODO: do we want to keep history when .set(json) is called?

View File

@ -486,6 +486,7 @@ export function patchData (data, patch) {
const path = parseJSONPointer(action.path) const path = parseJSONPointer(action.path)
let newValue = jsonToData(path, action.value, expand) let newValue = jsonToData(path, action.value, expand)
// TODO: move setting type to jsonToData
if (action.jsoneditor && action.jsoneditor.type) { if (action.jsoneditor && action.jsoneditor.type) {
// insert with type 'string' or 'value' // insert with type 'string' or 'value'
newValue.type = action.jsoneditor.type newValue.type = action.jsoneditor.type