question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

support for asynchronous actions

See original GitHub issue

i keep getting the following error for async actions

action with type undefined did not modify the data in any reducer.You may have mutated state directly or you may have a typo in your reducer

i think this is because of the following code in the middleware.

const prevState = getState();
const result = next(action);
const nextState = getState();

Since the action here is a function which returns a promise we need to compare the nextState with the prevState only after the promise has been resolved. Something like the following might fix the issue

const prevState = getState();
const result = Promise.resolve(next(action));
result.then(() => {
    const nextState = getState();
    if (prevState === nextState) {
        callback(action);
    }
});

return result;

The above issue will only happen if thunk middleware is added after the redux-unhandled-action middleware. Something like the following

applyMiddleware(reduxUnhandledAction(), thunk)

But if we add thunk at the beginning, then this issue will not happen as the async action will not be forwarded to the other middlewares. So the following will work fine

applyMiddleware(thunk, reduxUnhandledAction())

So I am not sure if there is need to fix it. If this is the expected behavior, then the issue can be closed.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
conorhastingscommented, Oct 6, 2017

@oyeanuj should be position agnostic now

0reactions
oyeanujcommented, Oct 6, 2017

@conorhastings @amit1911 So, is the middleware position agnostic? Or does it come at the end?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use promises - Learn web development | MDN
With a promise-based API, the asynchronous function starts the operation and returns a Promise object. You can then attach handlers to this ...
Read more >
Redux Fundamentals, Part 6: Async Logic and Data Fetching
The official Redux Fundamentals tutorial: learn how to use async logic ... It only knows how to synchronously dispatch actions, update the ...
Read more >
Synchronous and Asynchronous Actions - Micro Focus
The actions that you send to Media Server can be synchronous or asynchronous. Media Server does not respond to a synchronous action until...
Read more >
Asynchronous Programming - Eloquent JavaScript
One approach to asynchronous programming is to make functions that perform a slow action take an extra argument, a callback function. The action...
Read more >
Task asynchronous programming model - Microsoft Learn
Asynchrony is essential for activities that are potentially blocking, such as web access. Access to a web resource sometimes is slow or delayed....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found