Class diff.Diff

Create a new instance of a patch command based on the given factory objects.

Constructor

class diff.Diff(diffFactory, docFactory, deltaFactory)
Arguments:
  • diffFactory (Object) – A reference to a diff algorithm profile.
  • docFactory (Object) – A reference to a document profile.
  • deltaFactory (Object) – A reference to a delta profile.

Usage example:

var diffProfile = require('./lib/profiles/algo-diff-skelmatch');
var docProfile = require('./lib/profiles/doc-tree-xml');
var deltaProfile = require('./lib/profiles/delta-tree-xml');
var diff = require('./lib/delta/diff');

var d = new diff.Diff(diffProfile, docProfile, deltaProfile);

var orig = docProfile.loadOriginalDocument(original_content);
var changed = docProfile.loadInputDocument(changed_content);

var delta = d.diff(orig, changed);

var result = deltaProfile.serializeDocument(delta);

Methods

Diff#collect

diff.Diff.Diff#collect(doc1, doc2, matching)
Arguments:
  • doc1 (Object) –
    Original document. An instance returned by document
    profile loadOriginalDocument method.
  • doc2 (Object) –
    Changed document. An instance returned by document
    profile loadInputDocument method.
  • matching (Object) –
    The matching produced by the choosen diff
    algorithm.
Returns Object:

Delta document.

Construct delta document.

Diff#diff

diff.Diff.Diff#diff(doc1, doc2)
Arguments:
  • doc1 (Object) –
    Original document. An instance returned by document
    profile loadOriginalDocument method.
  • doc2 (Object) –
    Changed document. An instance returned by document
    profile loadInputDocument method.
Returns Object:

Delta document.

Return the delta object after computing and collecting the diff between doc1 and doc2.

Diff#populate

diff.Diff.Diff#populate(deltadoc, doc)
Arguments:
  • deltadoc (Object) – The delta document produced by diff.Diff.collect.
  • doc (Object) –
    Original document. An instance returned by document
    profile loadInputDocument method.
Returns Object:
The file-format specific representation of the delta

document (e.g. the DOM document).

Populate delta document with detached operations

Table Of Contents

Previous topic

Example code

Next topic

Class patch.Patch