json-joy
    Preparing search index...

    Class Patch

    Represents a JSON CRDT patch.

    Normally, you would create a new patch using the PatchBuilder class.

    import {Patch, PatchBuilder, LogicalClock} from 'json-joy/lib/json-crdt-patch';

    const clock = new LogicalClock(3, 100);
    const builder = new PatchBuilder(clock);
    const patch = builder.flush();

    Save patch to a binary representation:

    const binary = patch.toBinary();
    

    Load patch from a binary representation:

    const patch = Patch.fromBinary(binary);
    

    Implements

    • Printable
    Index

    Constructors

    Properties

    meta: unknown = undefined

    Arbitrary metadata associated with the patch, which is not used by the library.

    A list of operations in the patch.

    Methods

    • The .rebase() operation is meant to be applied to patches which have not yet been advertised to the server (other peers), or when the server clock is used and concurrent change on the server happened.

      The .rebase() operation returns a new Patch with the IDs recalculated such that the first operation has the time equal to newTime.

      Parameters

      • newTime: number

        Time where the patch ID should begin (ID of the first operation).

      • OptionaltransformAfter: number

        Time after (and including) which the IDs should be transformed. If not specified, equals to the time of the first operation.

      Returns Patch

    • Returns the total time span of the patch, which is the sum of all operation spans.

      Returns number

      The length of the patch.

    • Marshals the patch into a binary representation.

      Returns Uint8Array<ArrayBufferLike>

      A binary representation of the patch.

    • Returns a textual human-readable representation of the patch. This can be used for debugging purposes.

      Parameters

      • tab: string = ''

        Start string for each line.

      Returns string

      Text representation of the patch.