Skip to main content

Flow

@dopt/javascript / Exports / Flow

Class: Flow

Table of contents

Accessors

Methods

Accessors

type

get type(): "flow"

Returns

"flow"

Defined in

packages/@dopt/javascript/src/flow.ts:60


kind

get kind(): "flow"

Returns

"flow"

Defined in

packages/@dopt/javascript/src/flow.ts:64


uid

get uid(): string

Returns

string

Defined in

packages/@dopt/javascript/src/flow.ts:68


sid

get sid(): string

Returns

string

Defined in

packages/@dopt/javascript/src/flow.ts:72


version

get version(): number

Returns

number

Defined in

packages/@dopt/javascript/src/flow.ts:76


state

get state(): Object

Returns the up-to-date state of this Flow instance.

Returns

Object

The state of this instance.

NameType
stoppedboolean
startedboolean
finishedboolean

Defined in

packages/@dopt/javascript/src/flow.ts:85


blocks

get blocks(): Block<unknown>[]

Returns all the block children of this Flow.

Remarks

Blocks returned by this method have type Block.

Example

const blocks = flow.blocks();

// can access state properties safely
const states = blocks.map((block) => block.state);

// to transition these blocks
data.map(block => block.transition('default'));

Returns

Block<unknown>[]

An array of Block which are contained within this flow.

Defined in

packages/@dopt/javascript/src/flow.ts:140

Methods

initialized

initialized(): Promise<boolean>

Returns a promise that resolves when this flow has been initialized (or if it fails to initialize).

Initialization is defined as:

  • the flow has been fetched
  • Dopt's socket connection is ready
  • the flow has been started, if necessary

Remarks

When initialization succeeds, this will return true. If any parts of initialization fail, this will return false. Likewise, if this flow doesn't match any flows passed in the DoptConfig, this will return false.

Example

const flow = dopt.flow('onboarding-flow');
flow.initialized().then(() => {
// Safely access the first block in this flow
const block = dopt.block("HNWvcT78tyTwygnbzU6SW");
});

Returns

Promise<boolean>

A Promise. Once this flow's initialization is complete, the promise resolves to true if successful, false otherwise.

Defined in

packages/@dopt/javascript/src/flow.ts:117


start

start(options?): void

Start this flow. Will also update the state of blocks within this flow, as appropriate.

Remarks

This function will update state with Dopt and trigger changes. Subscribe to the flows and blocks you care about to react to those changes.

Parameters

NameType
options?Object
options.force?boolean

Returns

void

void

Defined in

packages/@dopt/javascript/src/flow.ts:168

start(): void

Returns

void

Defined in

packages/@dopt/javascript/src/flow.ts:169


finish

finish(): void

Finish this flow. Will also update the state of blocks within this flow, as appropriate.

Remarks

This function will update state with Dopt and trigger changes. Subscribe to the flows and blocks you care about to react to those changes.

Returns

void

void

Defined in

packages/@dopt/javascript/src/flow.ts:183


stop

stop(): void

Stop this flow. Will also update the state of blocks within this flow, as appropriate.

Remarks

This function will update state with Dopt and trigger changes. Subscribe to the flows and blocks you care about to react to those changes.

Returns

void

void

Defined in

packages/@dopt/javascript/src/flow.ts:196


reset

reset(options?): void

Reset this flow. Will also update the state of blocks within this flow, as appropriate. Under the hood, this method sets flows and blocks to their original/default states and subsequently calls start.

Remarks

This function will update state with Dopt and trigger changes. Subscribe to the flows and blocks you care about to react to those changes.

Parameters

NameType
options?Object
options.force?boolean

Returns

void

void

Defined in

packages/@dopt/javascript/src/flow.ts:216

reset(): void

Returns

void

Defined in

packages/@dopt/javascript/src/flow.ts:217


subscribe

subscribe(listener): () => void

Subscribe to changes on this flow.

Example

const flow = dopt.flow("welcome-to-dopt");
const unsubscribe = flow.subscribe(async (flow: Flow) => {
if (flow.state.completed) {
await showModal("Yay, you've completed your first tour!");
unsubscribe();
}
});

Parameters

NameTypeDescription
listener(flow: Flow) => voidThe listener function is called with this Flow instance.

Returns

fn

A function which can be called to unsubscribe the listener.

▸ (): void

Returns

void

Defined in

packages/@dopt/javascript/src/flow.ts:241