# 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

- P extends MergableObject<P>

##### Index

### Constructors

constructor

### Accessors

changeCount
conflictCount
conflicts
hasChanges
objects

### Methods

acceptChanges
add
clear
delete
get
has
mergeRemotes
update

## Constructors

### constructor

- new MergableSet<P extends MergableObject<P>>(): MergableSet<P>

  #### Type Parameters

  - P extends MergableObject<P>

  #### Returns MergableSet<P>

## Accessors

### changeCount

- get changeCount(): number

  Gets number of objects that are not marked as MergableObjectState.Unchanged.

  #### Returns number

  Number of changed objects.

### conflictCount

- get conflictCount(): number

  Get number of conflicts in the set.

  #### Returns number

  Number of conflicts.

### conflicts

- get conflicts(): Readonly<MergableObjectWithState<P>>[]

  Gets all conflicts.

  #### Returns Readonly<MergableObjectWithState<P>>[]

  All conflicts.

### hasChanges

- get hasChanges(): boolean

  Checks if there are any changed objects in the set.

  #### Returns boolean

  `true` if there areobject not marked as MergableObjectState.Unchanged.

### objects

- 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

### acceptChanges

- 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`.

### add

- 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`.

### clear

- clear(): void

  Clear set

  #### Returns void

### delete

- 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`

### get

- get(id: string): undefined | MergableObjectWithState<P>

  Get object with specified id.

  #### Parameters

  - id: string

    Id of object to get.

  #### Returns undefined | MergableObjectWithState<P>

### has

- 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`.

### mergeRemotes

- 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.).

### update

- 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`.