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
|
- React/JavaScript
|
||||||
- Waku Relay
|
- Waku Relay
|
||||||
- Protobuf using `protons`.
|
- Protobuf using `protons`.
|
||||||
|
- No async/await syntax.
|
||||||
|
|
||||||
A barebone chat app to illustrate the [ReactJS Relay guide](/guides/reactjs-relay.md).
|
A barebone chat app to illustrate the [ReactJS Relay guide](/guides/reactjs-relay.md).
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ function App() {
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
|
||||||
async function sendMessage(message, timestamp, waku) {
|
function sendMessage(message, timestamp, waku) {
|
||||||
const time = timestamp.getTime();
|
const time = timestamp.getTime();
|
||||||
|
|
||||||
const payload = proto.SimpleChatMessage.encode({
|
const payload = proto.SimpleChatMessage.encode({
|
||||||
|
@ -103,6 +103,7 @@ async function sendMessage(message, timestamp, waku) {
|
||||||
text: message,
|
text: message,
|
||||||
});
|
});
|
||||||
|
|
||||||
const wakuMessage = await WakuMessage.fromBytes(payload, ContentTopic);
|
return WakuMessage.fromBytes(payload, ContentTopic).then((wakuMessage) =>
|
||||||
await waku.relay.send(wakuMessage);
|
waku.relay.send(wakuMessage)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
- React/JavaScript,
|
- React/JavaScript,
|
||||||
- Waku Store,
|
- Waku Store,
|
||||||
- Protobuf using `protons`.
|
- Protobuf using `protons`.
|
||||||
|
- No async/await syntax.
|
||||||
|
|
||||||
A simple app that retrieves chat messages using [Waku Store](https://rfc.vac.dev/spec/13/)
|
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).
|
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`;
|
const ContentTopic = `/min-react-js-chat/1/chat/proto`;
|
||||||
|
|
||||||
async function sendMessage(message, timestamp, waku) {
|
function sendMessage(message, timestamp, waku) {
|
||||||
const time = timestamp.getTime();
|
const time = timestamp.getTime();
|
||||||
|
|
||||||
// Encode to protobuf
|
// Encode to protobuf
|
||||||
const payload = proto.SimpleChatMessage.encode({
|
const payload = proto.SimpleChatMessage.encode({
|
||||||
timestamp: time,
|
timestamp: time,
|
||||||
text: message,
|
text: message
|
||||||
});
|
});
|
||||||
|
|
||||||
// Wrap in a Waku Message
|
// Wrap in a Waku Message
|
||||||
const wakuMessage = await WakuMessage.fromBytes(payload, ContentTopic);
|
return WakuMessage.fromBytes(payload, ContentTopic).then((wakuMessage) =>
|
||||||
|
// Send over Waku Relay
|
||||||
// Send over Waku Relay
|
waku.relay.send(wakuMessage)
|
||||||
await waku.relay.send(wakuMessage);
|
);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue