Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // redux utilities
- // create a store, apply middlewares to it
- import { createStore, applyMiddleware } from 'redux';
- // middleware to parse actions' promises
- import { promiseMiddleware } from './middleware';
- // defaultstate + trivial reducer
- const defaultState = {
- appName: 'conduit',
- articles: null,
- };
- const reducer = function(state = defaultState, action) {
- // update state based on the action type
- switch (action.type) {
- // HOME_PAGE_LOADED => put articles into state
- case 'HOME_PAGE_LOADED':
- return { ...state, articles: action.payload.articles };
- // unrecognized action type => don't change state
- default:
- return state;
- }
- };
- const middleware = applyMiddleware(promiseMiddleware);
- // create store
- const store = createStore(reducer, middleware);
- export default store;
Advertisement
Add Comment
Please, Sign In to add comment