redux-utilities / redux-promise

FSA-compliant promise middleware for Redux.
MIT License
2.67k stars 134 forks source link

Redux middleware configuration #11

Open spiroid opened 8 years ago

spiroid commented 8 years ago

Hi,

I'm trying to initialize redux with this middleware, but i can't get it working for now. I'm new to redux and started with a project based on redux 0.12

A short snippet of the application init steps:

...
import { createRedux, createDispatcher, composeStores } from 'redux';
import thunkMiddleware from 'redux/lib/middleware/thunk';
import promiseMiddleware from 'redux-promise';

import * as stores from '../stores';   

const dispatcher = createDispatcher( 
    composeStores(stores),
    [promiseMiddleware, thunkMiddleware]
);

const redux = createRedux(dispatcher);

A i missing something ? Thx for your help.

dariocravero commented 8 years ago

@spiroid I'd suggest you move to 1.0-rc already as it has important changes from 0.12 and 1.0 is just around the corner.

Adapting the release notes for redux-promise:

import { createStore, combineReducers, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import promise from 'redux-promise';
import * as reducers from '../reducers';

const initialState = {}; // or whatever it should be
const reducer = combineReducers(reducers);
const finalCreateStore = applyMiddleware(thunk, promise)(createStore);
const store = finalCreateStore(reducer, initialState);
spiroid commented 8 years ago

@dariocravero: many thanks this was very helpful.

I migrated to redux 1.0-rc and changed the application init code following your code snippet and the release notes.

Now it works with the async notation :+1:

@acdlite: could you please update the readme with this information to help newcomers ?