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 {
expand,
jsonToData, dataToJson, toDataPath, patchData, compileJSONPointer
expand, jsonToData, dataToJson, toDataPath, patchData, compileJSONPointer
} from './jsonData'
import {
duplicate, insert, append, changeType, changeValue, changeProperty, sort
@ -16,15 +15,12 @@ export default class TreeMode extends Component {
constructor (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 data = jsonToData([], this.props.data || {}, expand)
this.state = {
options: {
name
name: null
},
data,
@ -248,10 +244,11 @@ export default class TreeMode extends Component {
* @param {SetOptions} [options]
*/
set (json, options = {}) {
const name = options && options.name || null // the root name
const data = jsonToData([], json, options.expand || TreeMode.expand)
this.setState({
options: setIn(this.state.options, ['name'], options && options.name || null),
options: setIn(this.state.options, ['name'], name),
data,
// 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)
let newValue = jsonToData(path, action.value, expand)
// TODO: move setting type to jsonToData
if (action.jsoneditor && action.jsoneditor.type) {
// insert with type 'string' or 'value'
newValue.type = action.jsoneditor.type