mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-22 03:29:43 +00:00
docs: fix Messages.listenTo() API docs
This commit is contained in:
parent
f81e25710f
commit
9f1c4cb329
@ -21,11 +21,13 @@ We can subscribe to channels using the `listenTo()` method by specifying a list
|
||||
```
|
||||
EmbarkJS.Messages.listenTo({
|
||||
topic: ['topic1', 'topic2']
|
||||
}).then(message {
|
||||
}).subscribe(message {
|
||||
console.log('received: ' + message);
|
||||
});
|
||||
```
|
||||
|
||||
`listenTo()` returns an Observable that we can subscribe to. Observables work great if multiple values can be emitted over time, which is exactly the case for messages being emitted with Whisper. In other words, this is a long-living Observable, so it's important to unsubscribe from it once we're no longer interested in the data. Otherwise we'll introduce memory leaks.
|
||||
|
||||
## Sending messages
|
||||
|
||||
Sending messages can be done using the `sendMessage()` method and it's entirely up to use whether we want to send plain text messages or even objects.
|
||||
@ -49,6 +51,8 @@ EmbarkJS.Messages.sendMessage({
|
||||
});
|
||||
```
|
||||
|
||||
Notice that a topic/channel name has to be at least 4 characters long. Whisper will otherwise emit an error on the subscription.
|
||||
|
||||
{% notification info 'On topic arrays:' %}
|
||||
Array of topics are considered an AND. In Whisper you can use another array for OR combinations of several topics e.g `["topic1", ["topic2", "topic3"]]` => `topic1 AND (topic2 OR topic 3)`.
|
||||
{% endnotification %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user