diff

diff

Source:

Methods

(static) apply(changeOperations, object, changeHandleropt) → {Object}

Source:
See:
Alias for diff.applyDiff
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:
The result of applying the set of operational transforms to the provided object.
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:
The result of applying the set of operational transforms to the provided object.
Type
Object

(static) create(object1, object2) → {operations}

Source:
See:
An alias for diff.createDiff
Parameters:
Name Type Description
object1 Object The original object
object2 Object The target object
Returns:
An array of operational transforms that turns the original object into the target object.
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:
An array of operational transforms that turns the original object into the target object.
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:
a change handling function object.
Type
function

(static) reverse(A) → {Array.<operation>}

Source:
See:
Alias for diff.reverseDiff
Parameters:
Name Type Description
A Array.<operation> sequence of operational transforms.
Returns:
A list of operational transforms that rolls back the list of input operations.
Type
Array.<operation>

(static) reverseDiff(operations) → {Array.<operation>}

Source:
Reverse the sequence of operational transforms, such that if for a tuple (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:
A list of operational transforms that rolls back the list of input operations.
Type
Array.<operation>