npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rxjs-socket.io

v0.3.9

Published

wraps socket.io-client into replay subjects called ioEvents

Downloads

6

Readme

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

import {IO} from 'rxjs-socket.io';

// Assign a provider for the RxJs-Socket.io class
const Socket = new IO();

// Listen to and subscribe to an event
Socket.listenToEvent('event-name').event$.subscribe(data => console.log('event-name data:', data));

// Connect
Socket.connect(`http://localhost:1337`);

In depth

import {IO, ioEvent} from 'rxjs-socket.io';
import {merge} from 'rxjs';
import {filter, map, takeUntil} from 'rxjs/operators';

// Assign a provider for the RxJs-Socket.io class
const Socket = new IO();

// Assign a pointer to the connection Observable, it will be hot when we connect. it's cold until then.
const connection = Socket.event$;

// Create an assignment to the pipe of the sockets' connection which emits only when we are disconnected
const connectedClosed$ = connection.pipe(filter(({connected}) => !connected));

// Create new Events to be listened to
const HelloWorldEvent = new ioEvent(`HelloWorld`);
const FooBar = new ioEvent('FooBar');

// (optional) assign the cold obserables to a variable
const HelloWorldEvent$ = HelloWorldEvent.event$;

// Do fancy stuff with the Subjects provided
merge(
  ...[HelloWorldEvent, FooBar]
    .map(({name, event$}) =>
           event$.pipe(map(data => ({name, data})))))
  .pipe(takeUntil(connectedClosed$))
  .subscribe(({name: eventName, data: eventData}) => {
    console.log(`event: ${eventName}, data: ${JSON.stringify(eventData)}`);
  });

// Or do some more basic stuff,
HelloWorldEvent$.subscribe(data => console.log(`HelloWorldEvent$:`, data));


// Finally, listen and connect to the provided events
Socket.listenToEvent(HelloWorldEvent);
Socket.listenToEvent(FooBar);

Socket.connect(`http://localhost:1337`);


// You can make events and hook them later too!
const BarFoo = new ioEvent(`BarFoo`);

// You can even mess up the order on the listening and subscribing
Socket.listenToEvent(BarFoo);

BarFoo.event$.subscribe(data => console.log(`BarFoo`, data));

// If you don't need the pointer to the event to refer to it later,
Socket.listenToEvent(new ioEvent<string>(`FooBarBarFoo`)).event$.subscribe(data => console.log(`FooBarBarFoo`, data));

// And you can deconstruct the creation of new ioEvents and get their observables
const [foo, bar, baz] = Socket.listen(['foo', 'bar', 'baz']);
merge(foo, bar, baz).subscribe(data => console.log(`foo, bar, baz`, data));

// IF you need a side-effect but don't want to subscribe you can always access
BarFoo.onUpdate = (newState) => console.log(`BarFoo newState`, newState);

| links | | |--- |--- | | repo | https://gitlab.com/moshmage/rxjs-socket.io/ | | examples | -todo- | | documentation | https://moshmage.gitlab.io/rxjs-socket.io/