why shoud I use Redux-Thunk instead of a custom middleware? - redux

I have the following middleware.
this middleware acts like the redux-thunk middleware, but passing the dispatcher and the state getter to the action creator function, but also I pass the next middleware that can be called. in this case I can export all my middlewares like this
so In my action creator, instead of dispatching the action, I just pass it to the next middleware.
I just want to know why I should use redux-thunk instead of this simple customThunk middleware?

Related

How can I resolve Promise pending output in nestjs framework?

I am building application in nodejs where I have to display the data by hitting the HTTPS endpoint. I am using Swagger UI to display the data.
If this is the built in HttpService in NestJS, the service returns an RxJS Observable which by default is not awaitable. You can tack on a toPromise() to convert the Observble to a promise that can be awaited and should have the awaited response from there. Otherwise, you can remove the await and make the function non-async, returning the observable and letting NestJS subscribe to it under the hood.
Important side note: You'll need to make sure that you don't try to send back the raw Axios response, as there are circular references that Nest will not e able to stringify. Look into the observable pipe and map operators, or use a then after the toPromise() and map the response that way
If you are not required to user HttpService from NestJs, you can use request-promise-native or request-promise. These packages will return Promises by default and you can await them.
Hope it helps!

Redux-saga: what mechanism makes it possible for redux-saga middleware to wait and not block everything else

Redux-saga middleware gives us the feeling as if it runs on a separate thread. When it is told to wait for a certain action to be dispatched by the saga(generator function), it suspends the saga until the action of interest is dispatched. Single js runtime is single threaded, how saga middleware waits for an action to be dispatched and at the same time not block everything else?
Waiting for actions works like this:
For any take() effect redux-saga middleware makes an entry in takers array. An entry contains the pattern and the suspended generator.
On any action dispatch the middleware checks the action against the takers array. Matching generators are scheduled to be run.
This is asynchronous waiting that doesn't involve blocking anything.

How to keep my reducer pure when using Redux Promise Middleware?

I'm using Redux Promise Middleware and my action creator returns an action with a promise.
Now, in the reducer, I receive the resolved promise data and I have to 'provide' the new state. I also have to do something that is not 'pure' with that data, e.g., store it in local storage.
How should I approach this situation and still keep the reducer pure? That data is obtained in middleware and the first time I get it is in reducer.
I know I can handle the promise in my action creator and access the data before dispatching the action but is there another better way?
You can create your own middleware!
You can call it localStorage-middleware for instance and you can dispatch the action before providing your data to the reducer. Your middleware will listen to that action, like dispatch(saveDataToLocalStorage(dataToSave))

When to Commit Unit Of Work using SignalR?

I'm trying to use the Unit Of Work pattern with RavenDb and SignalR. However, I can't find a clear SignalR Hub event to use as the hook to call SaveChanges on my RavenDb document session.
If it was MVC I'd use Application_EndRequest in Global.asax or OnActionExecuted in my Controller, but what equivalent is there for a SignalR Hub?
You could register a custom Hub pipeline module that overrides the HubPipelineModule.OnAfterIncoming method.
OnAfterIncoming will be called upon the completion of each Hub method.

Understanding Async Methods in Web Service

I consume Java Service in my .NET appliaction. I have one question: When service serialize in .NET he also create Async methods. For example for GetPersons() method service create GetPersonsAsync() which is return void. In which cases I can use this Async methods and what the destination of these methods.
Generally, for async methods, you also need to specify a callback method. The called web method immediately returns but keeps working in the backround. When its done, it invokes your callback method with its results

Resources