I have an ngrx meta-reducer which adjusts the payload of the action like so:
export function doSomething(reducer) {
return (state, action) => {
action.payload = 'fred'
return reducer(state, action)
}
}
export const metaReducers: MetaReducer<State>[] = [doSomething]
This works fine. However, I want the payload to be determined by the response of an asynchronous HTTP request. Something like this:
export function doSomething(reducer) {
return (state, action) => {
// ASSUME THE HTTP SERVICE IS AVAILABLE AS MAKING THE HTTP SERVICE AVAILABLE IS NOT A PROBLEM (trying to keep the code simple for illustration)
this.http.get('/some/data').subscribe((res) => {
action.payload = res.data
return reducer(state, action)
})
}
}
But this does not work. Anyone know how to achieve this? thx