Skip to main content

Dopt

@dopt/javascript / Exports / Dopt

Class: Dopt

Table of contents

Constructors

Methods

Constructors

constructor

new Dopt(config)

Creates a Dopt class instance.

Remarks

Before using a Dopt instance, check whether the instance has been initialized.

Example

const dopt = new Dopt({
apiKey: "<MY BLOCKS API KEY>",
userId: "<MY USER'S ID>",
flowVersions: { "welcome-to-dopt": 3 },
});

Parameters

NameTypeDescription
configDoptConfigDoptConfig

Defined in

packages/@dopt/javascript/src/dopt.ts:151

Methods

initialized

initialized(): Promise<boolean>

Resolves to true when this Dopt instance has been intiailized.

Dopt-level initialization is defined as:

  • all flows have been fetched
  • Dopt's socket connection is ready
  • all flows which need to be started have been started

Remarks

Note, this hook does not check whether any initialization steps had errors. Use flow.initialized to check flow status, including failures, at a more granular level.

Example

dopt.initialized().then(() => {
// Safely access block(s) or flow(s)!
const blocks = dopt.blocks();
const block = dopt.block("HNWvcT78tyTwygnbzU6SW");
});

Returns

Promise<boolean>

A Promise. Once all of Dopt's initialization is complete, the promise resolves to true.

Defined in

packages/@dopt/javascript/src/dopt.ts:214


configure

configure(config): Promise<void>

Configures a Dopt instance with new properties. For example, if you didn't pass in a userId initially, you can use this method to configure Dopt to your user.

Remarks

Before using a Dopt instance, check whether the instance has been initialized.

Example

dopt.configure({
userId: "<MY USER'S ID>",
});

Parameters

NameTypeDescription
configPartial<Pick<DoptConfig, "userId" | "groupId" | "flowVersions">>a partial DoptConfig, it only accepts userId, groupId, and flowVersions attributes.

Returns

Promise<void>

A promise which resolves once the configuration is complete. However, you should not rely on this promise since there may be side effects which won't resolve before promise completion. Instead, rely on dopt.initialized to evaluate whether configuration is complete.

Defined in

packages/@dopt/javascript/src/dopt.ts:257


flow

flow(sid): Flow

Returns the Flow associated with the given id and version.

Example

const flow = dopt.flow("welcome-to-dopt");

Parameters

NameType
sidstring

Returns

Flow

A Flow instance which matches the given id.

Defined in

packages/@dopt/javascript/src/dopt.ts:448


flows

flows(): Flow[]

Returns all flows associated with the flowVersions specified to the SDK.

Remarks

This method will return an empty array if this Dopt instance is not initialized.

Returns

Flow[]

An array of all Flow instances stored by this Dopt class.

Defined in

packages/@dopt/javascript/src/dopt.ts:479


block

block<T>(id): Block<T>

Returns the Block associated with this id.

Example

const block = dopt.block("HNWvcT78tyTwygnbzU6SW");

Type parameters

Name
T

Parameters

NameTypeDescription
idstringone of ['uid'] | ['sid'] The id of the block. this param accepts either the user defined identifier (sid) or the system created identifier (the uid)

Returns

Block<T>

A Block instance corresponding to the id.

Defined in

packages/@dopt/javascript/src/dopt.ts:520


blocks

blocks(): Block<unknown>[]

Returns all blocks associated with the flowVersions specified to the SDK.

Remarks

This method will return an empty array if this Dopt instance is not initialized.

Returns

Block<unknown>[]

An array of all Block instances stored by this Dopt class.

Defined in

packages/@dopt/javascript/src/dopt.ts:558


modal(id): Modal

Returns the Modal associated with this id.

Example

const modal = dopt.modal("flow-one.my-modal");

Parameters

NameTypeDescription
idstringone of ['uid'] | ['sid'] The id of the modal. this param accepts either the user defined identifier (sid) or the system created identifier (the uid)

Returns

Modal

A Modal instance corresponding to the id.

Defined in

packages/@dopt/javascript/src/dopt.ts:599


card

card(id): Card

Returns the Card associated with this id.

Example

const card = dopt.card("flow-one.my-card");

Parameters

NameTypeDescription
idstringone of ['uid'] | ['sid'] The id of the card. this param accepts either the user defined identifier (sid) or the system created identifier (the uid)

Returns

Card

A Card instance corresponding to the id.

Defined in

packages/@dopt/javascript/src/dopt.ts:615


checklist

checklist(id): Checklist

Returns the Checklist associated with this id.

Example

const checklist = dopt.checklist("flow-two.my-checklist");

Parameters

NameTypeDescription
idstringone of ['uid'] | ['sid'] The id of the modal. this param accepts either the user defined identifier (sid) or the system created identifier (the uid)

Returns

Checklist

A Checklist instance corresponding to the id.

Defined in

packages/@dopt/javascript/src/dopt.ts:631


checklistItem

checklistItem(id): ChecklistItem

Returns the ChecklistItem associated with this id.

Example

const checklistItem = dopt.checklistItem("flow-two.my-checklist-item");

Parameters

NameTypeDescription
idstringone of ['uid'] | ['sid'] The id of the checklist item. this param accepts either the user defined identifier (sid) or the system created identifier (the uid)

Returns

ChecklistItem

A ChecklistItem instance corresponding to the id.

Defined in

packages/@dopt/javascript/src/dopt.ts:654


hints

hints(id): Hints

Returns the Hints associated with this id.

Example

const hints = dopt.hints("flow-two.my-hints");

Parameters

NameTypeDescription
idstringone of ['uid'] | ['sid'] The id of the modal. this param accepts either the user defined identifier (sid) or the system created identifier (the uid)

Returns

Hints

A Hints instance corresponding to the id.

Defined in

packages/@dopt/javascript/src/dopt.ts:673


hintsItem

hintsItem(id): HintsItem

Returns the HintsItem associated with this id.

Example

const hintsItem = dopt.hintsItem("flow-two.my-hints-item");

Parameters

NameTypeDescription
idstringone of ['uid'] | ['sid'] The id of the hints item. this param accepts either the user defined identifier (sid) or the system created identifier (the uid)

Returns

HintsItem

A HintsItem instance corresponding to the id.

Defined in

packages/@dopt/javascript/src/dopt.ts:696


tour

tour(id): Tour

Returns the Tour associated with this id.

Example

const tour = dopt.tour("flow-three.my-tour");

Parameters

NameTypeDescription
idstringone of ['uid'] | ['sid'] The id of the modal. this param accepts either the user defined identifier (sid) or the system created identifier (the uid)

Returns

Tour

A Tour instance corresponding to the id.

Defined in

packages/@dopt/javascript/src/dopt.ts:728


tourItem

tourItem(id): TourItem

Returns the TourItem associated with this id.

Example

const tourItem = dopt.tourItem("flow-three.my-tour-item");

Parameters

NameTypeDescription
idstringone of ['uid'] | ['sid'] The id of the checklist item. this param accepts either the user defined identifier (sid) or the system created identifier (the uid)

Returns

TourItem

A TourItem instance corresponding to the id.

Defined in

packages/@dopt/javascript/src/dopt.ts:751


destroy

destroy(): void

Closes this instance's internal socket connection.

Remarks

You may want to do this when a component (or set of components) which depends on this instance is being unmounted and you don't want to leak an open socket connection.

Returns

void

Defined in

packages/@dopt/javascript/src/dopt.ts:779