Skip to content

Commit 7c6d4e4

Browse files
feat(store): deprecate selectors with props (#2993)
1 parent a5a1330 commit 7c6d4e4

File tree

4 files changed

+79
-3
lines changed

4 files changed

+79
-3
lines changed

modules/store/src/models.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export interface StoreFeature<T, V extends Action = Action> {
4848

4949
export type Selector<T, V> = (state: T) => V;
5050

51+
/**
52+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
53+
*/
5154
export type SelectorWithProps<State, Props, Result> = (
5255
state: State,
5356
props: Props

modules/store/src/selector.ts

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export interface MemoizedSelector<
2828
clearResult: () => void;
2929
}
3030

31+
/**
32+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
33+
*/
3134
export interface MemoizedSelectorWithProps<
3235
State,
3336
Props,
@@ -122,6 +125,9 @@ export function createSelector<State, S1, Result>(
122125
s1: Selector<State, S1>,
123126
projector: (s1: S1) => Result
124127
): MemoizedSelector<State, Result>;
128+
/**
129+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
130+
*/
125131
export function createSelector<State, Props, S1, Result>(
126132
s1: SelectorWithProps<State, Props, S1>,
127133
projector: (s1: S1, props: Props) => Result
@@ -130,6 +136,9 @@ export function createSelector<State, S1, Result>(
130136
selectors: [Selector<State, S1>],
131137
projector: (s1: S1) => Result
132138
): MemoizedSelector<State, Result>;
139+
/**
140+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
141+
*/
133142
export function createSelector<State, Props, S1, Result>(
134143
selectors: [SelectorWithProps<State, Props, S1>],
135144
projector: (s1: S1, props: Props) => Result
@@ -140,15 +149,22 @@ export function createSelector<State, S1, S2, Result>(
140149
s2: Selector<State, S2>,
141150
projector: (s1: S1, s2: S2) => Result
142151
): MemoizedSelector<State, Result>;
152+
/**
153+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
154+
*/
143155
export function createSelector<State, Props, S1, S2, Result>(
144156
s1: SelectorWithProps<State, Props, S1>,
145157
s2: SelectorWithProps<State, Props, S2>,
146158
projector: (s1: S1, s2: S2, props: Props) => Result
147159
): MemoizedSelectorWithProps<State, Props, Result>;
160+
148161
export function createSelector<State, S1, S2, Result>(
149162
selectors: [Selector<State, S1>, Selector<State, S2>],
150163
projector: (s1: S1, s2: S2) => Result
151164
): MemoizedSelector<State, Result>;
165+
/**
166+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
167+
*/
152168
export function createSelector<State, Props, S1, S2, Result>(
153169
selectors: [
154170
SelectorWithProps<State, Props, S1>,
@@ -163,6 +179,9 @@ export function createSelector<State, S1, S2, S3, Result>(
163179
s3: Selector<State, S3>,
164180
projector: (s1: S1, s2: S2, s3: S3) => Result
165181
): MemoizedSelector<State, Result>;
182+
/**
183+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
184+
*/
166185
export function createSelector<State, Props, S1, S2, S3, Result>(
167186
s1: SelectorWithProps<State, Props, S1>,
168187
s2: SelectorWithProps<State, Props, S2>,
@@ -173,6 +192,9 @@ export function createSelector<State, S1, S2, S3, Result>(
173192
selectors: [Selector<State, S1>, Selector<State, S2>, Selector<State, S3>],
174193
projector: (s1: S1, s2: S2, s3: S3) => Result
175194
): MemoizedSelector<State, Result>;
195+
/**
196+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
197+
*/
176198
export function createSelector<State, Props, S1, S2, S3, Result>(
177199
selectors: [
178200
SelectorWithProps<State, Props, S1>,
@@ -189,6 +211,9 @@ export function createSelector<State, S1, S2, S3, S4, Result>(
189211
s4: Selector<State, S4>,
190212
projector: (s1: S1, s2: S2, s3: S3, s4: S4) => Result
191213
): MemoizedSelector<State, Result>;
214+
/**
215+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
216+
*/
192217
export function createSelector<State, Props, S1, S2, S3, S4, Result>(
193218
s1: SelectorWithProps<State, Props, S1>,
194219
s2: SelectorWithProps<State, Props, S2>,
@@ -205,6 +230,9 @@ export function createSelector<State, S1, S2, S3, S4, Result>(
205230
],
206231
projector: (s1: S1, s2: S2, s3: S3, s4: S4) => Result
207232
): MemoizedSelector<State, Result>;
233+
/**
234+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
235+
*/
208236
export function createSelector<State, Props, S1, S2, S3, S4, Result>(
209237
selectors: [
210238
SelectorWithProps<State, Props, S1>,
@@ -223,6 +251,9 @@ export function createSelector<State, S1, S2, S3, S4, S5, Result>(
223251
s5: Selector<State, S5>,
224252
projector: (s1: S1, s2: S2, s3: S3, s4: S4, s5: S5) => Result
225253
): MemoizedSelector<State, Result>;
254+
/**
255+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
256+
*/
226257
export function createSelector<State, Props, S1, S2, S3, S4, S5, Result>(
227258
s1: SelectorWithProps<State, Props, S1>,
228259
s2: SelectorWithProps<State, Props, S2>,
@@ -241,6 +272,9 @@ export function createSelector<State, S1, S2, S3, S4, S5, Result>(
241272
],
242273
projector: (s1: S1, s2: S2, s3: S3, s4: S4, s5: S5) => Result
243274
): MemoizedSelector<State, Result>;
275+
/**
276+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
277+
*/
244278
export function createSelector<State, Props, S1, S2, S3, S4, S5, Result>(
245279
selectors: [
246280
SelectorWithProps<State, Props, S1>,
@@ -261,6 +295,9 @@ export function createSelector<State, S1, S2, S3, S4, S5, S6, Result>(
261295
s6: Selector<State, S6>,
262296
projector: (s1: S1, s2: S2, s3: S3, s4: S4, s5: S5, s6: S6) => Result
263297
): MemoizedSelector<State, Result>;
298+
/**
299+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
300+
*/
264301
export function createSelector<State, Props, S1, S2, S3, S4, S5, S6, Result>(
265302
s1: SelectorWithProps<State, Props, S1>,
266303
s2: SelectorWithProps<State, Props, S2>,
@@ -283,13 +320,15 @@ export function createSelector<State, S1, S2, S3, S4, S5, S6, Result>(
283320
Selector<State, S1>,
284321
Selector<State, S2>,
285322
Selector<State, S3>,
286-
287323
Selector<State, S4>,
288324
Selector<State, S5>,
289325
Selector<State, S6>
290326
],
291327
projector: (s1: S1, s2: S2, s3: S3, s4: S4, s5: S5, s6: S6) => Result
292328
): MemoizedSelector<State, Result>;
329+
/**
330+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
331+
*/
293332
export function createSelector<State, Props, S1, S2, S3, S4, S5, S6, Result>(
294333
selectors: [
295334
SelectorWithProps<State, Props, S1>,
@@ -320,6 +359,9 @@ export function createSelector<State, S1, S2, S3, S4, S5, S6, S7, Result>(
320359
s7: Selector<State, S7>,
321360
projector: (s1: S1, s2: S2, s3: S3, s4: S4, s5: S5, s6: S6, s7: S7) => Result
322361
): MemoizedSelector<State, Result>;
362+
/**
363+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
364+
*/
323365
export function createSelector<
324366
State,
325367
Props,
@@ -362,6 +404,9 @@ export function createSelector<State, S1, S2, S3, S4, S5, S6, S7, Result>(
362404
],
363405
projector: (s1: S1, s2: S2, s3: S3, s4: S4, s5: S5, s6: S6, s7: S7) => Result
364406
): MemoizedSelector<State, Result>;
407+
/**
408+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
409+
*/
365410
export function createSelector<
366411
State,
367412
Props,
@@ -415,6 +460,9 @@ export function createSelector<State, S1, S2, S3, S4, S5, S6, S7, S8, Result>(
415460
s8: S8
416461
) => Result
417462
): MemoizedSelector<State, Result>;
463+
/**
464+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
465+
*/
418466
export function createSelector<
419467
State,
420468
Props,
@@ -470,6 +518,9 @@ export function createSelector<State, S1, S2, S3, S4, S5, S6, S7, S8, Result>(
470518
s8: S8
471519
) => Result
472520
): MemoizedSelector<State, Result>;
521+
/**
522+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
523+
*/
473524
export function createSelector<
474525
State,
475526
Props,
@@ -545,9 +596,15 @@ export function createSelectorFactory<T = any, V = any>(
545596
memoize: MemoizeFn,
546597
options: SelectorFactoryConfig<T, V>
547598
): (...input: any[]) => MemoizedSelector<T, V>;
599+
/**
600+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
601+
*/
548602
export function createSelectorFactory<T = any, Props = any, V = any>(
549603
memoize: MemoizeFn
550604
): (...input: any[]) => MemoizedSelectorWithProps<T, Props, V>;
605+
/**
606+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
607+
*/
551608
export function createSelectorFactory<T = any, Props = any, V = any>(
552609
memoize: MemoizeFn,
553610
options: SelectorFactoryConfig<T, V>

modules/store/src/store.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { ReducerManager } from './reducer_manager';
88
import { StateObservable } from './state';
99

1010
@Injectable()
11-
export class Store<T = object> extends Observable<T>
11+
export class Store<T = object>
12+
extends Observable<T>
1213
implements Observer<Action> {
1314
constructor(
1415
state$: StateObservable,
@@ -21,6 +22,9 @@ export class Store<T = object> extends Observable<T>
2122
}
2223

2324
select<K>(mapFn: (state: T) => K): Observable<K>;
25+
/**
26+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
27+
*/
2428
select<K, Props = any>(
2529
mapFn: (state: T, props: Props) => K,
2630
props: Props
@@ -130,9 +134,15 @@ export class Store<T = object> extends Observable<T>
130134

131135
export const STORE_PROVIDERS: Provider[] = [Store];
132136

137+
export function select<T, K>(
138+
mapFn: (state: T) => K
139+
): (source$: Observable<T>) => Observable<K>;
140+
/**
141+
* @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue}
142+
*/
133143
export function select<T, Props, K>(
134144
mapFn: (state: T, props: Props) => K,
135-
props?: Props
145+
props: Props
136146
): (source$: Observable<T>) => Observable<K>;
137147
export function select<T, a extends keyof T>(
138148
key: a

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ export const selectVisibleBooks = createSelector(
8282

8383
### Using selectors with props
8484

85+
<div class="alert is-critical">
86+
87+
Selectors with props are [deprecated](https://github.com/ngrx/platform/issues/2980).
88+
89+
</div>
90+
8591
To select a piece of state based on data that isn't available in the store you can pass `props` to the selector function. These `props` gets passed through every selector and the projector function.
8692
To do so we must specify these `props` when we use the selector inside our component.
8793

0 commit comments

Comments
 (0)