Skip to content

Commit 274554b

Browse files
karptoniteMikeRyanDev
authored andcommitted
feat(Entity): Rename 'sort' to 'sortComparer'
Closes #370
1 parent 9e1375d commit 274554b

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

docs/entity/adapter.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ returned adapter provides many [methods](#adapter-methods) for performing operat
77
against the collection type. The method takes an object for configuration with 2 properties.
88

99
- `selectId`: A `method` for selecting the primary id for the collection
10-
- `sort`: A compare function used to [sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) the collection. The comparer function is only needed if the collection needs to be sorted before being displayed. Set to `false` to use leave the collection unsorted, which is more performant during CRUD operations.
10+
- `sortComparer`: A compare function used to [sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) the collection. The comparer function is only needed if the collection needs to be sorted before being displayed. Set to `false` to use leave the collection unsorted, which is more performant during CRUD operations.
1111

1212
Usage:
1313

@@ -31,7 +31,7 @@ export function sortByName(a: User, b: User): number {
3131

3232
export const adapter: EntityAdapter<User> = createEntityAdapter<User>({
3333
selectId: (user: User) => user.id,
34-
sort: sortByName,
34+
sortComparer: sortByName,
3535
});
3636
```
3737

example-app/app/books/reducers/books.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ export interface State extends EntityState<Book> {
2020
* functions for single or multiple operations
2121
* against the dictionary of records. The configuration
2222
* object takes a record id selector function and
23-
* a sort option whether to sort the records when performing
24-
* operations
23+
* a sortComparer option which is set to a compare
24+
* function if the records are to be sorted.
2525
*/
2626
export const adapter: EntityAdapter<Book> = createEntityAdapter<Book>({
2727
selectId: (book: Book) => book.id,
28-
sort: false,
28+
sortComparer: false,
2929
});
3030

3131
/** getInitialState returns the default initial state

modules/entity/spec/sorted_state_adapter.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('Sorted State Adapter', () => {
1414
beforeEach(() => {
1515
adapter = createEntityAdapter({
1616
selectId: (book: BookModel) => book.id,
17-
sort: (a, b) => a.title.localeCompare(b.title),
17+
sortComparer: (a, b) => a.title.localeCompare(b.title),
1818
});
1919

2020
state = { ids: [], entities: {} };

modules/entity/src/create_adapter.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ import { createUnsortedStateAdapter } from './unsorted_state_adapter';
1212

1313
export function createEntityAdapter<T>(options: {
1414
selectId: IdSelector<T>;
15-
sort?: false | Comparer<T>;
15+
sortComparer?: false | Comparer<T>;
1616
}): EntityAdapter<T> {
17-
const { selectId, sort }: EntityDefinition<T> = { sort: false, ...options };
17+
const { selectId, sortComparer }: EntityDefinition<T> = {
18+
sortComparer: false,
19+
...options,
20+
};
1821

1922
const stateFactory = createInitialStateFactory<T>();
2023
const selectorsFactory = createSelectorsFactory<T>();
21-
const stateAdapter = sort
22-
? createSortedStateAdapter(selectId, sort)
24+
const stateAdapter = sortComparer
25+
? createSortedStateAdapter(selectId, sortComparer)
2326
: createUnsortedStateAdapter(selectId);
2427

2528
return {

modules/entity/src/models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface EntityState<T> {
2222

2323
export interface EntityDefinition<T> {
2424
selectId: IdSelector<T>;
25-
sort: false | Comparer<T>;
25+
sortComparer: false | Comparer<T>;
2626
}
2727

2828
export interface EntityStateAdapter<T> {

0 commit comments

Comments
 (0)