Use callback option in store guide

This commit is contained in:
Franck Royer 2021-10-05 13:35:29 +11:00
parent 6f4d765e30
commit d6f180cf36
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 12 additions and 9 deletions

View File

@ -140,23 +140,26 @@ const decodeWakuMessage = (wakuMessage) => {
You now have all the building blocks to retrieve and decode messages for a store node.
Retrieve messages from a store node:
Store node responses are paginated.
The `WakuStore.queryHistory` API automatically query all the pages in a sequential manner.
To process messages as soon as they received (page by page), use the `callback` option:
```js
const ContentTopic = '/store-guide/1/news/proto';
waku.store
.queryHistory([ContentTopic])
.catch((e) => {
// Be sure to catch any potential error
console.log('Failed to retrieve messages', e);
})
.then((retrievedMessages) => {
.queryHistory([ContentTopic], {
callback: (retrievedMessages) => {
const articles = retrievedMessages
.map(decodeWakuMessage) // Decode messages
.filter(Boolean); // Filter out undefined values
console.log(`${articles.length} articles have been retrieved`);
}
})
.catch((e) => {
// Be sure to catch any potential error
console.log('Failed to retrieve messages', e);
});
```