Add some success action chaining

This commit is contained in:
Jake Howard 2016-05-02 21:07:07 +01:00
parent 5407f6bfe5
commit 61f1cd1163
4 changed files with 14 additions and 3 deletions

View file

@ -5,12 +5,12 @@ import endpoints from '../settings/endpoints';
export const LOGIN = makeAsyncActionSet('LOGIN');
export function login(token) {
export function login(token, callback) {
return buildAsyncAction(
LOGIN,
endpoints.get('USER_INFO').query({ 'circle-token': token }).toString(),
methods.GET,
{},
{ token }
{ token, callback }
);
}

View file

@ -121,7 +121,7 @@ export class Login extends React.Component {
loaderHandler.hideLoader();
return;
}
this.props.login(this.state.token);
this.props.login(this.state.token, this.props.nav.push.bind(this.props.nav, RouteMaster.get('HOME')));
}
showAbout() {

View file

@ -0,0 +1,9 @@
export default store => next => action => {
if (action.meta &&
action.meta.callback &&
action.type.endsWith('SUCCESS') &&
typeof action.meta.callback === 'function') {
action.meta.callback();
}
return next(action);
};

View file

@ -7,6 +7,7 @@ import createEngine from 'redux-storage-engine-reactnativeasyncstorage';
import filter from 'redux-storage-decorator-filter';
import { apiMiddleware } from 'redux-api-middleware';
import actionChain from './middleware/actionChain';
const engine = filter(createEngine(settings.get('STORAGE_KEY')));
@ -18,6 +19,7 @@ export default function configureStore(initialState) {
const createStoreWithMiddleware = applyMiddleware(
apiMiddleware,
actionChain,
storeMiddleware // Last in list
)(createStore);