# Commands & Events

## An introduction to commands & events

A **command** is an action/instruction sent to the Flipbook. These are used to trigger functionality inside the flipbook.

An **event** is when certain things happen inside a flipbook. These can be subscribed to in order to execute code when they occur. The code that should be executed is passed as a callback function when subscribing. You can set up multiple subscriptions to the same event. In addition, when you set up a subscription you will get an unsubscribe function returned which can be used to delete/cancel the subscription at any time (Note: You will need to `await` the subscription setup for the unsubscribe function to be accessible). For example:

```javascript
var mySubscription = await instance.basket.onToggled(() => {
    console.log('The basket was toggled');
});

mySubscription.unsubscribe();
```

The JS API comes with an extensive list of commands and events, which are split into the categories below:

{% content-ref url="/pages/4zE0Bs9b64WIp3wRasfu" %}
[Basket](/flipbook-javascript-api/commands-and-events/basket.md)
{% endcontent-ref %}

{% content-ref url="/pages/HQ3f7xa57O97a4EUGI3k" %}
[Consent](/flipbook-javascript-api/commands-and-events/consent.md)
{% endcontent-ref %}

{% content-ref url="/pages/FvI162KpbT856lKdBDRe" %}
[Paging](/flipbook-javascript-api/commands-and-events/paging.md)
{% endcontent-ref %}

{% content-ref url="/pages/JXFRW0OQLufshIsfpXHa" %}
[Publication](/flipbook-javascript-api/commands-and-events/publication.md)
{% endcontent-ref %}

{% content-ref url="/pages/YicvZpkPJINRnufWpi9L" %}
[Search](/flipbook-javascript-api/commands-and-events/search.md)
{% endcontent-ref %}

{% content-ref url="/pages/WXIY9tEiuvM56HP90GwH" %}
[Table of Contents](/flipbook-javascript-api/commands-and-events/table-of-contents.md)
{% endcontent-ref %}

{% content-ref url="/pages/c8z2n26gMe8MtEbVAQgP" %}
[Sharing](/flipbook-javascript-api/commands-and-events/sharing.md)
{% endcontent-ref %}

In addition to these commands and events, there is also a `updateConfig` command that can be used to update/set certain config settings of the API instance. The command accepts a single argument, consisting of the properties below:

| Property        | Type   | Description                                                                  |
| --------------- | ------ | ---------------------------------------------------------------------------- |
| `preventAction` | Object | Used to prevent default Flipbook behaviour when certain events are triggered |

For the `preventAction` object inside, this accepts one or multiple of the following properties:

| Property      | Type      | Description                                                                         |
| ------------- | --------- | ----------------------------------------------------------------------------------- |
| `basketClick` | `boolean` | When set to true, this will prevent the native basket from opening                  |
| `itemAdd`     | `boolean` | When set to true, this will prevent all shop items being added to the native basket |

Below is an example use which will prevent the native basket from opening:

```javascript
instance.updateConfig({
    preventAction: {
        basketClick: true,
        itemAdd: true
    }
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ipaper.io/flipbook-javascript-api/commands-and-events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
