Skip to content

Commit 7ad76b8

Browse files
feat(router-store): rename getSelectors to getRouterSelectors (#3745)
Closes #3738
1 parent c21ee92 commit 7ad76b8

File tree

8 files changed

+59
-23
lines changed

8 files changed

+59
-23
lines changed

modules/router-store/spec/router_selectors.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
getSelectors,
2+
getRouterSelectors,
33
RouterReducerState,
44
DEFAULT_ROUTER_FEATURENAME,
55
createRouterSelector,
@@ -135,7 +135,7 @@ describe('Router State Selectors', () => {
135135
router: mockData,
136136
};
137137

138-
selectors = getSelectors();
138+
selectors = getRouterSelectors();
139139
});
140140

141141
it('should create selectCurrentRoute selector for selecting the current route', () => {
@@ -148,7 +148,7 @@ describe('Router State Selectors', () => {
148148
const stateOverwrite = {
149149
anotherRouterKey: mockData,
150150
};
151-
const selectorOverwrite = getSelectors(
151+
const selectorOverwrite = getRouterSelectors(
152152
(state: typeof stateOverwrite) => state.anotherRouterKey
153153
);
154154

@@ -162,7 +162,7 @@ describe('Router State Selectors', () => {
162162
const stateOverwrite = {
163163
[DEFAULT_ROUTER_FEATURENAME]: mockData,
164164
};
165-
const selectorOverwrite = getSelectors(createRouterSelector());
165+
const selectorOverwrite = getRouterSelectors(createRouterSelector());
166166

167167
const result = selectorOverwrite.selectCurrentRoute(stateOverwrite);
168168
expect(result).toEqual(
@@ -178,7 +178,7 @@ describe('Router State Selectors', () => {
178178
const state: State = {
179179
router: undefined,
180180
};
181-
selectors = getSelectors((state: State) => state.router);
181+
selectors = getRouterSelectors((state: State) => state.router);
182182

183183
const result = selectors.selectCurrentRoute(state);
184184

modules/router-store/spec/types/selectors.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { compilerOptions } from './utils';
44
describe('router selectors', () => {
55
const expectSnippet = expecter(
66
(code) => `
7-
import * as fromRouter from '@ngrx/router-store';
7+
import { getRouterSelectors, RouterReducerState } from '@ngrx/router-store';
88
import { createSelector, createFeatureSelector } from '@ngrx/store';
99
1010
export interface State {
11-
router: fromRouter.RouterReducerState<any>;
11+
router: RouterReducerState<any>;
1212
}
1313
1414
export const selectRouter = createFeatureSelector<
1515
State,
16-
fromRouter.RouterReducerState<any>
16+
RouterReducerState<any>
1717
>('router');
1818
1919
export const {
@@ -25,7 +25,7 @@ describe('router selectors', () => {
2525
selectRouteData,
2626
selectUrl,
2727
selectTitle,
28-
} = fromRouter.getSelectors(selectRouter);
28+
} = getRouterSelectors(selectRouter);
2929
3030
${code}
3131
`,

modules/router-store/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,9 @@ export {
4444
MinimalRouterStateSnapshot,
4545
MinimalRouterStateSerializer,
4646
} from './serializers/minimal_serializer';
47-
export { getSelectors, createRouterSelector } from './router_selectors';
47+
export {
48+
getRouterSelectors,
49+
getSelectors,
50+
createRouterSelector,
51+
} from './router_selectors';
4852
export { provideRouterStore } from './provide_router_store';

modules/router-store/src/router_selectors.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ export function createRouterSelector<
1313
return createFeatureSelector(DEFAULT_ROUTER_FEATURENAME);
1414
}
1515

16-
export function getSelectors<V extends Record<string, any>>(
16+
/**
17+
* @deprecated This function is deprecated in favor of `getRouterSelectors`.
18+
* For more info see: https://github.com/ngrx/platform/issues/3738
19+
*/
20+
export const getSelectors = getRouterSelectors;
21+
22+
export function getRouterSelectors<V extends Record<string, any>>(
1723
selectState: (state: V) => RouterReducerState<any> = createRouterSelector<V>()
1824
): RouterStateSelectors<V> {
1925
const selectRouterState = createSelector(

projects/example-app/src/app/reducers/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import {
66
ActionReducerMap,
77
MetaReducer,
88
} from '@ngrx/store';
9-
import * as fromRouter from '@ngrx/router-store';
9+
import {
10+
getRouterSelectors,
11+
routerReducer,
12+
RouterReducerState,
13+
} from '@ngrx/router-store';
1014

1115
/**
1216
* Every reducer module's default export is the reducer function itself. In
@@ -24,7 +28,7 @@ import { InjectionToken, isDevMode } from '@angular/core';
2428
*/
2529
export interface State {
2630
[fromLayout.layoutFeatureKey]: fromLayout.State;
27-
router: fromRouter.RouterReducerState<any>;
31+
router: RouterReducerState<any>;
2832
}
2933

3034
/**
@@ -37,7 +41,7 @@ export const ROOT_REDUCERS = new InjectionToken<
3741
>('Root reducers token', {
3842
factory: () => ({
3943
[fromLayout.layoutFeatureKey]: fromLayout.reducer,
40-
router: fromRouter.routerReducer,
44+
router: routerReducer,
4145
}),
4246
});
4347

@@ -60,7 +64,6 @@ export function logger(reducer: ActionReducer<State>): ActionReducer<State> {
6064
* the root meta-reducer. To add more meta-reducers, provide an array of meta-reducers
6165
* that will be composed to form the root meta-reducer.
6266
*/
63-
6467
export const metaReducers: MetaReducer<State>[] = isDevMode() ? [logger] : [];
6568

6669
/**
@@ -78,4 +81,4 @@ export const selectShowSidenav = createSelector(
7881
/**
7982
* Router Selectors
8083
*/
81-
export const { selectRouteData } = fromRouter.getSelectors();
84+
export const { selectRouteData } = getRouterSelectors();

projects/ngrx.io/content/examples/router-store-selectors/src/app/router.selectors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// #docregion routerSelectors
2-
import { getSelectors, RouterReducerState } from '@ngrx/router-store';
2+
import { getRouterSelectors, RouterReducerState } from '@ngrx/router-store';
33

44
// `router` is used as the default feature name. You can use the feature name
5-
// of your choice by creating a feature selector and pass it to the `getSelectors` function
5+
// of your choice by creating a feature selector and pass it to the `getRouterSelectors` function
66
// export const selectRouter = createFeatureSelector<RouterReducerState>('yourFeatureName');
77

88
export const {
@@ -16,5 +16,5 @@ export const {
1616
selectRouteDataParam, // factory function to select a route data param
1717
selectUrl, // select the current url
1818
selectTitle, // select the title if available
19-
} = getSelectors();
19+
} = getRouterSelectors();
2020
// #enddocregion routerSelectors

projects/ngrx.io/content/guide/migration/v15.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,26 @@ export class TestComponent {
221221
}
222222
```
223223

224+
## Deprecations
225+
226+
### @ngrx/router-store
227+
228+
#### Renamed `getSelectors` Function (Introduced in v15.2)
229+
230+
The `getSelectors` function is deprecated in favor of `getRouterSelectors`.
231+
232+
BEFORE:
233+
234+
```ts
235+
import { getSelectors } from '@ngrx/router-store';
236+
237+
const routerSelectors = getSelectors();
238+
```
239+
240+
AFTER:
241+
242+
```ts
243+
import { getRouterSelectors } from '@ngrx/router-store';
244+
245+
const routerSelectors = getRouterSelectors();
246+
```

projects/ngrx.io/content/guide/router-store/selectors.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Router selectors
22

3-
The `getSelectors` method supplied within `@ngrx/router-store` provides functions for selecting common information from the router state.
3+
The `getRouterSelectors` method supplied within `@ngrx/router-store` provides functions for selecting common information from the router state.
44

5-
The default behavior of `getSelectors` selects the router state for the `router` state key.
6-
If the default router state config is overwritten with a different router state key, the `getSelectors` method takes a selector function to select the piece of state where the router state is being stored.
5+
The default behavior of `getRouterSelectors` selects the router state for the `router` state key.
6+
If the default router state config is overwritten with a different router state key, the `getRouterSelectors` method takes a selector function to select the piece of state where the router state is being stored.
77
The example below shows how to provide a selector for the top level `router` key in your state object.
88

9-
**Note:** The `getSelectors` method works with the `routerReducer` provided by `@ngrx/router-store`. If you use a [custom serializer](guide/router-store/configuration#custom-router-state-serializer), you'll need to provide your own selectors.
9+
**Note:** The `getRouterSelectors` method works with the `routerReducer` provided by `@ngrx/router-store`. If you use a [custom serializer](guide/router-store/configuration#custom-router-state-serializer), you'll need to provide your own selectors.
1010

1111
Usage:
1212

0 commit comments

Comments
 (0)