Skip to content

Commit

Permalink
feat(store): deprecate createFeature signature with root state (#3756)
Browse files Browse the repository at this point in the history
Closes #3737
  • Loading branch information
markostanimirovic authored Jan 24, 2023
1 parent e4f873b commit ccb3b93
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
38 changes: 14 additions & 24 deletions modules/store/src/feature_creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ export function createFeature<
* @returns An object that contains a feature name, a feature reducer,
* a feature selector, and a selector for each feature state property.
*/
export function createFeature<FeatureName extends string, FeatureState>(
featureConfig: FeatureConfig<FeatureName, FeatureState> &
NotAllowedFeatureStateCheck<FeatureState>
): Feature<Record<string, any>, FeatureName, FeatureState>;
/**
* @deprecated Use the `createFeature` signature without root state instead.
* For more info see: https://github.com/ngrx/platform/issues/3737
*/
export function createFeature<
AppState extends Record<string, any>,
FeatureName extends keyof AppState & string = keyof AppState & string,
Expand All @@ -110,13 +118,7 @@ export function createFeature<
*
* @usageNotes
*
* **With Application State**
*
* ```ts
* interface AppState {
* products: ProductsState;
* }
*
* interface ProductsState {
* products: Product[];
* selectedId: string | null;
Expand All @@ -127,8 +129,7 @@ export function createFeature<
* selectedId: null,
* };
*
* // AppState is passed as a generic argument
* const productsFeature = createFeature<AppState>({
* const productsFeature = createFeature({
* name: 'products',
* reducer: createReducer(
* initialState,
Expand All @@ -140,24 +141,13 @@ export function createFeature<
* });
*
* const {
* selectProductsState, // type: MemoizedSelector<AppState, ProductsState>
* selectProducts, // type: MemoizedSelector<AppState, Product[]>
* selectSelectedId, // type: MemoizedSelector<AppState, string | null>
* } = productsFeature;
* ```
*
* **Without Application State**
*
* ```ts
* const productsFeature = createFeature({
* name: 'products',
* reducer: createReducer(initialState),
* });
*
* const {
* name,
* reducer,
* // feature selector
* selectProductsState, // type: MemoizedSelector<Record<string, any>, ProductsState>
* // feature state properties selectors
* selectProducts, // type: MemoizedSelector<Record<string, any>, Product[]>
* selectSelectedId, // type: MemoizedSelector<Record<string, any, string | null>
* selectSelectedId, // type: MemoizedSelector<Record<string, any>, string | null>
* } = productsFeature;
* ```
*
Expand Down
28 changes: 28 additions & 0 deletions projects/ngrx.io/content/guide/migration/v15.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,34 @@ export class TestComponent {

## Deprecations

### @ngrx/store

#### Deprecated `createFeature` Signature with Root State (Introduced in v15.2)

The `createFeature` signature with root state is deprecated in favor of a signature without root state.

BEFORE:

```ts
interface AppState {
users: State;
}

export const usersFeature = createFeature<AppState>({
name: 'users',
reducer: createReducer(initialState, /* case reducers */),
});
```

AFTER:

```ts
export const usersFeature = createFeature({
name: 'users',
reducer: createReducer(initialState, /* case reducers */),
});
```

### @ngrx/router-store

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

0 comments on commit ccb3b93

Please sign in to comment.