Skip to main content

getIDResolver()

Description

Returns a function that synchronizes client (temporary) ids with server ids

info

When the client creates a new object (task or project), it receives a temporary id, while the corresponding server id is stored in the RestDataProvider. The function returned by getIDResolver() maps a client id to its server id. It is mainly used when handling server events in a multiuser backend.

Usage

getIDResolver(): (id: string | number, type: number) => string | number;

Returns

The method returns the idResolver(id, type) function:

  • id - the client (temporary) id to resolve
  • type - the type of the model:
    • 1 - a task (TaskID)
    • 2 - a project (ProjID)

The function returns the server id that corresponds to the passed client id.

Example

const { RestDataProvider } = todo;

const restProvider = new RestDataProvider(url);
const idResolver = restProvider.getIDResolver();

const TaskID = 1;
const serverId = idResolver(clientId, TaskID);

Related articles: Working with Server