Redux saga why select do not block? - redux

Why saga use a non blocking operation to retrive a value from an in memory object? Wouldn't be better just use a blocking operation like getState?

In redux-saga yield select() is synchronize, I don't understand why you say it's non blocking, or you should post more detail?
Use select effect but not call getState directly is good for test.

Related

If i have 100 reducers in my react app will all reducers get called when an action is dispatched?

If so will this lead to a performance issue ?
Secondly
Is there a way to specifically call a reducer without invoking all 100 reducers ?
This is specifically answered in the Redux FAQ:
https://redux.js.org/faq/performance#wont-calling-all-my-reducers-for-each-action-be-slow
It's important to note that a Redux store really only has a single reducer function.
However, even if you happen to have many different reducer functions composed together, and even with deeply nested state, reducer speed is unlikely to be a problem. JavaScript engines are capable of running a very large number of function calls per second, and most of your reducers are probably just using a switch statement and returning the existing state by default in response to most actions.
Also, "call a reducer" is the wrong mental model here. Actions are like "events" that are being broadcast - you don't ever "call a reducer" directly:
https://redux.js.org/style-guide/style-guide#model-actions-as-events-not-setters

Firestore callback inside of signInSuccessWithAuthResult to get extra userdata?

I'm using firebaseui, and it has the signInSuccessWithAuthResult callback which returns me the user.
So inside of there I want to call back out to a firestore document where I have more user profile data to use and save.
But I think this method is completing before the firestore .get() is and just never works.
Am I thinking about this problem wrong? Is this just not the right place to do this?
But I think this method is completing before the Firestore .get() is and just never works.
You are guessing right, the operation of adding a listener is asynchronous and returns immediately and the callback from the Task it returns will be called sometime later. There are no guarantees about how long it will take. Depending on your connection speed and the state, it may take from a few hundred milliseconds to a few seconds before the authentication process is complete.
If you want to use the results of your authentication process, you must wait until the asynchronous operation is complete. This means that you can only use the results inside the listener callback itself.

NgRx. Dispatching action with state information

I have the following use-case. I use NgRx Store/Effects and I need to send a request to my back-end service.
Request is initiated in my component, then dispatch to NgRx Effect and then sent to my back-end service.
But I need to attach a piece of state to my Http request. So far I see two ways of doing it:
1) Select state from Store in the component and include into Action as payload
2) Inject Store into Effect and select piece of the state from Store in the specific effect
What is the suggested way from NgRx-driven point of view?
Personally I would opt for option one if possible. Because it's easier to understand with the benefit that it's easy to test.
There are some times where this isn't possible or where it would cause too much overhead, if that's the case I use a withLatestFrom(storeSelector) inside an effect.

redux-thunk and redux-saga simultaneously

I've come across two sources where it explains how to use two middleware systems together.
The first one says:
You can add the saga middleware right alongside the thunk middleware. Remember, the order you list middleware does matter.
Code:
const store = createStore(reducer, applyMiddleware(thunk, sagaMiddleware))
The second one provides this part of code source2:
createStore(rootReducer,applyMiddleware(sagaMiddleware, thunk)
Is it ok? Or the first one just remind us that the order matters but in case of the order between saga and thunk it doesn't matter? Maybe there's other reasons to warn about order relatively saga and thunk?
Yes, you can absolutely use both middleware together.
The ordering matters because the middleware pipeline order is based on the order of arguments to applyMiddleware(). That said, it's primarily a concern when you have a custom middleware that calls next(action), which forwards the action to the next middleware in the pipeline. With thunks and sagas you're normally calling dispatch(action), which always starts at the beginning of the pipeline.
For more details, see the Redux FAQ entry on "what is the difference between next and dispatch in a middleware?".
you can use putResolve from saga api
putResolve(action)
Just like put but the effect is blocking (if promise is returned from dispatch it will wait for its resolution) and will bubble up errors from downstream.
https://redux-saga.js.org/docs/api/
Since redux-thunks return a promise, you can call them directly in your sagas and wait for a return value.
Also, it will bubble up any errors.

How to use flux with firebase's sometimes synchronous callbacks

I am trying to use flux with firebase, and found out that the Firebase.on() callbacks are sometimes triggered synchronously by a Firebase.set() called within the same client.
This does not jive with the flux pattern of dispatching an action when the user triggers a firebase set and another one when the value comes back, which will break the multiple dispatch invariant.
A workaround would be to delay the mutation calls with process.nextTick(). Is there a way to force the callbacks to be called in the next tick instead, like how promises work? Or is there a recommended pattern here?

Resources