Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #24 from saleor/deprecation-in-readme
Browse files Browse the repository at this point in the history
Add deprecation to readme
  • Loading branch information
lkostrowski authored Sep 2, 2022
2 parents 8543bc0 + 8cba0cc commit 36b0a36
Showing 1 changed file with 3 additions and 91 deletions.
94 changes: 3 additions & 91 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,95 +1,7 @@
# Saleor App Bridge

## Installation
**DEPRECATED**

```bash
npm i @saleor/app-bridge
```

## Usage

First initialize the package by running `createApp()`:

```js
import { createApp } from "@saleor/app-bridge";

const app = createApp();
```

Access app state:

```js
const { token, domain, ready, id } = app.getState();
```

## Events

Events are messages that originate in Saleor Dashboard.

### Available methods

**`subscribe(eventType, callback)`** - can be used to listen to particular event type. It returns an unsubscribe function, which unregisters the callback.

Example:

```js
const unsubscribe = app.subscribe("handshake", (payload) => {
setToken(payload.token); // do something with event payload
const { token } = app.getState(); // you can also get app's current state here
});

// unsubscribe when callback is no longer needed
unsubscribe();
```

**`unsubscribeAll(eventType?)`** - unregisters all callbacks of provided type. If no type was provided, it will remove all event callbacks.

Example:

```js
app.unsubscribeAll("handshake"); // unsubscribe from all handshake events

app.unsubscribeAll(); // unsubscribe from all events
```

### Available event types

| Event type | Description |
| :---------- | :--------------------------------------------------------------------------- |
| `handshake` | Fired when iFrame containing the App is initialized or new token is assigned |
| `response` | Fired when Dashboard responds to an Action |
| `redirect` | Fired when Dashboard change a subpath within the app path |
| `theme` | Fired when Dashboard change the theme |

## Actions

Actions expose a high-level API to communicate with Saleor Dashboard. They're exported under an `actions` namespace.

### Available methods

**`dispatch(action)`** - dispatches an Action. Returns a promise which resolves when action is successfully completed.

Example:

```js
import { actions } from "@saleor/app-bridge";

const handleRedirect = async () => {
await app.dispatch(actions.Redirect({ to: "/orders" }));
console.log("Redirect complete!");
};

handleRedirect();
```

### Available actions

| Action | Arguments | Description |
| :--------- | :--------------------------------------------------------------- | :---------- |
| `Redirect` | `to` (string) - relative (inside Dashboard) or absolute URL path | |
| | `newContext` (boolean) - should open in a new browsing context | |
|`Notification` | `status` (`info` / `success` / `warning` / `error` / undefined)| |
| | `title` (string / undefined) - title of the notification | |
| | `text` (string / undefined) - content of the notification | |
| | `apiMessage` (string / undefined) - error log from api | |
This package has been merged into [Saleor App SDK](https://github.com/saleor/saleor-app-sdk/blob/main/docs/app-bridge.md).
Use this package to handle communication between Saleor App and Saleor Dashboard

0 comments on commit 36b0a36

Please sign in to comment.