Skip to main content

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.

Index

Constructors

constructor

Accessors

publicchangeCount

  • get changeCount(): number

publicconflictCount

  • get conflictCount(): number
  • Get number of conflicts in the set.


    Returns number

    Number of conflicts.

publicconflicts

publichasChanges

  • get hasChanges(): boolean

publicobjects

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


    Returns IterableIterator<Readonly<MergableObjectWithState<P>>, any, any>

    All objects.

Methods

publicacceptChanges

  • acceptChanges(): boolean
  • 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.

publicadd

  • add(o: P): boolean
  • 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.

publicclear

  • clear(): void
  • Clear set


    Returns void

publicdelete

  • delete(local: string | Pick<P, id>): boolean
  • Deletes a object


    Parameters

    • local: string | Pick<P, id>

      Id of object to delete

    Returns boolean

    true if object was deleted. Otherwise false

publicget

  • Get object with specified id.


    Parameters

    • id: string

      Id of object to get.

    Returns undefined | MergableObjectWithState<P>

publichas

  • has(id: string): boolean
  • Check if object with specified id exists.


    Parameters

    • id: string

      Id of matching object.

    Returns boolean

    true if object exists. Otherwise false.

publicmergeRemotes

  • mergeRemotes(remoteObjects: P[]): number
  • 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.).

publicupdate

  • update(id: string, updateAction: (existingItem: P) => void): boolean
  • 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.