Explores
The Explore workflow context, available as client.workflows.explores.
Manages the Explore workflows by unit ID. client.workflows.explore is
the one of the default unit.
Instance properties
context.autocomplete
Autocomplete settings shared by the workflows of this context. Call
enable() or disable() to switch autocomplete on or off, and read
enabled for the current state.
Type: Object
Instance methods
context.clearApi()
Remove the API options set by useApi().
Returns this.
context.clearDataProcessor()
Remove the functions added by useDataProcessor().
Returns this.
context.clearInteractions()
Remove the interaction options set by useInteractions().
Returns this.
context.clearLayouts()
Remove the layout options set by useLayouts().
Returns this.
context.clearTrackers()
Remove the tracker options set by useTrackers().
Returns this.
context.create([unitId])
Create the workflow of a unit.
| Parameter | Type | Description |
|---|---|---|
unitId |
string |
The unit ID. Default 'default'. Optional. |
Returns UnitWorkflow.
Throws Error: If the workflow of the unit already exists.
context.get([unitId])
Get the workflow of a unit, creating it if it does not exist.
| Parameter | Type | Description |
|---|---|---|
unitId |
string |
The unit ID. Default 'default'. Optional. |
Returns UnitWorkflow.
context.has([unitId])
Whether the workflow of a unit exists.
| Parameter | Type | Description |
|---|---|---|
unitId |
string |
The unit ID. Default 'default'. Optional. |
Returns boolean.
context.on(name, callback)
Listen to an event.
| Parameter | Type | Description |
|---|---|---|
name |
string |
The event name, or '*' for all events. |
callback |
function |
Called with (data, meta) on every event, where meta carries the event name and the timestamp ts. |
Returns function: A function to remove the listener.
context.once(name)
Wait for the next occurrence of an event.
| Parameter | Type | Description |
|---|---|---|
name |
string |
The event name. |
Returns Promise<{data: *, meta: Object}>: The event, with its data and meta.
context.useApi([name], [payload])
Set the API to call, and extra payload to send with each request.
| Parameter | Type | Description |
|---|---|---|
name |
string or Object or false |
The API name, such as 'questions', or with its group, such as 'ask/questions'. Pass the payload object alone to keep the API, or false to stop calling the API, so you can provide data by updateData() instead. Optional. |
payload |
Object |
Extra payload, merged into the request payload. Optional. |
Returns this.
workflow.useApi("ask/questions", { source_fl: ["title", "url"] });
context.useDataProcessor(fns)
Add functions to process the data before it is rendered. They run in the order they are added.
| Parameter | Type | Description |
|---|---|---|
fns |
function or function()[] |
Functions taking (data, oldData) and returning the processed data. |
Returns this.
context.useInteractions(options)
Set how interactions are sent.
| Parameter | Type | Description |
|---|---|---|
options |
Object or false |
Pass false to stop sending interactions. |
options.preprocess |
function or function()[] |
Functions taking the interaction payload and returning the modified one, run before it is sent. Optional. |
options.handle |
function |
A function taking the interaction payload, to send it yourself instead. Optional. |
Returns this.
context.useLayouts(options)
Set the layouts, by role.
| Parameter | Type | Description |
|---|---|---|
options |
Object or false |
The layout of each role, as a layout name, layout options, or [name, options]. Pass false to stop rendering. |
Returns this.
workflow.useLayouts({
query: { placeholder: "Ask a question" },
products: "list",
});
context.useTrackers(options)
Set the trackers, by role.
| Parameter | Type | Description |
|---|---|---|
options |
Object or boolean |
true or false to turn all trackers on or off, or the options of each role: active, and the options of each event type, impression, viewable (area and duration), and click (lenient). |
Returns this.
workflow.useTrackers({ products: { viewable: { duration: 2000 } } });
context.workflows()
All workflows of this context.
Returns UnitWorkflow[].
