Fix a bug in syncing an eson value. Cleanup old ESON types
This commit is contained in:
parent
410353c86f
commit
ec987385c8
|
@ -50,11 +50,16 @@ import { createFindKeyBinding } from '../utils/keyBindings'
|
||||||
import { KEY_BINDINGS } from '../constants'
|
import { KEY_BINDINGS } from '../constants'
|
||||||
import { immutableJSONPatch } from '../immutableJSONPatch'
|
import { immutableJSONPatch } from '../immutableJSONPatch'
|
||||||
import {
|
import {
|
||||||
applyErrors, applySelection, contentsFromPaths,
|
applyErrors,
|
||||||
|
applySelection,
|
||||||
|
contentsFromPaths,
|
||||||
expand,
|
expand,
|
||||||
EXPANDED,
|
EXPANDED,
|
||||||
expandPath, immutableESONPatch,
|
expandPath,
|
||||||
nextSearchResult, pathsFromSelection, previousSearchResult,
|
immutableESONPatch,
|
||||||
|
nextSearchResult,
|
||||||
|
pathsFromSelection,
|
||||||
|
previousSearchResult,
|
||||||
search,
|
search,
|
||||||
syncEson
|
syncEson
|
||||||
} from '../eson'
|
} from '../eson'
|
||||||
|
|
|
@ -93,7 +93,7 @@ export function syncEson(json, eson) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (jsonType === 'value') { // json is a value
|
else if (jsonType === 'value') { // json is a value
|
||||||
if (sameType) {
|
if (sameType && eson[VALUE] === json) {
|
||||||
return eson
|
return eson
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -16,7 +16,8 @@ import {
|
||||||
SELECTED_LAST,
|
SELECTED_LAST,
|
||||||
SELECTED_START, SELECTION,
|
SELECTED_START, SELECTION,
|
||||||
syncEson,
|
syncEson,
|
||||||
TYPE
|
TYPE,
|
||||||
|
VALUE
|
||||||
} from './eson'
|
} from './eson'
|
||||||
import { getIn, setIn } from './utils/immutabilityHelpers'
|
import { getIn, setIn } from './utils/immutabilityHelpers'
|
||||||
import { createAssertEqualEson } from './utils/assertEqualEson'
|
import { createAssertEqualEson } from './utils/assertEqualEson'
|
||||||
|
@ -60,6 +61,36 @@ test('syncEson', () => {
|
||||||
expect(nodeState2.obj.a[ID]).toEqual(nodeState1.obj.a[ID])
|
expect(nodeState2.obj.a[ID]).toEqual(nodeState1.obj.a[ID])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('syncEson (replace a value)', () => {
|
||||||
|
const json1 = {
|
||||||
|
value: 1
|
||||||
|
}
|
||||||
|
const eson1 = syncEson(json1, undefined)
|
||||||
|
|
||||||
|
expect(eson1.value[ID]).toBeDefined()
|
||||||
|
expect(eson1.value[TYPE]).toEqual('value')
|
||||||
|
expect(eson1.value[VALUE]).toEqual(1)
|
||||||
|
|
||||||
|
const json2 = {
|
||||||
|
value: 2
|
||||||
|
}
|
||||||
|
const eson2 = syncEson(json2, eson1)
|
||||||
|
|
||||||
|
expect(eson2.value[ID]).toBeDefined()
|
||||||
|
expect(eson2.value[TYPE]).toEqual('value')
|
||||||
|
expect(eson2.value[VALUE]).toEqual(2)
|
||||||
|
|
||||||
|
// eson1 should be untouched
|
||||||
|
expect(eson1.value[VALUE]).toEqual(1)
|
||||||
|
|
||||||
|
const json3 = {
|
||||||
|
value: 2 // samve as json2
|
||||||
|
}
|
||||||
|
const eson3 = syncEson(json3, eson2)
|
||||||
|
expect(eson3.value).toBe(eson2.value)
|
||||||
|
expect(eson3).toBe(eson2)
|
||||||
|
})
|
||||||
|
|
||||||
test('expand a single path', () => {
|
test('expand a single path', () => {
|
||||||
const eson = syncEson({
|
const eson = syncEson({
|
||||||
"obj": {
|
"obj": {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
* modes: string[]?,
|
* modes: string[]?,
|
||||||
* history: boolean?,
|
* history: boolean?,
|
||||||
* indentation: number | string?,
|
* indentation: number | string?,
|
||||||
* onChange: function (patch: ESONPatchDocument, revert: ESONPatchDocument)?,
|
* onChange: function (patch: JSONPatchDocument, revert: JSONPatchDocument)?,
|
||||||
* onChangeText: function ()?,
|
* onChangeText: function ()?,
|
||||||
* onChangeMode: function (mode: string, prevMode: string)?,
|
* onChangeMode: function (mode: string, prevMode: string)?,
|
||||||
* onError: function (err: Error)?,
|
* onError: function (err: Error)?,
|
||||||
|
@ -81,20 +81,6 @@
|
||||||
* }} JSONPatchOptions
|
* }} JSONPatchOptions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {{
|
|
||||||
* op: 'add' | 'remove' | 'replace' | 'copy' | 'move' | 'test',
|
|
||||||
* path: string,
|
|
||||||
* from?: string,
|
|
||||||
* value?: *,
|
|
||||||
* meta?: ESONPatchOptions
|
|
||||||
* }} ESONPatchOperation
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {ESONPatchOperation[]} ESONPatchDocument
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* patch: JSONPatchDocument,
|
* patch: JSONPatchDocument,
|
||||||
|
@ -103,22 +89,6 @@
|
||||||
* }} JSONPatchResult
|
* }} JSONPatchResult
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {{
|
|
||||||
* id: string,
|
|
||||||
* path: Path,
|
|
||||||
* type: ESONType,
|
|
||||||
* before?: string
|
|
||||||
* props?: string[],
|
|
||||||
* expanded?: boolean,
|
|
||||||
* selected?: boolean,
|
|
||||||
* searchProperty?: SearchResultStatus,
|
|
||||||
* searchValue?: SearchResultStatus
|
|
||||||
* }} ESONPatchOptions
|
|
||||||
*
|
|
||||||
* // TODO: describe search results and selection
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object | Array} ESON
|
* @typedef {Object | Array} ESON
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue