A simple example of using SSE and subscriptions
Hello! Congrats on launching v11 🚀 I'm having a hard time to understand subscriptions](https://trpc.io/docs/server/subscriptions), specially the full stack example which is already a bit complex. Just wondering if there is a simple example somewhere without using React for example and just a basic subscription when a todo item is added for example.
Also, is it just me or the
onComplete
, onData
, etc options in a plain subscription got removed and is only available in useSubscription()
? The types from v10 have it https://github.com/trpc/trpc/blob/3bc06d055d3b860d978e9c465bce56fdcf95b71f/packages/client/src/internals/TRPCUntypedClient.ts#L32
Thanks!4 Replies
Which part are you confused on? The trpc component or using it on the frontend?
@Sploopy Man you have rescued me ! i've been fighting exactly this usecase and could not figure out why my event emmiter is not sending the data.... Your example worked Like a charm THANKS ! ❤️
I do agree with @Donald Biden that there should be a less complicated example in the docs regarding this. As I could not get it to work with the current example of chat pub/sub in the docs
feel free to make a PR to the docs 🙂
if you figure out how to...
- use explicit resource management, and
- make your redis client compatible with async iterables rather than
.on('x')
... you should be able to rewrite your thing into something like
tRPC also exports a function called observableToAsyncIterator that works with rxjs observables, which might also be worth mentioning
also in the next version of rxjs observables will implement Symbol.asyncIterator so they should be able to be returned directly