Can we combine multiple pipeable selectors in the same manner as regular selectors?
Combining regular selectors:
export const selectActiveOrganization = createSelector(
selectOrganizations,
selectActiveOrganizationId,
(organizations, activeOrgId) => organizations[activeOrgId],
);
In the example above, two selectors selectOrganizations
and selectActiveOrganizationId
are used to create selectActiveOrganization
using createSelector
.
The issue here is that selectActiveOrganization
can potentially return undefined
.
Let's now convert this into a pipeable selector:
const _selectActiveOrganization = createSelector(
selectOrganizations,
selectActiveOrganizationId,
(organizations, activeOrgId) => organizations[activeOrgId],
);
export const selectActiveOrganizationPipeable = pipe(
select(_selectActiveOrganization),
filter(activeOrg => !!activeOrg),
);
In selectActiveOrganizationPipeable
, we have enhanced the original selector to only emit a value if there is an active organization.
Now let's assume we want to extend our pipeable selector to extract only the organization name.
export const selectActiveOrganizationNamePipeable = pipe(
select(selectActiveOrganizationPipeable),
map(organization => organization.name), // --> TS ERROR: Property 'name' does not exist on type 'Observable<Organization>'.ts(2339)
);
Is it possible to reuse the existing selectActiveOrganizationPipeable
? (similar to how we reuse regular selectors)