docs: fix Messages.listenTo() API docs

This commit is contained in:
Pascal Precht 2019-06-20 15:10:51 +02:00 committed by Pascal Precht
parent f81e25710f
commit 9f1c4cb329

View File

@ -21,11 +21,13 @@ We can subscribe to channels using the `listenTo()` method by specifying a list
``` ```
EmbarkJS.Messages.listenTo({ EmbarkJS.Messages.listenTo({
topic: ['topic1', 'topic2'] topic: ['topic1', 'topic2']
}).then(message { }).subscribe(message {
console.log('received: ' + 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
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. 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:' %} {% 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)`. 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 %} {% endnotification %}