RxJs SocketIO
An abstraction of socket-io with RxJs, it does this by separating the concerns of connection and event handling into two, IO
and ioEvent
.
Installation
$ npm install --save rxjs-socket.io
Quickstart
; // Assign a provider for the RxJs-Socket.io class; // Listen to and subscribe to an eventSocket.listenToEvent'event-name'.event$.subscribeconsole.log'event-name data:', data; // ConnectSocket.connect`http://localhost:1337`;
In depth
;;; // Assign a provider for the RxJs-Socket.io class; // Assign a pointer to the connection Observable, it will be hot when we connect. it's cold until then.; // Create an assignment to the pipe of the sockets' connection which emits only when we are disconnected; // Create new Events to be listened to;; // (optional) assign the cold obserables to a variable; // Do fancy stuff with the Subjects providedmerge ... .mapevent$.pipemap .pipetakeUntilconnectedClosed$ .subscribe; // Or do some more basic stuff,HelloWorldEvent$.subscribeconsole.log`HelloWorldEvent$:`, data; // Finally, listen and connect to the provided eventsSocket.listenToEventHelloWorldEvent;Socket.listenToEventFooBar; Socket.connect`http://localhost:1337`; // You can make events and hook them later too!; // You can even mess up the order on the listening and subscribingSocket.listenToEventBarFoo; BarFoo.event$.subscribeconsole.log`BarFoo`, data; // If you don't need the pointer to the event to refer to it later,Socket.listenToEventnew ioEvent`FooBarBarFoo`.event$.subscribeconsole.log`FooBarBarFoo`, data; // And you can deconstruct the creation of new ioEvents and get their observables;mergefoo, bar, baz.subscribeconsole.log`foo, bar, baz`, data; // IF you need a side-effect but don't want to subscribe you can always accessBarFoo.onUpdate =console.log`BarFoo newState`, newState;
links | |
---|---|
repo | https://gitlab.com/moshmage/rxjs-socket.io/ |
examples | -todo- |
documentation | https://moshmage.gitlab.io/rxjs-socket.io/ |