Removed `name` from global options
This commit is contained in:
parent
3d467e65e1
commit
611db9c431
|
@ -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?
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue