Replying to Avatar Cesar Dias

Highly recommend rxjs, it's been an incredible journey for me and I had to learn some things the hard way.

After a heavy year on rxjs, I manage to build very complex pipelines with have very little state (variables) and close to no imperative code, I kinda got to a point of no way back.

Your approach of takeUntil is totally correct, which is the rxjs way of doing things, a powerful advice to rxjs is to avoid Subjects at all costs, they deviate the concepts of reactive programming and forces you in the imperative approach, people using rxjs with only Subjects aren't really using rxjs at all, just a fancy event emitter (the meme), there's a reason why xstream (a alternative library to rxjs) called their `next` function `shamefullySendNext` (yes, there's use cases for Subjects)

I have no issues with typescript in rxjs, it works pretty well and point-free operators would work just fine, I have issues naming things properly.

You have to be careful as well where you subscribe to the observables, it should be the final stage and usually close to the UI, and unsubscribe when the ui is "unmounted".

I was writing this document for nostr:nprofile1qydhwumn8ghj7umpw3jkcmrfw3jju6r6wfjrzdpe9e3k7mgpz9mhxue69uhkummnw3e82efwvdhk6qg5waehxw309aex2mrp0yhxgctdw4eju6t0qyxhwumn8ghj7mn0wvhxcmmvqyg8wumn8ghj7mn0wd68ytnhd9hx2qpqye5ptcxfyyxl5vjvdjar2ua3f0hynkjzpx552mu5snj3qmx5pzjs7haql4 the other day but never had a change to finish, which is my client approach for nostr subscription in rxjs https://github.com/cesardeazevedo/nostr-observable, the idea was to have a 100% stateless library for nostr.

This file is how I handle subscription and everything else is built on top of it https://github.com/cesardeazevedo/nosotros/blob/main/src/core/operators/subscribe.ts

If you have any questions don't hesitate to ask, I would love to help anything rxjs related.

Thanks, that rfc looks really nice. I also looked through nosotros/core and the code is super clean and includes a number of patterns that took a while for me to identify (like the relayFilters stuff). Have you looked into https://github.com/penpenpng/rx-nostr at all? My impression was that everything was pretty tightly coupled, making it hard to implement custom policy. Speaking of which, how do you handle relay AUTH when using websocketSubject? I am using policy functions that patch my socket adapter: https://github.com/coracle-social/welshman/blob/net2-rxjs/packages/net2/src/policy.ts

Reply to this note

Please Login to reply.

Discussion

Yes, relayFilters stream approach was something that I came up with the outbox in mind, it's been very useful and easy to split filters of a single subscription, I also designed in a way to work batching multiple unrelated subscriptions together, everything becomes a queue at the end consumed by the start() operators, this approach has been working really well for me and haven't touch much in a while.

rx-nostr is indeed too tightly coupled and when I started my mind was mainly focus on the batcher.

The way I been designing things is the core the be completely stateless and lazy, you can create a subscription and the core will never initiate any subscription for you, just like rxjs itself wouldn't, it just gives you the building blocks.