From 46daba338a934841d742afb36286c286d49bcc81 Mon Sep 17 00:00:00 2001 From: timdeschryver <28659384+timdeschryver@users.noreply.github.com> Date: Sun, 11 Apr 2021 18:28:25 +0200 Subject: [PATCH 1/2] feat(store): deprecate selectors with props --- modules/store/src/models.ts | 3 ++ modules/store/src/selector.ts | 59 ++++++++++++++++++++++++++++++++++- modules/store/src/store.ts | 14 +++++++-- 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/modules/store/src/models.ts b/modules/store/src/models.ts index ae298e3a1e..d3813448fe 100644 --- a/modules/store/src/models.ts +++ b/modules/store/src/models.ts @@ -48,6 +48,9 @@ export interface StoreFeature { export type Selector = (state: T) => V; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export type SelectorWithProps = ( state: State, props: Props diff --git a/modules/store/src/selector.ts b/modules/store/src/selector.ts index 68e8824d80..96f4182d9d 100644 --- a/modules/store/src/selector.ts +++ b/modules/store/src/selector.ts @@ -28,6 +28,9 @@ export interface MemoizedSelector< clearResult: () => void; } +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export interface MemoizedSelectorWithProps< State, Props, @@ -122,6 +125,9 @@ export function createSelector( s1: Selector, projector: (s1: S1) => Result ): MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelector( s1: SelectorWithProps, projector: (s1: S1, props: Props) => Result @@ -130,6 +136,9 @@ export function createSelector( selectors: [Selector], projector: (s1: S1) => Result ): MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelector( selectors: [SelectorWithProps], projector: (s1: S1, props: Props) => Result @@ -140,15 +149,22 @@ export function createSelector( s2: Selector, projector: (s1: S1, s2: S2) => Result ): MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelector( s1: SelectorWithProps, s2: SelectorWithProps, projector: (s1: S1, s2: S2, props: Props) => Result ): MemoizedSelectorWithProps; + export function createSelector( selectors: [Selector, Selector], projector: (s1: S1, s2: S2) => Result ): MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelector( selectors: [ SelectorWithProps, @@ -163,6 +179,9 @@ export function createSelector( s3: Selector, projector: (s1: S1, s2: S2, s3: S3) => Result ): MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelector( s1: SelectorWithProps, s2: SelectorWithProps, @@ -173,6 +192,9 @@ export function createSelector( selectors: [Selector, Selector, Selector], projector: (s1: S1, s2: S2, s3: S3) => Result ): MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelector( selectors: [ SelectorWithProps, @@ -189,6 +211,9 @@ export function createSelector( s4: Selector, projector: (s1: S1, s2: S2, s3: S3, s4: S4) => Result ): MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelector( s1: SelectorWithProps, s2: SelectorWithProps, @@ -205,6 +230,9 @@ export function createSelector( ], projector: (s1: S1, s2: S2, s3: S3, s4: S4) => Result ): MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelector( selectors: [ SelectorWithProps, @@ -223,6 +251,9 @@ export function createSelector( s5: Selector, projector: (s1: S1, s2: S2, s3: S3, s4: S4, s5: S5) => Result ): MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelector( s1: SelectorWithProps, s2: SelectorWithProps, @@ -241,6 +272,9 @@ export function createSelector( ], projector: (s1: S1, s2: S2, s3: S3, s4: S4, s5: S5) => Result ): MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelector( selectors: [ SelectorWithProps, @@ -261,6 +295,9 @@ export function createSelector( s6: Selector, projector: (s1: S1, s2: S2, s3: S3, s4: S4, s5: S5, s6: S6) => Result ): MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelector( s1: SelectorWithProps, s2: SelectorWithProps, @@ -283,13 +320,15 @@ export function createSelector( Selector, Selector, Selector, - Selector, Selector, Selector ], projector: (s1: S1, s2: S2, s3: S3, s4: S4, s5: S5, s6: S6) => Result ): MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelector( selectors: [ SelectorWithProps, @@ -320,6 +359,9 @@ export function createSelector( s7: Selector, projector: (s1: S1, s2: S2, s3: S3, s4: S4, s5: S5, s6: S6, s7: S7) => Result ): MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelector< State, Props, @@ -362,6 +404,9 @@ export function createSelector( ], projector: (s1: S1, s2: S2, s3: S3, s4: S4, s5: S5, s6: S6, s7: S7) => Result ): MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelector< State, Props, @@ -415,6 +460,9 @@ export function createSelector( s8: S8 ) => Result ): MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelector< State, Props, @@ -470,6 +518,9 @@ export function createSelector( s8: S8 ) => Result ): MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelector< State, Props, @@ -545,9 +596,15 @@ export function createSelectorFactory( memoize: MemoizeFn, options: SelectorFactoryConfig ): (...input: any[]) => MemoizedSelector; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelectorFactory( memoize: MemoizeFn ): (...input: any[]) => MemoizedSelectorWithProps; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function createSelectorFactory( memoize: MemoizeFn, options: SelectorFactoryConfig diff --git a/modules/store/src/store.ts b/modules/store/src/store.ts index 0c8528b617..a6eca729d5 100644 --- a/modules/store/src/store.ts +++ b/modules/store/src/store.ts @@ -8,7 +8,8 @@ import { ReducerManager } from './reducer_manager'; import { StateObservable } from './state'; @Injectable() -export class Store extends Observable +export class Store + extends Observable implements Observer { constructor( state$: StateObservable, @@ -21,6 +22,9 @@ export class Store extends Observable } select(mapFn: (state: T) => K): Observable; + /** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ select( mapFn: (state: T, props: Props) => K, props: Props @@ -130,9 +134,15 @@ export class Store extends Observable export const STORE_PROVIDERS: Provider[] = [Store]; +export function select( + mapFn: (state: T) => K +): (source$: Observable) => Observable; +/** + * @deprecated Selectors with props are deprecated, for more info see {@link https://github.com/ngrx/platform/issues/2980 Github Issue} + */ export function select( mapFn: (state: T, props: Props) => K, - props?: Props + props: Props ): (source$: Observable) => Observable; export function select( key: a From 97ac4de7911466875bc4bbc727d3a6737ec46aee Mon Sep 17 00:00:00 2001 From: timdeschryver <28659384+timdeschryver@users.noreply.github.com> Date: Sun, 11 Apr 2021 18:31:10 +0200 Subject: [PATCH 2/2] docs(store): deprecate selectors with props --- projects/ngrx.io/content/guide/store/selectors.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/projects/ngrx.io/content/guide/store/selectors.md b/projects/ngrx.io/content/guide/store/selectors.md index 75964bb36b..755aa99742 100644 --- a/projects/ngrx.io/content/guide/store/selectors.md +++ b/projects/ngrx.io/content/guide/store/selectors.md @@ -82,6 +82,12 @@ export const selectVisibleBooks = createSelector( ### Using selectors with props +
+ +Selectors with props are [deprecated](https://github.com/ngrx/platform/issues/2980). + +
+ 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. To do so we must specify these `props` when we use the selector inside our component.