-
-
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): concatLatestFrom operator #2760
feat(effects): concatLatestFrom operator #2760
Conversation
9bb6341
to
89238cd
Compare
Preview docs changes for 6e6e146 at https://previews.ngrx.io/pr2760-6e6e1463/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@david-shortman
Thanks for the PR. 👍
- Could you also provide the support for a single select without wrapping it into tuple?
- as for the naming (typically the hardest part 🙂), what do you think about
withLazyLatestFrom
?
a6b2d22
to
306378a
Compare
@alex-okrushko Have achieved allowing single observable or array of observables to be returned by factory function. I kept mulling the name over in my head, and I wonder if |
b6d1589
to
2d85933
Compare
@alex-okrushko benlesh over at RxJs gave a pretty good suggestion to use Wondering if the better direction would be updating the docs to use this simpler way to delay running Of course, |
What about creating just a wrapper function? export function withLazyLatestFrom(...observables: Observable): (source: Observable) => Observable {
return (source: Observable) => {
return source.pipe(concatMap((value) => of(value).pipe(withLatestFrom(...observables))));
};
} Typedefs omitted because I am not able to type it properly in order to infer all the types properly. |
@srnec your solution does not delay the evaluation of the input observable. The argument to the operator will be immediately evaluated unless you use a lambda and evaluate the lambda later. |
@david-shortman
|
@alex-okrushko ah, ok. I'll see what the RxJs folks think. Side-note, what would be the best path forward for this PR be TS version-wise? Do I need to target it to pre-V4, or just let this hang around while? |
TS 3.9, if possible. |
2d85933
to
3e2a37a
Compare
47bb85c
to
9136797
Compare
c65cda0
to
0f2b0e1
Compare
@david-shortman the API docs aren't showing in the preview. Will you take a look? |
9aa79f2
to
da63bcd
Compare
@david-shortman I'll take a look this week |
da63bcd
to
7f159eb
Compare
I'm not sure why this isn't showing in the PR preview for the API docs, but the changes LGTM and I think its ok to move forward with. I'll wait on @alex-okrushko or @timdeschryver to provide another review/approval before merging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work, David! Thank you so much!
Sorry that it took a bit longer than expected.
Let's address these comments and we'd be able to get it into v11, which hopefully can be release within next week or two.
>( | ||
observablesFactory: (value: V) => T extends Observable<unknown>[] ? [...T] : T | ||
) { | ||
return concatMap((value) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, when I write custom operators, I typically do
function myOperator(foo: string): (source: Observable<A>) => Observable<b> {
return source.pipe(
.... // here goes the implementation
)
}
I don't quite remember why that's the way to do it. E.g. @cartant also uses it in his article: https://ncjamieson.com/managing-operator-state/
Might be a good idea to do it this way anyway. (in the meantime, I'll try to find out why it's done so).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since writing this PR, I have spent more time on the RxJs docs site and found that they give the same another different recommendation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revising my statement- RxJs now provides the pipe
function to independently and more quickly create custom operators. No need to spend the extra characters referring to a source and writing details that expose a deeper understanding than necessary of the nature of observables.
7f159eb
to
6e6e146
Compare
Awesome work, @david-shortman 👍 |
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 is 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?