-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(effects): add lazy concatLatestFrom operator for TS 3.9 #2799
Conversation
5f8fd1c
to
696d142
Compare
Preview docs changes for 15390a3 at https://previews.ngrx.io/pr2799-15390a30/ |
Fun(?) note: In the series of function overload declarations, the declaration that comes last MUST come last. I was losing my sanity trying to figure out why the types weren't working when it was put at the top. Apparently, when TS attempts to check if a function call matches a signature, it would refuse to believe an array could be narrowed to any of the tuples in the signatures. |
696d142
to
e7eb24e
Compare
e7eb24e
to
15390a3
Compare
hey @david-shortman great to see this implementation :) I had this question around using |
In the following image, the source observable is the first stream. The second stream is the input observable which we want the latest value from. The bottom stream is the output, which emits a value every time the source stream emits a value, and attaches (concats) the latest value from the second stream to it. I am not sure in what way you are using someEffect = createEffect(() =>
this.actions.pipe(
ofType(SomeAction),
withLatestFrom(this.store.select(selectSomething)),
tap(() => console.log('effect triggered'))
); then
The reason for creating |
hey @david-shortman thank you for the great explanation.
So in this example above, the log inside |
So when you use Using a flattening operator (or My hypothesis for why you're seeing a tap is that, once you've set up a pipe from the observable produced by store.select, the selector's value continues to change in your application, and that tap continues to be executed for each change because it was part of an observable that was subscribed to. This would only occur after the effect has run once, however. That hypothesis sounds kinda wrong tho. To continue talking about this stuff since it's not entirely relevant to the PR, if you want you can open a StackOverflow question and we can converse about it there. |
hey @david-shortman thank you for getting back. The reason I asked this question here is if that was something it could be addressed along with the PR.
Does this mean the log happens only because there is a subscription? or the Again, raising this here along with the PR is because the PR is related to improving how some behaviour around this is currently handled in NgRx. But if you think this isn't the right place, I can create a question on StackOverflow. Thanks |
There's just a lot of nuance that has to be described to give a complete picture. And describing that nuance is what is irrelevant to the PR 😅. Also, Here's a nuanced explanation: Concept 1- How a Javascript engine will evaluate the declaration of an Observable with a
|
Thank @david-shortman for the explanation. This is very detailed 👍 I can see why it is a nuance. |
@alex-okrushko I didn't know if I needed to do anything else to mark this PR as ready for review... so I'm just throwing out that this PR is ready for review 😅 |
@david-shortman |
Oh yeah look at that. I'll close this and move my documentation updates to #2760 |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
The NgRx Effects docs tell us:
An operator which does this for consumers of NgRx would be nice to have, but does not currently exist.
Closes #2222
What is the new behavior?
store.select
(or any arbitrary function that produces an observable) are delayed until the function provided toconcatLatestFrom
is calledDoes this PR introduce a breaking change?
Other information