npm

Join us for the "JavaScript Supply Chain Security" tech talk, presented by VP of Security, Adam Baldwin. 6/20 at 10am PT.Sign up here »

redux-matter

0.0.4 • Public • Published

Redux Matter

npm version npm downloads build status dependencies status license

Redux middleware, actions, and reducer for Matter.

Documentation

Middleware

import { createStore, applyMiddleware, compose } from 'redux';
import rootReducer from '../reducers'; // Combined reducers
import thunkMiddleware from 'redux-thunk';
import { createMiddleware } from 'redux-matter';
 
let matterMiddleware = createMiddleware('tessellate', {});
const createStoreWithMiddleware = compose(
  // Save for redux middleware
  applyMiddleware(thunkMiddleware, matterMiddleware)
)(createStore);

Reducers

Add reducers to combineReducers function:

import { combineReducers } from 'redux';
import { routerStateReducer } from 'redux-router';
import { Reducers } from 'redux-matter';
const rootReducer = combineReducers({
  account: Reducers.account,
  entities: Reducers.entities,
  router: routerStateReducer
});
 
export default rootReducer;

Actions

Example of using Actions from redux-matter in a smart component:

import React, { Component, PropTypes } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { Actions } from 'redux-matter';
 
class Main extends Component {
  constructor(props) {
    super(props);
    this.onLoginClick = this.onLoginClick.bind(this);
  }
  onLoginClick(e) {
    e.preventDefault();
    let testLogin = {username: 'test', password: 'asdfasdf'};
    this.props.login(testLogin);
  }
  render() {
    return (
      <div className="App">
        <button onClick={ this.onLoginClick }>Login</button>
      </div>
    )
  }
}
//Place state of redux store into props of component
function mapStateToProps(state) {
  return {
    account: state.account
  };
}
//Place action methods into props
function mapDispatchToProps(dispatch) {
  return bindActionCreators(Actions, dispatch);
}
 
export default connect(mapStateToProps, mapDispatchToProps)(Main);
 

install

npm i redux-matter

Downloadsweekly downloads

4

version

0.0.4

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability