Skip to content

Commit

Permalink
Revert "feat(router-store): add selectParamFromRouterState selector (#…
Browse files Browse the repository at this point in the history
…2771)" (#2845)

This reverts commit 3a1f359.
  • Loading branch information
brandonroberts authored Dec 29, 2020
1 parent 3a1f359 commit 8d4e8cc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 45 deletions.
19 changes: 2 additions & 17 deletions modules/router-store/spec/router_selectors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ const mockData = {
},
fragment: null,
firstChild: {
params: {
p: 'first-occurrence',
},
params: {},
paramMap: {
params: {
p: 'first-occurrence',
},
params: {},
},
data: {},
url: [
Expand All @@ -46,12 +42,10 @@ const mockData = {
firstChild: {
params: {
id: 'etyDDwAAQBAJ',
p: 'second-occurrence',
},
paramMap: {
params: {
id: 'etyDDwAAQBAJ',
p: 'second-occurrence',
},
},
data: {
Expand Down Expand Up @@ -188,15 +182,6 @@ describe('Router State Selectors', () => {
);
});

it('should create a selector for selecting the first occurrence of a specific route param', () => {
const result = selectors.selectParamFromRouterState('p')(state);

expect(result).toEqual(state.router.state.root.firstChild.params.p);
expect(result).not.toEqual(
state.router.state.root.firstChild.firstChild.params.p
);
});

it('should create a selector for selecting the route data', () => {
const result = selectors.selectRouteData(state);

Expand Down
3 changes: 0 additions & 3 deletions modules/router-store/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ export interface RouterStateSelectors<V> {
selectQueryParam: (param: string) => MemoizedSelector<V, string | undefined>;
selectRouteParams: MemoizedSelector<V, Params>;
selectRouteParam: (param: string) => MemoizedSelector<V, string | undefined>;
selectParamFromRouterState: (
param: string
) => MemoizedSelector<V, string | undefined>;
selectRouteData: MemoizedSelector<V, Data>;
selectUrl: MemoizedSelector<V, string>;
}
16 changes: 0 additions & 16 deletions modules/router-store/src/router_selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,6 @@ export function getSelectors<V>(
);
const selectRouteParam = (param: string) =>
createSelector(selectRouteParams, (params) => params && params[param]);
const selectParamFromRouterState = (param: string) =>
createSelector(selectRouterState, (routerState) => {
let paramValue: string | undefined;
let route = routerState?.root;

while (route?.firstChild) {
route = route.firstChild;
if (route?.params?.[param]) {
paramValue = route.params[param];
break;
}
}

return paramValue;
});
const selectRouteData = createSelector(
selectCurrentRoute,
(route) => route && route.data
Expand All @@ -72,7 +57,6 @@ export function getSelectors<V>(
selectQueryParam,
selectRouteParams,
selectRouteParam,
selectParamFromRouterState,
selectRouteData,
selectUrl,
};
Expand Down
17 changes: 8 additions & 9 deletions projects/ngrx.io/content/guide/router-store/selectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ export const selectRouter = createFeatureSelector<
>('router');

export const {
selectCurrentRoute, // select the current route
selectFragment, // select the current route fragment
selectQueryParams, // select the current route query params
selectQueryParam, // factory function to select a query param
selectRouteParams, // select the current route params
selectRouteParam, // factory function to select a route param
selectParamFromRouterState, // factory function to select the first occurrence of a route param
selectRouteData, // select the current route data
selectUrl, // select the current url
selectCurrentRoute, // select the current route
selectFragment, // select the current route fragment
selectQueryParams, // select the current route query params
selectQueryParam, // factory function to select a query param
selectRouteParams, // select the current route params
selectRouteParam, // factory function to select a route param
selectRouteData, // select the current route data
selectUrl, // select the current url
} = fromRouter.getSelectors(selectRouter);

export const selectSelectedCarId = selectQueryParam('carId');
Expand Down

0 comments on commit 8d4e8cc

Please sign in to comment.