Rename action to operation

This commit is contained in:
Jos de Jong 2020-07-12 10:58:55 +02:00
parent bdc9f3ba34
commit fb3a9cdf36
4 changed files with 20 additions and 17 deletions

View File

@ -5,7 +5,7 @@
insertBefore,
removeAll,
replace
} from './actions.js'
} from './operations.js'
import {
DEFAULT_LIMIT,
STATE_EXPANDED,

View File

@ -1,6 +1,6 @@
<script>
import { debounce, isEqual } from 'lodash-es'
import { rename } from './actions.js'
import { rename } from './operations.js'
import {
DEBOUNCE_DELAY,
DEFAULT_LIMIT,

View File

@ -6,7 +6,7 @@ import { compileJSONPointer } from './utils/jsonPointer'
import { findUniqueName } from './utils/stringUtils'
/**
* Create a JSONPatch for an insert action.
* Create a JSONPatch for an insert operation.
*
* This function needs the current data in order to be able to determine
* a unique property name for the inserted node in case of duplicating
@ -51,7 +51,7 @@ export function insertBefore (json, path, values, nextKeys) { // TODO: find a b
}
/**
* Create a JSONPatch for an append action. The values will be appended
* Create a JSONPatch for an append operation. The values will be appended
* to the end of the array or object.
*
* This function needs the current data in order to be able to determine
@ -113,7 +113,7 @@ export function rename(parentPath, oldKey, newKey, nextKeys) {
}
/**
* Create a JSONPatch for an insert action.
* Create a JSONPatch for an insert operation.
*
* This function needs the current data in order to be able to determine
* a unique property name for the inserted node in case of duplicating
@ -136,14 +136,17 @@ export function replace (json, paths, values, nextKeys) { // TODO: find a bette
const firstPath = first(paths)
const offset = firstPath ? parseInt(last(firstPath), 10) : 0
const removeActions = removeAll(paths)
const insertActions = values.map((entry, index) => ({
op: 'add',
path: compileJSONPointer(parentPath.concat(index + offset)),
value: entry.value
}))
return [
// remove operations
...removeAll(paths),
return removeActions.concat(insertActions)
// insert operations
values.map((entry, index) => ({
op: 'add',
path: compileJSONPointer(parentPath.concat(index + offset)),
value: entry.value
}))
]
}
else { // parent is Object
return [
@ -168,7 +171,7 @@ export function replace (json, paths, values, nextKeys) { // TODO: find a bette
}
/**
* Create a JSONPatch for a remove action
* Create a JSONPatch for a remove operation
* @param {Path} path
* @return {JSONPatchDocument}
*/
@ -180,7 +183,7 @@ export function remove (path) {
}
/**
* Create a JSONPatch for a multiple remove action
* Create a JSONPatch for a multiple remove operation
* @param {Path[]} paths
* @return {JSONPatchDocument}
*/

View File

@ -13,7 +13,7 @@ import { isEqual, initial } from 'lodash-es'
* The original JSON object will not be changed,
* instead, the patch is applied in an immutable way
* @param {JSON} json
* @param {JSONPatchDocument} operations Array with JSON patch actions
* @param {JSONPatchDocument} operations Array with JSON patch operations
* @return {{json: JSON, revert: JSONPatchDocument, error: Error | null}}
*/
export function immutableJSONPatch (json, operations) {
@ -54,7 +54,7 @@ export function immutableJSONPatch (json, operations) {
return {
json: updatedJson,
revert: [],
error: new Error('Property "from" expected in copy action ' + JSON.stringify(operation))
error: new Error('Property "from" expected in copy operation ' + JSON.stringify(operation))
}
}
@ -70,7 +70,7 @@ export function immutableJSONPatch (json, operations) {
return {
json: updatedJson,
revert: [],
error: new Error('Property "from" expected in move action ' + JSON.stringify(operation))
error: new Error('Property "from" expected in move operation ' + JSON.stringify(operation))
}
}