0.2.5 • Published 8 years ago

redux-grout v0.2.5

Weekly downloads
5
License
MIT
Repository
github
Last release
8 years ago

Redux Grout

npm version npm downloads build status dependencies status codeclimate coverage license

Redux middleware, actions, and reducers for Grout.

Documentation

Middleware

import { createStore, applyMiddleware, compose } from 'redux';
import rootReducer from '../reducers'; // Combined reducers
import thunkMiddleware from 'redux-thunk';
import { createMiddleware } from 'redux-grout';

let groutMiddleware = createMiddleware();
const createStoreWithMiddleware = compose(
  // Save for redux middleware
  applyMiddleware(thunkMiddleware, groutMiddleware)
)(createStore);

Reducers

Add reducers to combineReducers function:

import { combineReducers } from 'redux';
import { routerStateReducer } from 'redux-router';
import { Reducers } from 'redux-grout';
const { account, files, entities} = Reducers;
const rootReducer = combineReducers({
  account,
  files,
  entities,
  router: routerStateReducer
});

export default rootReducer;

Actions

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

import React, { Component, PropTypes } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { Actions } from 'redux-grout';

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);
0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.8

8 years ago

0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago