From 6e22897f74167de0b591a6ec1e5dac9827104896 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Thu, 15 Jul 2021 14:08:07 +1000 Subject: [PATCH] Rename `stateWaku` to `waku` There should only be one. --- examples/web-chat/src/App.tsx | 36 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/examples/web-chat/src/App.tsx b/examples/web-chat/src/App.tsx index 24115bfeb9..f713f4b094 100644 --- a/examples/web-chat/src/App.tsx +++ b/examples/web-chat/src/App.tsx @@ -76,7 +76,7 @@ async function retrieveStoreMessages( export default function App() { let [newMessages, setNewMessages] = useState([]); let [archivedMessages, setArchivedMessages] = useState([]); - let [stateWaku, setWaku] = useState(undefined); + let [waku, setWaku] = useState(undefined); let [nick, setNick] = useState(() => { const persistedNick = window.localStorage.getItem('nick'); return persistedNick !== null ? persistedNick : generate(); @@ -87,15 +87,15 @@ export default function App() { }, [nick]); useEffect(() => { - if (stateWaku) return; + if (waku) return; initWaku(setWaku) .then(() => console.log('Waku init done')) .catch((e) => console.log('Waku init failed ', e)); - }, [stateWaku]); + }, [waku]); useEffect(() => { - if (!stateWaku) return; + if (!waku) return; const handleRelayMessage = (wakuMsg: WakuMessage) => { console.log('Message received: ', wakuMsg); @@ -105,23 +105,23 @@ export default function App() { } }; - stateWaku.relay.addObserver(handleRelayMessage, [ChatContentTopic]); + waku.relay.addObserver(handleRelayMessage, [ChatContentTopic]); return; - }, [stateWaku]); + }, [waku]); useEffect(() => { - if (!stateWaku) return; + if (!waku) return; const handleProtocolChange = async ( - waku: Waku, + _waku: Waku, { peerId, protocols }: { peerId: PeerId; protocols: string[] } ) => { if (protocols.includes(StoreCodec)) { console.log(`${peerId.toB58String()}: retrieving archived messages}`); try { const length = await retrieveStoreMessages( - waku, + _waku, peerId, setArchivedMessages ); @@ -135,37 +135,33 @@ export default function App() { } }; - stateWaku.libp2p.peerStore.on( + waku.libp2p.peerStore.on( 'change:protocols', - handleProtocolChange.bind({}, stateWaku) + handleProtocolChange.bind({}, waku) ); // To clean up listener when component unmounts return () => { - stateWaku?.libp2p.peerStore.removeListener( + waku?.libp2p.peerStore.removeListener( 'change:protocols', - handleProtocolChange.bind({}, stateWaku) + handleProtocolChange.bind({}, waku) ); }; - }, [stateWaku]); + }, [waku]); return (
- + { - const { command, response } = handleCommand( - input, - stateWaku, - setNick - ); + const { command, response } = handleCommand(input, waku, setNick); const commandMessages = response.map((msg) => { return Message.fromUtf8String(command, msg); });