-
Notifications
You must be signed in to change notification settings - Fork 87
How to chain action Promise #66
Comments
If you don't have control over the
I'll admit I'm unclear on the code, exactly. But you might want to do something like:
Though I would probably discourage this coupling/chaining of actions and consider consolidating into one action. If you really want this complication That error means you're triggering a dispatch of a non-object somewhere, likely in a middleware. Redux thunk also exists, and there's no reason you can't use it alongside the Promise middleware included here, or switch to i entirely. IMO it can get a little messy/hard to read, but it is very flexible. |
Thanks for the answer, yeah it is asyn operation, that is the reason. Do you suggest changing from promiseMiddleware to redux saga or thunk? is it easy to change that in your code? do you suggest that way, because i am using your code as boilerplate and project is up and running. |
I personally prefer writing promise middleware to thunk, and as long as you understand the code you can really extend it to do whatever you want. If you look at saga or thunk and like either you can start using them. For this case though any of my above solutions should work fine, you can chain async actions with the promise middleware as in the last example. I would just say that if you're chaining a bunch of actions you should think about refactoring them, because coupling actions isn't a really a desirable pattern. That said I would always advocate your better judgment! Don't worry so much about the implementation, worry that you understand it, are comfortable working with and extending it etc. To be clear, the first example above is to combine these things into one action (ie, if they will always be run in sequence) and to adapt the callback code to a promise. The second example is how to do it without much refactoring, just dispatch and use use |
Thanks @bananaoomarang , i liked both your solutions, let me try now. |
i will change the code like this, do you agree
|
That looks good to me |
Works like a charm, thank you. I know this is more like issues forum, if i want to ask you questions in future, what is best place to reach you? |
This works fine for me (though I can’t promise quick replies) I think my email is on my Github profile page too? If not you can just use On Fri, 30 Sep 2016, 15:34 govind999, [email protected] wrote:
|
Just one more question, as it is rawHTML, i am planning to get it from store.getState().RawHTMLdata and pass to template of HTML. Because the HTML is in state its messing up UI. How can use and then delete it from store before i send it to UI? any ideas? |
Not sure what you mean by this. Maybe you want: https://facebook.github.io/react/tips/dangerously-set-inner-html.html |
What i mean to say is when the reducer has HTML data, it will go to store and then go UI as initial state right? so its rawHTML and is messing up UI. I thought i will grab the HTML from store and then send to template and delete it from store before sending to store, i posted on stack overflow too.. http://stackoverflow.com/questions/39799728/delete-one-reducer-data-from-store-before-rendering |
Hmmm, I wouldn't necessarily advise putting HTML in the store but AFAIK no reason you shouldn't be able to. The Are you seeing errors in the console or are you just unable to display it? If it's the latter you probably just have to signal you want it to be displayed as HTML and not text. As I say, no technical reason you can't do this, but you might want to consider if it's the best approach. |
If i keep the HTML in the store, the initial state which goes to UI has this data. So the html is getting printed on the page from store object as they are HTML tags, So want i did is, i manually removed that html from initial state.
const HTMLstr = '<!doctype html>' +
|
Hi Team,
I am following your code boilerplate for my project, I ran into a situation where i am making an API call which responds with xml data, so i need to parse that data and then send to reducer. May i know how to do that.
Then it has to send the raise the event. I tried as below but it is throwing error
I am getting below error
Error: Actions must be plain objects. Use custom middleware for async actions.
Thanks.
The text was updated successfully, but these errors were encountered: