Skip to main content

LayerInterface <P>

A layer can contain any type of object data structure. When objects are added, deleted or modified events on the corresponding objects are raised. Since layer objects are divided into local and remote objects. Remote objects are those that are retrieved from the backend.

Implemented by

Index

Properties

attachments

attachments: LayerAttachmentsApi

Provides access to the layer attachments API (LayerAttachmentsApi) Use methods on it to get, add, update and delete attachments for this layer.

readonlychangeCount

changeCount: number

Number of objects in layer not marked with state Unchanged.

readonlyconflictCount

conflictCount: number

Number of objects with conflicts in the layer. A conflict occurs if there is a mismatch between the local and the remote representation of the layer. Conflicts can only occur when saveAndMerge or loadAndMerge is called.

readonlyconflicts

conflicts: Readonly<MergableObjectWithState<P>>[]

Conflicts in the layer. A conflict occurs if there is a mismatch between the local and the remote representation of a object in the layer. Conflicts can only occur when saveAndMerge or loadAndMerge is called.

readonlydefinition

definition: LayerDefinition

The layer definition.

readonlyid

id: string

Id of the layer

readonlyisLoaded

isLoaded: boolean

true if a layer exists and if saveAndMerge or loadAndMerge has been called successfully at least once.

readonlyname

name: undefined | string

Get the name of the layer. Returns undefined if no layer has been loaded.

readonlyobjects

objects: IterableIterator<Readonly<MergableObjectWithState<P>>>

Get the objects currently in the layer

readonlypermission

permission: Permissions

Permissions user has on layer.

readonlyversion

version: number

Get the version of the currently loaded layer. [-1] if no layer has yet been loaded.

Methods

add

  • add(o: P): boolean
  • Add an object. If object already exists it will not be added. That is if an item where MergableObject.id already exists.


    Parameters

    • o: P

      Object to add

    Returns boolean

    true if object was added, otherwise false.

clear

  • clear(): void
  • Clear the layer.


    Returns void

delete

  • delete(p: string | P): boolean
  • Deletes a object


    Parameters

    • p: string | P

    Returns boolean

    true if object was deleted. Otherwise false

get

  • Get a specific object in the layer. Both the local and the remote representation of the object is returned


    Parameters

    • id: string

      id of the object to get. Returns undefined if no such object exists.

    Returns undefined | MergableObjectWithState<P>

loadAndMerge

  • Loads all existing (remote) objects from the backend and attempts to merge them into objects. This may result in conflicts between the local and the remote objects. A typical example is if the same object has been modified locally but also remotely (in the backend.)


    Returns Promise<number | LayerFailure>

saveAndMerge

  • saveAndMerge(overwriteLatestVersion?: boolean): Promise<number | LayerFailure>
  • Saves all objects in objects and retrieves any added, modified layer objects made in backend (Remote) at the same time. An attempt is then made to merge the object from the backend (Remote) into the local (browser) objects.


    Parameters

    • optionaloverwriteLatestVersion: boolean

      If true then latest version is overwritten (if save was successful).

    Returns Promise<number | LayerFailure>

    Number of conflicts. If &gt; 0 then the operation was not successful. The conflicts must be resolved before a new attempt is made. If a LayerFailure is returned then it signifies that some unexpected error occured. Inspect the contents to determine the cause.

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.