Skip to content

Transformations

Compare
Choose a tag to compare
@dgeb dgeb released this 02 Mar 21:39
· 2172 commits to main since this release

This release "transforms" the infrastructure used by Transformable sources. The
intent is to better expose the queues and the actions placed in queues, while
also correcting ordering issues by tracking the ancestry of operations.

New Operation, Action, and Transformation classes

Operation

Operation provides a thin wrapper over a JSON Patch operation.

Operations maintain the standard Patch attributes: op, path, and value.

Operations are automatically assigned a UUID id. They can maintain their
ancestry in a log. In this way, it is possible to determine whether
operations preceded each other.

Operations can spawn descendants, which automatically adds the parent to
the child's history.

The transform and didTransform methods on Transformable sources will
automatically normalize POJO operations into Operation instances.

Action

Actions wrap functions that are queued in an ActionQueue.

Actions can maintain optional metadata such as id and data. This metadata
makes it easier to identify actions within a queue. It can also be used by
actions themselves during processing.

Transformation

Transformations are created implicitly by Transformable sources in order
to group together related operations (i.e. those with a shared history).
This allows related operations to be processed together, and unrelated
operations to be queued in separate transformations to be processed
later.

A transformation tracks the original operations pushed to it, and can
verify whether other operations are descendants of those originals.

Important Note for Source Authors

In order to ensure that related transforms are resolved together and unrelated
transforms are queued for later processing, it's necessary to track operation
ancestry.

This should be straightforward within your sources. When sources receive
operations in _transform, they should now be of type Operation. If one
operation spawns another, then simply create the child operation using the
spawn method.

For example:

var childOperation = operation.spawn({op: 'add', path: path, value: value});

See the source for Cache, MemorySource, and JSONAPISource for
further examples.