Fixed optional types of flow
This commit is contained in:
parent
86f8aa56d0
commit
2ee11399ec
|
@ -43,7 +43,7 @@ export default class JSONEditor extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
componentWillReceiveProps (nextProps: {mode: ?string}) {
|
||||
componentWillReceiveProps (nextProps: {mode?: string}) {
|
||||
if (nextProps.mode !== this.props.mode) {
|
||||
this.setState({ mode: nextProps.mode })
|
||||
}
|
||||
|
|
|
@ -165,7 +165,7 @@ export default class JSONNode extends Component {
|
|||
}
|
||||
|
||||
// TODO: simplify the method renderProperty
|
||||
renderProperty (prop: ?PropertyData, index: ?number, data: JSONData, options: {escapeUnicode: boolean, isPropertyEditable: (Path) => boolean}) {
|
||||
renderProperty (prop?: PropertyData, index?: number, data: JSONData, options: {escapeUnicode: boolean, isPropertyEditable: (Path) => boolean}) {
|
||||
const isIndex = typeof index === 'number'
|
||||
|
||||
if (!prop && !isIndex) {
|
||||
|
@ -325,7 +325,7 @@ export default class JSONNode extends Component {
|
|||
/**
|
||||
* Get the css style given a search result type
|
||||
*/
|
||||
static getSearchResultClass (searchResultStatus: ?SearchResultStatus) {
|
||||
static getSearchResultClass (searchResultStatus?: SearchResultStatus) {
|
||||
if (searchResultStatus === 'active') {
|
||||
return ' jsoneditor-highlight-active'
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ export default class JSONNodeForm extends JSONNode {
|
|||
}
|
||||
|
||||
// render a readonly property
|
||||
renderProperty (prop: ?PropertyData, index: ?number, data: JSONData, options: {escapeUnicode: boolean, isPropertyEditable: (Path) => boolean}) {
|
||||
renderProperty (prop?: PropertyData, index?: number, data: JSONData, options: {escapeUnicode: boolean, isPropertyEditable: (Path) => boolean}) {
|
||||
const formOptions = Object.assign({}, options, { isPropertyEditable })
|
||||
|
||||
return JSONNode.prototype.renderProperty.call(this, prop, index, data, formOptions)
|
||||
|
|
|
@ -31,7 +31,7 @@ export function expandAll (path) {
|
|||
* @param {JSONDataType} [type='value'] Optional json data type for the created value
|
||||
* @return {JSONData}
|
||||
*/
|
||||
export function jsonToData (json, expand = expandAll, path = [], type = 'value') {
|
||||
export function jsonToData (json, expand = expandAll, path = [], type = 'value') : JSONData {
|
||||
if (Array.isArray(json)) {
|
||||
return {
|
||||
type: 'Array',
|
||||
|
@ -57,7 +57,7 @@ export function jsonToData (json, expand = expandAll, path = [], type = 'value')
|
|||
})
|
||||
}
|
||||
}
|
||||
else {
|
||||
else { // value
|
||||
return {
|
||||
type,
|
||||
value: json
|
||||
|
@ -166,7 +166,7 @@ export function expand (data: JSONData, callback: Path | (Path) => boolean, expa
|
|||
/**
|
||||
* Expand all Objects and Arrays on a path
|
||||
*/
|
||||
export function expandPath (data: JSONData, path: ?Path) : JSONData {
|
||||
export function expandPath (data: JSONData, path?: Path) : JSONData {
|
||||
let updatedData = data
|
||||
|
||||
if (path) {
|
||||
|
|
|
@ -207,7 +207,7 @@ export function remove (data: JSONData, path: string) {
|
|||
* @param {JSONPatch} patch
|
||||
* @return {Array}
|
||||
*/
|
||||
function simplifyPatch(patch: JSONPatch) {
|
||||
export function simplifyPatch(patch: JSONPatch) {
|
||||
const simplifiedPatch = []
|
||||
const paths = {}
|
||||
|
||||
|
|
10
src/types.js
10
src/types.js
|
@ -39,7 +39,7 @@ export type PropertyData = {
|
|||
id: number,
|
||||
name: string,
|
||||
value: JSONData,
|
||||
searchResult: ?SearchResultStatus
|
||||
searchResult?: SearchResultStatus
|
||||
}
|
||||
|
||||
export type ItemData = {
|
||||
|
@ -49,20 +49,20 @@ export type ItemData = {
|
|||
|
||||
export type ObjectData = {
|
||||
type: 'Object',
|
||||
expanded: ?boolean,
|
||||
expanded?: boolean,
|
||||
props: PropertyData[]
|
||||
}
|
||||
|
||||
export type ArrayData = {
|
||||
type: 'Array',
|
||||
expanded: ?boolean,
|
||||
expanded?: boolean,
|
||||
items: ItemData[]
|
||||
}
|
||||
|
||||
export type ValueData = {
|
||||
type: 'value' | 'string',
|
||||
value: ?any,
|
||||
searchResult: ?SearchResultStatus
|
||||
value?: any,
|
||||
searchResult?: SearchResultStatus
|
||||
}
|
||||
|
||||
export type JSONData = ObjectData | ArrayData | ValueData
|
||||
|
|
Loading…
Reference in New Issue