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

Allow diferentiating selectors and selectors-with-props at runtime #2531

Closed
GregOnNet opened this issue May 19, 2020 · 1 comment
Closed

Comments

@GregOnNet
Copy link
Contributor

Hi,

thanks for providing NgRx and for putting that much effort into it for such a long time. I already did a lot of projects with it.

Describe any alternatives/workarounds you're currently using

The Library NgRx Ducks build dynamic facades.
One feature is that the helper bindSelectors consumes all selectors of a file and turns them automatically into consumable Observables.

// selectors.ts
export const books = createSelector(featureSelector, state => state.books);

// facade.ts
import * as selectors from './selectors.ts'

@StoreFacade()
export class BookFacade {
  select = bindSelectors(selectors);
}

// component.ts
@Component({ /* ... */ })
export class BookComponent {
  books: Observable<Book[]>;

  constructor(private bookFacade: BookFacade) {
    this.books = this.bookFacade.select.books;
  }
}

Currently, I am not able to support selectors accepting props since I cannot differentiate at runtime if I have to deal with a plain selector or not.

It would be nice to enable NgRx Ducks supporting selectors having properties.

  constructor(private bookFacade: BookFacade) {
    this.books = this.bookFacade.select.booksByCategory('sci-fi');
  }

Other information:

Differentiating at runtime

In NgRx Ducks the building Blocks are tagged to be able to know at runtime what data structure is passed.
For tagging an enum is used:

export enum DucksIdentifier {
  Duck,
  DuckDispatcherPlain,
  DuckDispatcherPayload,
  DuckPickFunction
}

Maybe a selector-factory could also be tagged.

If accepted, I would be willing to submit a PR for this feature

[x] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No

@brandonroberts
Copy link
Member

We've deprecated selectors with props, so closing for now

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

No branches or pull requests

2 participants