Skip to content

Commit e93c449

Browse files
committed
docs: peek gotcha, link to podium-lib docs
1 parent cc3c545 commit e93c449

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

README.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @podium/browser
22

3-
This is a client-side library designed to:
3+
This is a [Podium client-side communication library](https://podium-lib.io/docs/guides/client-side-communication) designed to:
44

55
- send and receive messages between different podlets in a layout.
66
- send and receive messages between web and native in a webview.
@@ -24,22 +24,30 @@ import Podium from '@podium/browser';
2424
Use the [MessageBus](#messagebus) to send messages between podlets in a layout.
2525

2626
```javascript
27-
// In podlet A. Broadcast a message.
27+
// input-podlet.js
2828
import { MessageBus } from '@podium/browser';
2929

3030
const messageBus = new MessageBus();
3131

32-
messageBus.publish('search', 'query', 'couch');
32+
messageBus.publish('reminders', 'newReminder', {
33+
title: 'Buy milk',
34+
});
3335
```
3436

3537
```js
36-
// In podlet B. Subscribe to a message.
38+
// list-podlet.js
3739
import { MessageBus } from '@podium/browser';
3840

3941
const messageBus = new MessageBus();
4042

41-
messageBus.subscribe('search', 'query', (event) => {
42-
console.log(event.payload);
43+
// Check to see if an initial value exists on the messageBus
44+
// and fall back to a default value.
45+
const reminders = messageBus.peek('reminders', 'newReminder') || [];
46+
47+
// ListPodlet listens for new reminders published on the message bus and updates its state
48+
messageBus.subscribe('reminders', 'newReminder', (event) => {
49+
const reminder = event.payload;
50+
reminders.push(reminder);
4351
});
4452
```
4553

@@ -106,6 +114,17 @@ messageBus.publish('search', 'query', 'laptop');
106114
messageBus.publish('auth', 'logout');
107115
```
108116

117+
#### `.peek(channel, topic)`
118+
119+
Get the latest event for a channel and topic combination. Use this to set up your application's initial state if relevant – check for a value and fall back to a default.
120+
121+
This method takes the following arguments:
122+
123+
| option | default | type | required | details |
124+
| ------- | ------- | -------- | -------- | ------------------- |
125+
| channel | `null` | `string` | `true` | Name of the channel |
126+
| topic | `null` | `string` | `true` | Name of the topic |
127+
109128
#### `.subscribe(channel, topic, callback)`
110129

111130
Subscribe to messages for a channel and topic combination.
@@ -150,17 +169,6 @@ messageBus.subscribe('channel', 'topic', cb);
150169
messageBus.unsubscribe('channel', 'topic', cb);
151170
```
152171

153-
#### `.peek(channel, topic)`
154-
155-
Get the latest event for a channel and topic combination.
156-
157-
This method takes the following arguments:
158-
159-
| option | default | type | required | details |
160-
| ------- | ------- | -------- | -------- | ------------------- |
161-
| channel | `null` | `string` | `true` | Name of the channel |
162-
| topic | `null` | `string` | `true` | Name of the topic |
163-
164172
#### `.log(channel, topic)`
165173

166174
Returns an array of the 10 latest events for a channel and topic combination.

0 commit comments

Comments
 (0)