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

redux-socket-cluster

v0.11.1

Published

A socket-cluster state snatcher

Downloads

18

Readme

npm version

redux-socket-cluster

A socket-cluster state snatcher

WIP - Thoughts & PRs welcome!

Socket cluster is awesome, but it doesn't share it's state, so you always have to go to your stored socket to find out. This tiny package grabs all the tasty little state bits & sticks em in your redux store. Then, it sets up listeners for updates to keep those state bits nice and fresh. This makes it super easy to do things like "Please wait, reconnecting" modals without having to access the socket. More complex examples might be getting kicked off a subscription & pushing a "You got booted from the chat room. Sending you to the lobby..."

Installation

npm i -S redux-socket-cluster

API

###socketClusterReducer - the reducer.

add this to your rootReducer, maybe something like this:

import {socketClusterReducer} from 'redux-socket-cluster`;
function reducer(state, action) {
  return {
    routing: routeReducer(state.routing, action),
    ...,
    socket: socketClusterReducer(state.socket, action)
  }
}

This initial state object is an Object that looks like this:

  id: null,
  socketState: CLOSED,
  authState: PENDING,
  authToken: null,
  authError: null,
  error: null,
  pendingSubs: [],
  subs: []

###reduxSocket(options, hocOptions) - a HOC to put on your highest level real-time component. eg @reduxSocket({authTokenName: 'MyApp.token'}, {keepAlive: 60000})

For example, if you use websockets for everything, stick this on the main app. If only certain components have websockets, stick this on those containers. The options are identical to what you'd pass in to the client socketCluster (http://socketcluster.io/#!/docs/api-socketcluster-client).

hocOptions can be a function that takes in props, or a simple object. If an object, it has the following properties:

  • keepAlive: The number of milliseconds to keep the socket connection alive after navigating away from the component. Defaults to 15 seconds. Say the client subs to 1000 items & accidently clicks a link that unmounts the component, if they make it back to the component before the time expires, you won't have to start a new connection or resend those 1000 documents. Plus, any docs that came in while they were away will be there too. Neat!
  • AuthEngine: a class that takes in a redux store and creates a socket cluster AuthEngine.
  • onConnect(options, hocOptions, socket): a callback that returns an active socket when a connection has been established. Useful if you want to do something like upgrade a transport from HTTP to sockets
  • onDisconnect(timedOut, options, hocOptions, socket): a callback that returns a Boolean that is true due to keepAlive expiring and the now inactive socket. Similar to above, this is useful if you want to downgrade something from a socket transport to HTTP.

NOTES:

  • This setup assumes you've already given the client a token (probably via HTTP). If you'd like socket-cluster to create a token for you, create an issue with your current workflow & together we can make a pretty API for that usecase.

That's it!

TODO

  • More tests!
  • Add option to create token from socket cluster

License

MIT