mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-05-04 11:53:56 +00:00
Clean up observer when component dismount
This commit is contained in:
parent
1d3f0e4c8a
commit
4e7f75868f
@ -72,6 +72,11 @@ function App() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!waku) return;
|
if (!waku) return;
|
||||||
waku.relay.addObserver(observerPublicKeyMessage, [PublicKeyContentTopic]);
|
waku.relay.addObserver(observerPublicKeyMessage, [PublicKeyContentTopic]);
|
||||||
|
|
||||||
|
return function cleanUp() {
|
||||||
|
if (!waku) return;
|
||||||
|
waku.relay.deleteObserver(observerPublicKeyMessage, [PublicKeyContentTopic]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -81,6 +86,16 @@ function App() {
|
|||||||
observerDirectMessage.bind({}, ethDmKeyPair.privateKey),
|
observerDirectMessage.bind({}, ethDmKeyPair.privateKey),
|
||||||
[DirectMessageContentTopic]
|
[DirectMessageContentTopic]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return function cleanUp() {
|
||||||
|
if (!waku) return;
|
||||||
|
if (!ethDmKeyPair) return;
|
||||||
|
waku.relay.deleteObserver(
|
||||||
|
observerDirectMessage.bind({}, ethDmKeyPair.privateKey),
|
||||||
|
[DirectMessageContentTopic]
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const broadcastPublicKey = () => {
|
const broadcastPublicKey = () => {
|
||||||
@ -109,6 +124,8 @@ function App() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const sendDummyMessage = () => {
|
const sendDummyMessage = () => {
|
||||||
|
if (!waku) return;
|
||||||
|
|
||||||
console.log(`Sending messages to ${publicKeys.size} peers`);
|
console.log(`Sending messages to ${publicKeys.size} peers`);
|
||||||
publicKeys.forEach(async (publicKey, address) => {
|
publicKeys.forEach(async (publicKey, address) => {
|
||||||
const msg = await encodeEncryptedWakuMessage(
|
const msg = await encodeEncryptedWakuMessage(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user