how to manipulate data in ngrx effect and return it as payload to action? - ngrx

i have ngrx effect that makes post to api and get response.
when i get the response i want to create instance of interface of this data and dispatch success action with this as payload.
the problem is that i get instead the success action the fail action.
but when i do it this way and dispatching success action with the data i get success as expected
what is the issue here?

Related

Redux Saga calling same type multiple times simultaneously with different data

Below is the flow of my app:
I have to fetch profile pics of creators of each posts in the list.
I have an action type FETCH_USER_PROFILE. The action contains userId to be passed to api call inside saga function.
Considering React application, the profile or Avatar component of the post dispatching the action based on the createdByUserId prop it receives from the parent post component.
I have a key in the reducer isFetchingUserDetails
whenever the action type FETCH_USER_PROFILE is dispatched, inside saga for it, I yield-put isFetchingUserDetails as true.
And when the response from api is received,I yield-put isFetchingUserDetails as false.
Based on isFetchingUserDetails I display the loader on Avatar component.
It works fine for one api call but when multiple dispatches of same action type is sent (with different userIds though) simultaneously, it modifies the isFetchingUserDetails continuously as api calls can take non-uniform time due to network constraints.
Due to this even for avatars or profile for which response is not fetched doesnot show loader because isFetchingUserDetails is set as true by the first response received.
Kindly suggest me what I can do in this scenario.
Should I make multiple action types with suffices as userId? Is this even possible?
Should I set isFetchingUserDetails suffixed with userId? But it would make multiple keys in reducers if the user count is 10k+

Servlet forward() from POST to GET

I'm using a simple servlet that receives a POST request and forwards it to another servlet that expects a GET request.
I'm aware as original HtppServletRequest is having POST as it's method, thus it's failing to forward. Also, the HtppServletRequest method property doesn't have a setter method, only way out i can see is to create a new request object with the method as GET and set the remaining contents same as the original request.
Is there any better way of doing it?

Macruby get an object to notify AppDelegate when its completed a task

I am super new to Macruby and I'm trying to write a small app that sends post data to an api and then displays the response in text field.
I have gotten as far as collecting, sending the data and having the response output to the console using this gist: https://gist.github.com/alloy/885125
What I want to know is how do I get the download object to notify the AppDelegate, either via an event or some other mechanism, that its completed so I can collects its response and add it to the text field object?
Thanks.
Rather than using the supplied gist as a separate object that calls the main class when its finished I moved all the methods into the main AppDelegate class and had it delegate to itself once the post methods had finished.

Asynchronous action for strongly-typed partial view in _Layout

So, here's the rundown...
I've got a master layout page for my MVC 4 app that has some dynamic information and needs to be strongly typed to a specific domain entity to get that information. To keep my files cleaner, I've extracted out the typed fields to a partial view.
To grab the entity I need and map it to the partial's view-model, I have a LayoutController with an action that returns a Task<PartialViewResult>. This action uses a service layer to make an async call out to a Web API project, awaiting the entity. It massages that entity into the view-model and then returns PartialView("_LayoutPartial", viewModel).
From within the _Layout page, the partial is called via:
#{Html.RenderAction("LayoutInfo", "Layout", new { /*entity primary key*/ });}
I've stepped through the code and it does indeed get the correct entity back, but then after returning the partial view task, I get everybody's favorite Server Error page with the following error:
HttpServerUtility.Execute blocked while waiting for an asynchronous operation to complete.
I've done some Googling and SO searching and have no idea what this actually means. Am I thinking through this correctly?
That error message means that you're trying to invoke (and wait on!) an asynchronous method from within a synchronous method. In your specific case, the synchronous method is HtmlHelper.RenderAction, and the asynchronous method is your Task-returning action method. The reason the error occurs is that the point of writing an asynchronous Task-returning method is presumably to avoid blocking a thread, but RenderAction can't return until the Task is complete, so RenderAction ends up blocking while waiting for the operation to finish.
One option is to make the method that RenderAction calls synchronous instead of asynchronous, keeping in mind that this will continue to block the original thread. Another option is to populate the layout data asynchronously from within the original action method, then to pass that via ViewData to the layout page.

ASP.NET MVC rendering common data such as notifications

In my requirement, all views should be able to display notifications based on what happened within Actions in the controllers. The implementation as it stands is in a BaseModel which is inherited by all Models needing to show notifications. Then, any view with this requirement simply calls:
#{ Html.RenderPartial("MessageCtrl", Model); }
And a notification is rendered. This works fine in cases where an Action is returning a view directly, and is usually handled like this in an Action:
model.SetMessage(response);
return View(model);
...where SetMessage updates the notification related properties of the model from an object returned from my service. All responses implemented an interface I created called IResponse, so messaging can be handled throughout.
The problem arrises when I need to return a View from a different Action and still show a notification.
For example, on my EditUser action, if edit was successful, I want to show the Index view. To achieve this from the EditUser action, I need to return RedirectToAction (because simply returning the view will return the correct view with the incorrect URL indicating it is EditUser when it is not). However, RedirectToAction loses all notion of my model and BaseModel, so by the time it redirects, it has lost my notification. I know I can use RouteValues, but that defeats the purpose of having a common base model driven notification approach. I even looked at the ViewBag (usually I dismiss it as the ugly part of MVC), but found that ViewBags only persist for the life time of a single request, and using RedirectToAction, the ViewBag is empty again by the time it hits the target Action. Another thought was to store it in a session object, but that sounds downright ugly to me.
This seems like its a pretty standard requirement. Is there a standardised approach to passing common data (like notifications) around to different views asside from through the querystring through a RedirectToAction?
I think you are looking for TempData which only persists data in session across one redirect.

Resources