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

Component-store: Add selector object for selector #3624

Closed
1 of 2 tasks
alex-okrushko opened this issue Oct 20, 2022 · 0 comments · Fixed by #3629
Closed
1 of 2 tasks

Component-store: Add selector object for selector #3624

alex-okrushko opened this issue Oct 20, 2022 · 0 comments · Fixed by #3629

Comments

@alex-okrushko
Copy link
Member

Which @ngrx/* package(s) are relevant/related to the feature request?

component-store

Information

the View Model selectors, that are selecting from multiple Observables and grouping into an object can have a lot of repetitions, e.g.:

readonly vm$: Observable<SomeViewModel> = this.select(
		this.selectedTab$,
		this.routerStateService.baseListRoute$,
		this.secondaryNavigationItems$,
		this.isFlaggedPage$,
		this.pageTitle$,
		this.hasError$,
		this.errorMessage$,
		(
			selectedTab,
			baseRoute,
			secondaryNavTabs,
			isFlaggedPage,
			pageTitle,
			hasError,
			errorMessage,
		) => ({
			selectedTab,
			baseRoute,
			secondaryNavTabs,
			isFlaggedPage,
			pageTitle,
			hasError,
			errorMessage,
		}),
		{ debounce: true },
	); 

Let's add an easier way, e.g.:

readonly vm$: Observable<SomeViewModel> = this.select({
		selectedTab: this.selectedTab$,
		baseRoute: this.routerStateService.baseListRoute$,
		secondaryNavTabs: this.secondaryNavigationItems$,
		isFlaggedPge: this.isFlaggedPage$,
		pageTitle: this.pageTitle$,
		hasError: this.hasError$,
		errorMessage: this.errorMessage$,
		},
		{ debounce: true },
	); 

RxJS' combineLatest already allows to do just that https://rxjs.dev/api/index/function/combineLatest

combineLatest(sourcesObject: T): Observable<{
    [K in keyof T]: ObservedValueOf<T[K]>;
}>

Describe any alternatives/workarounds you're currently using

No response

I would be willing to submit a PR to fix this issue

  • Yes
  • No
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants