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 { immutableJSONPatch } from '../immutableJSONPatch'
|
||||
import {
|
||||
applyErrors, applySelection, contentsFromPaths,
|
||||
applyErrors,
|
||||
applySelection,
|
||||
contentsFromPaths,
|
||||
expand,
|
||||
EXPANDED,
|
||||
expandPath, immutableESONPatch,
|
||||
nextSearchResult, pathsFromSelection, previousSearchResult,
|
||||
expandPath,
|
||||
immutableESONPatch,
|
||||
nextSearchResult,
|
||||
pathsFromSelection,
|
||||
previousSearchResult,
|
||||
search,
|
||||
syncEson
|
||||
} from '../eson'
|
||||
|
|
|
@ -93,7 +93,7 @@ export function syncEson(json, eson) {
|
|||
}
|
||||
}
|
||||
else if (jsonType === 'value') { // json is a value
|
||||
if (sameType) {
|
||||
if (sameType && eson[VALUE] === json) {
|
||||
return eson
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -16,7 +16,8 @@ import {
|
|||
SELECTED_LAST,
|
||||
SELECTED_START, SELECTION,
|
||||
syncEson,
|
||||
TYPE
|
||||
TYPE,
|
||||
VALUE
|
||||
} from './eson'
|
||||
import { getIn, setIn } from './utils/immutabilityHelpers'
|
||||
import { createAssertEqualEson } from './utils/assertEqualEson'
|
||||
|
@ -60,6 +61,36 @@ test('syncEson', () => {
|
|||
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', () => {
|
||||
const eson = syncEson({
|
||||
"obj": {
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
* modes: string[]?,
|
||||
* history: boolean?,
|
||||
* indentation: number | string?,
|
||||
* onChange: function (patch: ESONPatchDocument, revert: ESONPatchDocument)?,
|
||||
* onChange: function (patch: JSONPatchDocument, revert: JSONPatchDocument)?,
|
||||
* onChangeText: function ()?,
|
||||
* onChangeMode: function (mode: string, prevMode: string)?,
|
||||
* onError: function (err: Error)?,
|
||||
|
@ -81,20 +81,6 @@
|
|||
* }} JSONPatchOptions
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* op: 'add' | 'remove' | 'replace' | 'copy' | 'move' | 'test',
|
||||
* path: string,
|
||||
* from?: string,
|
||||
* value?: *,
|
||||
* meta?: ESONPatchOptions
|
||||
* }} ESONPatchOperation
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {ESONPatchOperation[]} ESONPatchDocument
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* patch: JSONPatchDocument,
|
||||
|
@ -103,22 +89,6 @@
|
|||
* }} 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
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue