- Source:
Methods
(static) apply(changeOperations, object, changeHandleropt) → {Object}
- Source:
- See:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
changeOperations |
Array.<diffOperation> | the sequence of operational transforms to apply | |
object |
Object | the JS object to transform | |
changeHandler |
changeHandler |
<optional> |
a function object that can be used to fine-control the diff application process. |
Returns:
- Type
- Object
(static) applyDiff(changeOperations, object, changeHandleropt) → {Object}
- Source:
Apply a diff to a JS object, where the diff is structured as a sequence of operational transforms, consisting of:
add
update
move
rename
Note that in order to control the diff application behaviour, a change handler function object can be passed in. See diff.makeChangeHandler for details on this function object
When called without an explicit handler, a default change handler is used that performs "straight" diffing, without ignoring keys or transforming values during application. This default change handler is created by the diff.makeChangeHandler method.
However, in order to perform schema diffing, where the diff is computed between two schema objects, but then needs to be applied to plain data objects, this functionality allows the same diffing process to run, turning the sequence of operational transforms for schema objects into a sequence of concrete operational transforms for plain data objects.
See schema.makeSchemaChangeHandler for how this type of indirect diffing is achieved.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
changeOperations |
Array.<diffOperation> | the sequence of operational transforms to apply | |
object |
Object | the JS object to transform | |
changeHandler |
changeHandler |
<optional> |
a function object that can be used to fine-control the diff application process. |
Returns:
- Type
- Object
(static) create(object1, object2) → {operations}
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
object1 |
Object | The original object |
object2 |
Object | The target object |
Returns:
- Type
- operations
(static) createDiff(object1, object2) → {operations}
- Source:
- See:
-
- applyDiff
Create a diff between two JS objects, structured as a sequence of operational transforms, consisting of:
add
update
move
rename
Parameters:
Name | Type | Description |
---|---|---|
object1 |
Object | The original object |
object2 |
Object | The target object |
Returns:
- Type
- operations
(static) makeChangeHandler(ignoreKey, filterKeyString, transformValue) → {function}
- Source:
Create a change handler function object that can be used during diff application to control how the diff gets applied. This object takes three functions as arguments that each control a different aspect of the application process:
ignoreKey = function(keypath, type) {
// returns false if the diff application should skip the
// indicated type of transform for properties with the
// indicated keypath, using a dot separated value.
}
filterKeyString = function(keypath) {
// returns a (possibly) rewritten keypath, or
// false if the keypath should be ignored entirely
// for all possible operational transform types.
}
transformValue = function(keypath, value) {
// returns a (possibly) new value for the given keypath.
}
Any or all three functions may be omitted, in which case the
following defaults are used:
ignoreKey = function(keypath, type) {
return false;
}
filterKeyString = function(keypath) {
return keypath;
}
transformValue = function(keypath, value) {
return value;
}
Parameters:
Name | Type | Description |
---|---|---|
ignoreKey |
function | controls whether to apply diffs for specific key/type tuples. |
filterKeyString |
function | controls keypath mappings during diff application. |
transformValue |
function | controls value mappings during diff application. |
Returns:
- Type
- function
(static) reverse(A) → {Array.<operation>}
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
A |
Array.<operation> | sequence of operational transforms. |
Returns:
- Type
- Array.<operation>
(static) reverseDiff(operations) → {Array.<operation>}
- Source:
(object1, object2)
the input
operations transform object1 into object2, the reversed
sequence turns object2 into object1.
This function is idempotent, such that:
operations = reverseDiff(reverseDiff(operations))
Parameters:
Name | Type | Description |
---|---|---|
operations |
Array.<operation> | A sequence of operational transforms. |
Returns:
- Type
- Array.<operation>