Skip to content
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 #2798

Closed

Conversation

david-shortman
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

The NgRx Effects docs tell us:

Note: For performance reasons, use a flattening operator in combination with withLatestFrom to prevent the selector from firing until the correct action is dispatched.

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?

  • Calls to store.select (or any arbitrary function that produces an observable) are delayed until the function provided to concatLatestFrom is called
  • The lazy function can pass the current value in such that you can select using a selector factory like so:
concatLatestFrom((action) =>
        [this.store.select(getInfo(action.infoId)),
        this.store.select(selectOtherData)],
      ),

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

  • I have opened a separate PR with much simpler types for TS 4.X

@david-shortman
Copy link
Contributor Author

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.
Moving the function signature that uses no array for the observable factory to the bottom fixed this but I don't know why.

@ngrxbot
Copy link
Collaborator

ngrxbot commented Nov 25, 2020

Preview docs changes for cc60fe4 at https://previews.ngrx.io/pr2798-cc60fe41/

@david-shortman
Copy link
Contributor Author

I'm seeing test failures that aren't for the two brand new files, but it might be bc I was out of date with master? Seems unlikely but closing this one and opening #2799

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: Change behavior of ofType in Effects to be more consistent when combining observables
2 participants