mirror of https://github.com/waku-org/js-waku.git
Examples with no async/await syntax
Useful for those using ClojureScript. Resolves #182.
This commit is contained in:
parent
898f93371c
commit
a352cb0b38
|
@ -6,6 +6,7 @@
|
|||
- React/JavaScript
|
||||
- Waku Relay
|
||||
- Protobuf using `protons`.
|
||||
- No async/await syntax.
|
||||
|
||||
A barebone chat app to illustrate the [ReactJS Relay guide](/guides/reactjs-relay.md).
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ function App() {
|
|||
|
||||
export default App;
|
||||
|
||||
async function sendMessage(message, timestamp, waku) {
|
||||
function sendMessage(message, timestamp, waku) {
|
||||
const time = timestamp.getTime();
|
||||
|
||||
const payload = proto.SimpleChatMessage.encode({
|
||||
|
@ -103,6 +103,7 @@ async function sendMessage(message, timestamp, waku) {
|
|||
text: message,
|
||||
});
|
||||
|
||||
const wakuMessage = await WakuMessage.fromBytes(payload, ContentTopic);
|
||||
await waku.relay.send(wakuMessage);
|
||||
return WakuMessage.fromBytes(payload, ContentTopic).then((wakuMessage) =>
|
||||
waku.relay.send(wakuMessage)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
- React/JavaScript,
|
||||
- Waku Store,
|
||||
- Protobuf using `protons`.
|
||||
- No async/await syntax.
|
||||
|
||||
A simple app that retrieves chat messages using [Waku Store](https://rfc.vac.dev/spec/13/)
|
||||
to illustrate the [Retrieve Messages Using Waku Store With ReactJS guide](/guides/reactjs-store.md).
|
||||
|
|
|
@ -133,20 +133,20 @@ import { WakuMessage } from 'js-waku';
|
|||
|
||||
const ContentTopic = `/min-react-js-chat/1/chat/proto`;
|
||||
|
||||
async function sendMessage(message, timestamp, waku) {
|
||||
function sendMessage(message, timestamp, waku) {
|
||||
const time = timestamp.getTime();
|
||||
|
||||
// Encode to protobuf
|
||||
const payload = proto.SimpleChatMessage.encode({
|
||||
timestamp: time,
|
||||
text: message,
|
||||
text: message
|
||||
});
|
||||
|
||||
// Wrap in a Waku Message
|
||||
const wakuMessage = await WakuMessage.fromBytes(payload, ContentTopic);
|
||||
|
||||
// Send over Waku Relay
|
||||
await waku.relay.send(wakuMessage);
|
||||
return WakuMessage.fromBytes(payload, ContentTopic).then((wakuMessage) =>
|
||||
// Send over Waku Relay
|
||||
waku.relay.send(wakuMessage)
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue