reepicheep
reepicheep8mo ago

What is the pattern for unsubscribing from a subscription?

Hi there! I'd like to prevent unnecessary connections to a websocket server across multiple renders. What is the correct pattern to ensure this?
api.live.onNewIncident.useSubscription(undefined, {
onData: () => {
ctx.incidents.all.invalidate().catch(console.error);
},
});
api.live.onNewIncident.useSubscription(undefined, {
onData: () => {
ctx.incidents.all.invalidate().catch(console.error);
},
});
wss.on("connection", (ws) => {
console.log(`++ Connection (${wss.clients.size})`);

ws.once("close", () => {
console.log(`-- Connection (${wss.clients.size})`);
});
});
wss.on("connection", (ws) => {
console.log(`++ Connection (${wss.clients.size})`);

ws.once("close", () => {
console.log(`-- Connection (${wss.clients.size})`);
});
});
3 Replies
Father Christmas
I'd like to know too.
itsnotyalc
itsnotyalc3mo ago
As would I
BeBoRE
BeBoRE3mo ago
Use lazy on the wsLink