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

pubnub-redux

v0.0.13

Published

[![Build Status](https://travis-ci.com/pubnub/redux.svg?branch=master)](https://travis-ci.com/pubnub/redux)

Downloads

547

Readme

PubNub Redux SDK

Build Status

The PubNub Redux SDK offers a data management framework that listens to realtime events generated by the PubNub network to update the view inside your application. And of course, your data can coexist with PubNub-defined data.

The Redux SDK is an npm module that provides Redux-specific functions which can be integrated with your existing or new Redux data store.

Note: This is a beta version of the PubNub Redux SDK

Table of Contents

Concepts

The PubNub Redux SDK includes the following components that you help manage your application’s state and PubNub server communications.

  • Actions: Preconfigured actions that correspond to PubNub internals
  • Reducers: Configured to respond to the actions dispatched by the PubNub Redux SDK
  • Listeners: Monitor subscription notifications and dispatch actions
  • Commands: Functions that execute PubNub API calls and dispatch actions

Supported Features

  • Sending and Receiving Messages
  • Indicating User Presence
  • Monitoring Network Status
  • Managing User Data
  • Managing Channel Data
  • Managing Channel Memberships

Not Yet Supported

  • PubNub Access Manager
  • Storage and Playback
  • Signals
  • Message Actions

Dependencies

  • pubnub 4.28.3 or later
  • redux 4.0.4 or later
  • redux-thunk 2.3.0 or later

Setup Instructions

This section provides the basic integration setps to connect the PubNub Redux SDK into your existing application. For an example of an application built on top of this SDK, go to our reference application site at: https://www.pubnub.com/docs/chat/quickstart

Before You Begin

Before you can create an application with the PubNub Redux SDK, obtain a set of chat-optimized keys from your PubNub Dashboard.

In the following instructions, replace the following references with key values from your PubNub Dashboard.

  • myPublishKey
  • mySubscribeKey

Install the PubNub Redux libraries

npm install redux
npm install redux-thunk
npm install pubnub
npm install pubnub-redux

Configure the Store

A Redux application manages all application state in a centralized location called the store. To gain the benefits offered by the PubNub Redux SDK, you must configure your store to include references to the PubNub libraries.

Create the PubNub instance

let pubnub = new Pubnub({
  publishKey: "myPublishKey",
  subscribeKey: "mySubscribeKey"
});

Configure Reducers

let rootReducer = combineReducers(
  createNetworkStatusReducer(false),
  createMessageReducer(),
  createPresenceReducer(),
  createUUIDMetadataReducer(),
  createUUIDMetadataListReducer(),
  createChannelMetadataReducer(),
  createChannelMetadataListReducer(),
  createMembershipReducer(),
  createChannelMembersReducer(),
);

Configure Redux Thunk Middleware

The PubNub Redux SDK uses Redux Thunk to manage the interaction with commands that execute PubNub API calls, process the responses, and dispatch Redux actions.

let thunkArgument = {
  pubnub: {
    api: pubnub
  }
};

let middleware = applyMiddleware(ReduxThunk.withExtraArgument(thunkArgument));

Complete the Store Configuration

let myStore = createStore(
  rootReducer,
  undefined,
  middleware,
);

Register Listeners

You can register all the listeners that are included in the PubNub Redux SDK.

pubnub.addListener(createPubnubListener(store.dispatch));

You can also choose to register only specific listeners and combine with other listeners in your application.

pubnub.addListener(
  combineListeners(
    createNetworkStatusListener(store.dispatch),
    createMessageListener(store.dispatch),
    createPresenceListener(store.dispatch),
    // a custom listener
    {
      status: (status) => {
          console.log(status)
      }
    }
  )
);

Usage Examples

This section contains a few examples of commands to get your started. This is not meant to be an exhaustive list. Also, you can create commands in your application that use our actions to meet your requirements.

Sending a Message

dispatch(sendMessage({
  channel: 'my-channel',
  message: {
    title: 'hello world',
    body: 'This is our hello world message.'
  }
}));

Set User Data

dispatch(setUserData({
  uuid: 'my-user-id',
  data: {
    name: 'User Name'
  }
}));

Fetch User Data

dispatch(fetchUserData({
  uuid: 'my-user-id'
}));

Set Channel Data

dispatch(setChannelData({
  channel: 'my-channel-id',
  data: {
    name: 'Channel Name'
  }
}));

Set Memberships

dispatch(setMemberships({
  uuid: 'my-user-id',
  channels: [{
    id: 'channel-id'
  }]
}));