MutationTracker

MutationTracker

new MutationTracker(definition)

A MutationTracker allows to record mutations on any of object and store them. This stored mutations can be transported for reporting or to replay on similar objects.

Parameters:
Name Type Description
definition MutationTracker~definition

serialized mutation tracker

Source:

Extends

Methods

(static) isMutationTracker(obj) → {Boolean}

Check whether an object is an instance of MutationTracker.

Parameters:
Name Type Description
obj *
Source:
Returns:
Type
Boolean

applyOn(target)

Applies all the recorded mutations on a target object.

Parameters:
Name Type Description
target *

Target to apply mutations. Must implement applyMutation.

Source:

compact()

Compacts the recorded mutations removing duplicate mutations that apply on the same key path.

Source:

count() → {Number}

Returns the number of mutations tracked so far.

Source:
Returns:
Type
Number

findInParents(property, customizeropt) → {*|undefined}

Tries to find the given property locally, and then proceeds to lookup in each parent, going up the chain as necessary. Lookup will continue until customizer returns a truthy value. If used without a customizer, the lookup will stop at the first parent that contains the property.

Parameters:
Name Type Attributes Description
property String
customizer function <optional>
Inherited From:
Source:
Returns:
Type
* | undefined

forEachParent(optionsopt, iterator)

Invokes the given iterator for every parent in the parent chain of the given element.

Parameters:
Name Type Attributes Default Description
options Object | Boolean <optional>
{}

A set of options for the parent chain traversal.

Properties
Name Type Attributes Default Description
withRoot Boolean <optional>
<nullable>
false

Set to true to include the collection object as well.

iterator function

The function to call for every parent in the ancestry chain.

Inherited From:
Source:
To Do:
  • Cache the results

meta() → {*}

Returns the meta keys associated with the property

Inherited From:
Source:
Returns:
Type
*

parent() → {*|undefined}

Returns the parent of item

Inherited From:
Source:
Returns:
Type
* | undefined

toJSON()

Returns the JSON representation of a property, which conforms to the way it is defined in a collection. You can use this method to get the instantaneous representation of any property, including a Collection.

Inherited From:
Source:

track(instruction)

Track a mutation.

Parameters:
Name Type Description
instruction String

the type of mutation

Source:

Type Definitions

definition

A JSON representation of the MutationTracker.

Properties:
Name Type Attributes Default Description
stream Array

contains the stream mutations tracked

compacted Object

contains a compacted version of the mutations

autoCompact Boolean <optional>
false

when set to true, all new mutations would be compacted immediately

Source:

mutation

A JSON representation of a mutation on an object. Here objects mean instances of postman-collection classes. This captures the instruction and the parameters of the instruction so that it can be replayed on a different object. Mutations can be any change on an object. For example setting a key or unsetting a key.

For example, the mutation to set name on an object to 'Bruce Wayne' would look like ['name', 'Bruce Wayne']. Where the first item is the key path and second item is the value. To add a property punchLine to the object it would be the same as updating the property i.e. ['punchLine', 'I\'m Batman']. To remove a property age the mutation would look like ['age'].

This format of representing changes is derived from http://json-delta.readthedocs.io/en/latest/philosophy.html.

The set and unset are primitive instructions and can be derived from the mutation without explicitly stating the instruction. For more complex mutation the instruction would have to be explicitly stated.

Type:
  • Array
Source: