From 611db9c4316e5fb8a0636f34a3b441da37cef817 Mon Sep 17 00:00:00 2001 From: jos Date: Fri, 16 Sep 2016 20:37:07 +0200 Subject: [PATCH] Removed `name` from global options --- src/TreeMode.js | 11 ++++------- src/jsonData.js | 1 + 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/TreeMode.js b/src/TreeMode.js index 1228548..232e333 100644 --- a/src/TreeMode.js +++ b/src/TreeMode.js @@ -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? diff --git a/src/jsonData.js b/src/jsonData.js index 4896b47..beaf8ce 100644 --- a/src/jsonData.js +++ b/src/jsonData.js @@ -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