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

Using selectors with props #33

Closed
BorisZubchenko opened this issue May 19, 2020 · 2 comments
Closed

Using selectors with props #33

BorisZubchenko opened this issue May 19, 2020 · 2 comments

Comments

@BorisZubchenko
Copy link

The bindSelectors function accepts only MemoizedSelector. It creates problems when selector list has MemoizedSelectorWithProps item.

I see that the decision was made since it's unclear how to update the existing API.
I'd like to discuss the ability to make bindSelectors accept MemoizedSelectorWithProps as well even if we cannot use it as it should be (maybe we can select them with a store).

I really love the way I encapsulate my selectors and make it accessible from facades only. I was trying usePick approach but it makes my selectors global-wide.

@GregOnNet
Copy link
Member

This is also a good catch.
Technically I am not able to do this yet.

This is because I can not differentiate plain selectors and selectors with props at runtime.
Both are similar.

I can differentiate on the type-level but not at runtime.
I planend to ask the NgRx-Team to support this.

I need to open an issue for that.

@GregOnNet
Copy link
Member

@BorisZubchenko NgRx Ducks 12.1 supports Selector Factories.
Example: https://stackblitz.com/edit/ngrx-ducks-12

The only thing you need to do is writing a selector wrapped by a factory:

export const currentCountWithOffset = (offset: number) =>
  createSelector(
    visitCounter,
    counter => counter.simple.count + offset
  );

NgRx Ducks will consume this factory and transform it to a new function, instrumenting the Store to return an Observable.

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

No branches or pull requests

2 participants