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

pusher-redux-observable

v0.1.2

Published

redux-observable epic for Pusher

Downloads

375

Readme

pusher-redux-observable

redux-observable epic for Pusher

This project brings Pusher, rxjs Observables, and Redux together into one single flow. At the core of this flow is the redux-observable package which allows you to listen and respond to streams of redux actions asynchronously using rxjs Observables.

Installation

npm i pusher-redux-observable -D

All the functionality in this project has been combined into a top level 'pusherEpic' which can be added in to your redux-observable middleware:

import { pusherEpic } from 'pusher-redux-observable'
import { createEpicMiddleware, combineEpics } from 'redux-observable'
import { createStore, combineReducers, applyMiddleware } from 'redux'

const rootEpic = combineEpics(pusherEpic, ...myOtherEpics)

const store = createStore(
    combineReducers(...myReducers),
    applyMiddleware(
        createEpicMiddleware(rootEpic)
    )
)

After you have added the pusherEpic to your middleware chain, you can then start controlling Pusher by dispatching redux actions. The only way to interact with this package is by dispatching actions - actions in, actions out.

Create a connection

To create a new connection dispatch a PUSHER_CONNECT action:

import {PUSHER_CONNECT} from 'pusher-redux-observable'

dispatch({
    type: PUSHER_CONNECT,
    key: 'my_pusher_key'
    options: {
        cluster: 'eu'
    }
})

This will get picked up by the epic and a new connection will be created, which will result in a PUSHER_CONNECTION_SUCCESS or PUSHER_CONNECTION_ERROR action being dispatched.

To end the connection dispatch a PUSHER_DISCONNECT action

Subscribe to a channel

Once you have successfully connected, you will no doubt wish to subscribe to a channel. To subscribe to a channel you must dispatch a PUSHER_SUBSCRIBE_CHANNEL action with the name of the channel as a string

import {PUSHER_SUBSCRIBE_CHANNEL} from 'pusher-redux-observable'

const subscribeToChannels = action$ =>
        action$.ofType(PUSHER_CONNECTION_SUCCESS)
            .mapTo({type: PUSHER_SUBSCRIBE_CHANNEL, channel: 'myChannel'})

In this snippet we are listening for the PUSHER_CONNECTION_SUCCESS action and emitting a PUSHER_SUBSCRIBE_CHANNEL action in response

To unsubscribe to a channel you must similarly dispatch a PUSHER_UNSUBSCRIBE_CHANNEL action with the name of the channel

Receiving messages

When messages are received a PUSHER_MESSAGE_RECEIVED action will be emitted. This action has the following interface:

{
    type: PUSHER_MESSAGE_RECEIVED
    channel: string
    message: any
}

Most likely you will wish to write other epics that respond to these actions and dispatch further actions.