You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/browser.md
+43-21
Original file line number
Diff line number
Diff line change
@@ -3,30 +3,52 @@ id: browser
3
3
title: "@podium/browser"
4
4
---
5
5
6
-
The `@podium/browser` package contains classes to provide browser based functionality when building Podium micro-frontends.
7
-
8
-
For now, this module only includes [MessageBus](#messagebus), but it is possible that it will include more features in the future.
6
+
The `@podium/browser` module is a client-side library designed to simplify communication between a podlet and the layout, and between podlets.
9
7
10
8
## Installation
11
9
12
10
```bash
13
-
$ npm install @podium/browser
11
+
npm install @podium/browser
14
12
```
15
13
16
-
## MessageBus
14
+
## Usage
15
+
16
+
In your podlet's client side JavaScript code, import the `MessageBus` class from the browser package and create a new instance of the class.
17
+
18
+
```js
19
+
import { MessageBus } from"@podium/browser";
17
20
18
-
Cross podlet communication and message passing. For a information and examples on how and when to use this module, see [the guide](../podlet/podlet_to_podlet_communication)
21
+
constmessageBus=newMessageBus();
22
+
```
23
+
24
+
### Publishing messages
25
+
26
+
To publish a message, call the `publish` method and pass a `channel`, a `topic` and any data you want subscribers to receive.
To subscribe to messages on a particular channel and topic, call the `subscribe` method passing it the `channel`, `topic` and a callback function to be executed whenever an event occurs. Whenever the callback is executed it gets passed an `Event` object which has the properties `channel`, `topic` and `payload`.
0 commit comments