@twinfinity/core
    Preparing search index...

    Class MergableSet<P>

    Represents a collection of object that has a local and a remote representation. Changes are always made to the local representation of the object. However it is possible to merge remote representations of the objects. When a merge occurs new local objects may be added, updated and deleted In some cases conflicts may arise. Such as when a local object has been modified but the remote object has been deleted.

    Type Parameters

    Index

    Constructors

    Accessors

    • get conflictCount(): number

      Get number of conflicts in the set.

      Returns number

      Number of conflicts.

    • get hasChanges(): boolean

      Checks if there are any changed objects in the set.

      Returns boolean

      true if there areobject not marked as MergableObjectState.Unchanged.

    • get objects(): IterableIterator<Readonly<MergableObjectWithState<P>>>

      Gets all local objects and their remote counterparts. Includes both state and conflict reasons (if any)

      Returns IterableIterator<Readonly<MergableObjectWithState<P>>>

      All objects.

    Methods

    • Accepts changes in the set. Is only successful if no conflicts exist.

      Returns boolean

      true if no conflicts existed so changes can be accepted. Otherwise, false.

    • Adds an object. If object already exists, it will not be added. An object exists for items where MergableObject.id already exists.

      Parameters

      • o: P

        Object to add

      Returns boolean

      true if object was added, otherwise false.

    • Clear set

      Returns void

    • Deletes a object

      Parameters

      • local: string | Pick<P, "id">

        Id of object to delete

      Returns boolean

      true if object was deleted. Otherwise false

    • Check if object with specified id exists.

      Parameters

      • id: string

        Id of matching object.

      Returns boolean

      true if object exists. Otherwise false.

    • Merges remote objects.

      Parameters

      • remoteObjects: P[]

        Remote objects to merge.

      Returns number

      Number of conflicts that occured during the merge. May not be same as conflictCount (which gives all conflicts from previous merges as well.).

    • Updates an object that already exists.

      Parameters

      • id: string

        Id of object to update

      • updateAction: (existingItem: P) => void

        function called with MergableObject instance of specified id. Caller should make any required modfifications to the object in this function.

      Returns boolean

      true if object did exist, otherwise false.