1.14.2 • Published 6 years ago

@thehandsomepanther/brandibble-redux v1.14.2

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Brandibble Redux

npm CircleCI Status Open Source Love

A set of actions, reducers, and redux middleware for Brandibble.

Configuration

Middleware

import { brandibbleMiddleware } from 'brandibble-redux';
import { createStore, applyMiddleware, compose } from 'redux';

const store = createStore(
  ...
  compose(
    applyMiddleware(...brandibbleMiddleware),
  )
  ...
);

Actions

import { fetchAllergens } from 'brandibble-redux';

...
dispatch(fetchAllergens(brandibble));
...

Reducers

import { reducer as brandibbleReducer } from 'brandibble-redux';
import { combineReducers } from 'redux';

export default combineReducers({
  ...
  brandibble: brandibbleReducer,
  ...
});

Example

import App from './components/App';
import LoadingState from './components/LoadingState';
import {
  Brandibble,
  setupBrandibbleRedux,
} from 'brandibble-redux';
import { connect } from 'redux';
import { Component } from 'react'; // or 'react-native'

const brandibble = new Brandibble({
  // ...config
});

const mapStateToProps = state => {
  const { setupBrandibbleRedux } = state.brandibble.status;

  return {
    loaded: setupBrandibbleRedux === 'FULFILLED',
  };
};

const mapDispatchToProps = dispatch => {
  setup: () => dispatch(setupBrandibbleRedux(brandibble)),
};

@connect(mapStateToProps, mapDispatchToProps)
export default class Main extends Component {

  componentWillMount() {
    setup();
  }

  render() {
    const { loaded } = this.props;
    return loaded ? <LoadingState /> : <App />;
  }
}

Working on Brandibble Redux

IMPORTANT: Set an environment variable called BRANDIBBLE_API_KEY by making a file named .env in the root of this directory and filling it out with your Brandibble API key before running tests (see .env.example for an example).

git clone https://github.com/sanctuarycomputer/brandibble-redux
cd brandibble-redux
npm install

// Run tests (in chrome) with:
npm test