Skip to content

Commit 2afb792

Browse files
phillipzadabrandonroberts
authored andcommitted
feat(Entity): Add default selectId function for EntityAdapter (#405)
1 parent 193e8b3 commit 2afb792

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

modules/entity/src/create_adapter.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ import { createSelectorsFactory } from './state_selectors';
1010
import { createSortedStateAdapter } from './sorted_state_adapter';
1111
import { createUnsortedStateAdapter } from './unsorted_state_adapter';
1212

13-
export function createEntityAdapter<T>(options: {
14-
selectId: IdSelector<T>;
15-
sortComparer?: false | Comparer<T>;
16-
}): EntityAdapter<T> {
13+
export function createEntityAdapter<T>(
14+
options: {
15+
selectId?: IdSelector<T>;
16+
sortComparer?: false | Comparer<T>;
17+
} = {}
18+
): EntityAdapter<T> {
1719
const { selectId, sortComparer }: EntityDefinition<T> = {
1820
sortComparer: false,
21+
selectId: (instance: any) => instance.id,
1922
...options,
2023
};
2124

modules/store/src/store_module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,16 @@ export class StoreModule {
149149
): ModuleWithProviders;
150150
static forFeature<T, V extends Action = Action>(
151151
featureName: string,
152-
reducer: ActionReducer<T, V>| InjectionToken<ActionReducer<T, V>>,
152+
reducer: ActionReducer<T, V> | InjectionToken<ActionReducer<T, V>>,
153153
config?: StoreConfig<T, V>
154154
): ModuleWithProviders;
155155
static forFeature(
156156
featureName: string,
157-
reducers: ActionReducerMap<any, any> | InjectionToken<ActionReducerMap<any, any>> | ActionReducer<any, any> | InjectionToken<ActionReducer<any, any>>,
157+
reducers:
158+
| ActionReducerMap<any, any>
159+
| InjectionToken<ActionReducerMap<any, any>>
160+
| ActionReducer<any, any>
161+
| InjectionToken<ActionReducer<any, any>>,
158162
config: StoreConfig<any, any> = {}
159163
): ModuleWithProviders {
160164
return {

0 commit comments

Comments
 (0)