Giter VIP home page Giter VIP logo

redux-channels's Introduction

redux-channels

A provider and connect for getting websocket channels(ie, Socket.io/Phoenix/ActionCable) working with Redux.

This library was heavily inspired by and borrows code from react-redux and react-apollo.

Install

npm install --save redux-channels

Demo

There is a demo app over at presentation_app.

Usage

Phoenix channels

Phoenix channels are my primary target with the library.

import React from 'react';
import { render } from 'react-dom';
import { Socket } from 'phoenix';
import { SocketProvider } from 'redux-channels';

import configureStore from './store/configureStore';
import App from './containers/App';

const store = configureStore();

render(
  <SocketProvider store={store} socket={socket}>
    <App />
  </SocketProvider>,
  chatDOM
);
import { connect } from 'redux-channels';

class App extends React.Component {
  static propTypes = {
    messages: PropTypes.object,
    actions: PropTypes.object,
    someChannel: PropTypes.object
  };

  constructor(props) {
    super(props);
    const { actions, someChannel } = props;
    this.someChannel = someChannel;
    // Setup all your channel listening here
  }
}

const mapStateToProps = (state) => ({
  messages: state.messages
});
const mapDispatchToProps = (dispatch) => ({
  action: bindActionCreators(action, dispatch)
});
const mapSocketToProps = ({ socket, state }) => ({
  someChannel: socket.channel('some', { username: state.auth })
});
export default connect({
  mapStateToProps,
  mapDispatchToProps,
  mapSocketToProps
})(App);

socket.io

Use namespaces in socket.io to have different channels and follow the general pattern above.

redux-channels's People

Stargazers

Selvin avatar  avatar Dylan Bishop avatar Timon van Spronsen avatar sitch avatar Kevin Segal avatar Josh avatar Marc-Antoine Sauvé avatar Zen Savona avatar Jay Zeschin avatar Bill Gloff avatar Tom Crossland avatar Izaak Yusop avatar Daniel Farrell avatar  avatar

Watchers

Daniel Farrell avatar James Cloos avatar Marc-Antoine Sauvé avatar

Forkers

reyko

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.