rxjs-bus
Wrapper on top of RXJs to propose a versatile and easy to use bus.
BusManager
Initialization
General
; // Define bus we need BusManager;
Ephemeral
; BusManager /*** [Later] ***/ BusManager;
Use
Subscription
; let bus = BusManager; let subscription = bus; // You will receive events until you unsubscribe from
Emit
; let bus = BusManager; let data = "Hello !"; // could be anything bus;
Once
Once allow to automatically unsubscribe after receiving one event.
; let bus = BusManager; bus;
Raw
Expose directly RxJS api to do even more awesome things with your events!
; ; let bus = BusManager; let subscription = bus ;
Please consult RxJS documentation for more awesome event management!
Scheduling
It is possible to define how the event will be distributed. The possible values are :
- null
- asap
- async
- queue
- animationFrame
Default value used is null, which represent a synchronous event delivery.
; let bus = BusManager; bus;
For more information, please check RxJS 6 documentation.
Acknowledge
Sometimes, we want to have information back after sending an event... Ack is here to help you with that, without the hassle of creating a dedicated event id, or managing callback lifetime!
; ; let disposer = Dispowser; let bus = BusManager; let data = "Ping?"; bus; /*** [Somewhere in the code...] ***/ let bus = BusManager; bus;
Subscription management
I recommend to use Dispowser to help you manage your subscriptions. It allow to dispose easily without polluting your scope with annoying variables.
; let disposer = Dispowser; disposerregister = bus; disposerregister = bus; disposerregister = bus; /*** [...] ***/ disposer; // Events won't be received anymore
Without Dispowser, do as follow :)
let subscription = bus; /*** [...] ***/ subscription;
StateManager
WIP