Building request from external middleware

This commit is contained in:
James Barnsley
2018-09-24 13:21:08 +12:00
parent 338410d846
commit 1bb0c80431
8 changed files with 14850 additions and 10945 deletions

View File

@ -75,10 +75,13 @@ export function connectionRemoved(connection){
}
}
export function instruct(data = null){
export function instruct(method, params = null, response_callback = null, error_callback = null){
return {
type: 'PUSHER_INSTRUCT',
data: data
method: method,
params: params,
response_callback: response_callback,
error_callback: error_callback
}
}

View File

@ -245,16 +245,22 @@ const PusherMiddleware = (function(){
break;
case 'PUSHER_INSTRUCT':
request(action)
request(store, action.method, action.params)
.then(
response => {
store.dispatch({ type: 'PUSHER_INSTRUCT', data: response.data })
if (action.response_callback){
store.dispatch(action.response_callback.call(this, response));
}
},
error => {
store.dispatch(coreActions.handleException(
'Instruct failed',
error
));
error => {
if (action.error_callback){
store.dispatch(action.error_callback.call(this, error));
} else {
store.dispatch(coreActions.handleException(
'Instruct failed',
error
));
}
}
);
break