Skip to content

Commit ccb3b93

Browse files
feat(store): deprecate createFeature signature with root state (#3756)
Closes #3737
1 parent e4f873b commit ccb3b93

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

modules/store/src/feature_creator.ts

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ export function createFeature<
8787
* @returns An object that contains a feature name, a feature reducer,
8888
* a feature selector, and a selector for each feature state property.
8989
*/
90+
export function createFeature<FeatureName extends string, FeatureState>(
91+
featureConfig: FeatureConfig<FeatureName, FeatureState> &
92+
NotAllowedFeatureStateCheck<FeatureState>
93+
): Feature<Record<string, any>, FeatureName, FeatureState>;
94+
/**
95+
* @deprecated Use the `createFeature` signature without root state instead.
96+
* For more info see: https://github.com/ngrx/platform/issues/3737
97+
*/
9098
export function createFeature<
9199
AppState extends Record<string, any>,
92100
FeatureName extends keyof AppState & string = keyof AppState & string,
@@ -110,13 +118,7 @@ export function createFeature<
110118
*
111119
* @usageNotes
112120
*
113-
* **With Application State**
114-
*
115121
* ```ts
116-
* interface AppState {
117-
* products: ProductsState;
118-
* }
119-
*
120122
* interface ProductsState {
121123
* products: Product[];
122124
* selectedId: string | null;
@@ -127,8 +129,7 @@ export function createFeature<
127129
* selectedId: null,
128130
* };
129131
*
130-
* // AppState is passed as a generic argument
131-
* const productsFeature = createFeature<AppState>({
132+
* const productsFeature = createFeature({
132133
* name: 'products',
133134
* reducer: createReducer(
134135
* initialState,
@@ -140,24 +141,13 @@ export function createFeature<
140141
* });
141142
*
142143
* const {
143-
* selectProductsState, // type: MemoizedSelector<AppState, ProductsState>
144-
* selectProducts, // type: MemoizedSelector<AppState, Product[]>
145-
* selectSelectedId, // type: MemoizedSelector<AppState, string | null>
146-
* } = productsFeature;
147-
* ```
148-
*
149-
* **Without Application State**
150-
*
151-
* ```ts
152-
* const productsFeature = createFeature({
153-
* name: 'products',
154-
* reducer: createReducer(initialState),
155-
* });
156-
*
157-
* const {
144+
* name,
145+
* reducer,
146+
* // feature selector
158147
* selectProductsState, // type: MemoizedSelector<Record<string, any>, ProductsState>
148+
* // feature state properties selectors
159149
* selectProducts, // type: MemoizedSelector<Record<string, any>, Product[]>
160-
* selectSelectedId, // type: MemoizedSelector<Record<string, any, string | null>
150+
* selectSelectedId, // type: MemoizedSelector<Record<string, any>, string | null>
161151
* } = productsFeature;
162152
* ```
163153
*

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,34 @@ export class TestComponent {
223223

224224
## Deprecations
225225

226+
### @ngrx/store
227+
228+
#### Deprecated `createFeature` Signature with Root State (Introduced in v15.2)
229+
230+
The `createFeature` signature with root state is deprecated in favor of a signature without root state.
231+
232+
BEFORE:
233+
234+
```ts
235+
interface AppState {
236+
users: State;
237+
}
238+
239+
export const usersFeature = createFeature<AppState>({
240+
name: 'users',
241+
reducer: createReducer(initialState, /* case reducers */),
242+
});
243+
```
244+
245+
AFTER:
246+
247+
```ts
248+
export const usersFeature = createFeature({
249+
name: 'users',
250+
reducer: createReducer(initialState, /* case reducers */),
251+
});
252+
```
253+
226254
### @ngrx/router-store
227255

228256
#### Renamed `getSelectors` Function (Introduced in v15.2)

0 commit comments

Comments
 (0)