Skip to content

Commit

Permalink
feat(entity): remove addAll (#2783)
Browse files Browse the repository at this point in the history
* feat(entity): remove deprecated addAll

BREAKING CHANGE:

To overwrite the entities, we previously used the `addAll` method but the method name was confusing.

BEFORE:

```ts
adapter.addAll(action.entities, state);
```

AFTER:

The new method name `setAll` describes the intention better.

```ts
adapter.setAll(action.entities, state);
```

* refactor(data): use the setAll adapter method
  • Loading branch information
timdeschryver authored Nov 15, 2020
1 parent 63a26d8 commit 93a4754
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2520,7 +2520,7 @@ describe('EntityCollectionReducer', () => {

case EntityOp.QUERY_LOAD_SUCCESS:
return {
...adapter.addAll(action.payload.data, collection),
...adapter.setAll(action.payload.data, collection),
loaded: true,
loading: false,
changeState: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class EntityCollectionReducerMethods<T> {
): EntityCollection<T> {
const data = this.extractData(action);
return {
...this.adapter.addAll(data, collection),
...this.adapter.setAll(data, collection),
loading: false,
loaded: true,
changeState: {},
Expand Down Expand Up @@ -943,7 +943,7 @@ export class EntityCollectionReducerMethods<T> {
): EntityCollection<T> {
const entities = this.guard.mustBeEntities(action);
return {
...this.adapter.addAll(entities, collection),
...this.adapter.setAll(entities, collection),
loading: false,
loaded: true,
changeState: {},
Expand Down
17 changes: 0 additions & 17 deletions modules/entity/spec/sorted_state_adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,6 @@ describe('Sorted State Adapter', () => {
});
});

it('should remove existing and add new ones on addAll (deprecated)', () => {
const withOneEntity = adapter.addOne(TheGreatGatsby, state);

const withAll = adapter.setAll(
[AClockworkOrange, AnimalFarm],
withOneEntity
);

expect(withAll).toEqual({
ids: [AClockworkOrange.id, AnimalFarm.id],
entities: {
[AClockworkOrange.id]: AClockworkOrange,
[AnimalFarm.id]: AnimalFarm,
},
});
});

it('should let you add remove an entity from the state', () => {
const withOneEntity = adapter.addOne(TheGreatGatsby, state);

Expand Down
17 changes: 0 additions & 17 deletions modules/entity/spec/unsorted_state_adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,6 @@ describe('Unsorted State Adapter', () => {
});
});

it('should remove existing and add new ones on addAll (deprecated)', () => {
const withOneEntity = adapter.addOne(TheGreatGatsby, state);

const withAll = adapter.addAll(
[AClockworkOrange, AnimalFarm],
withOneEntity
);

expect(withAll).toEqual({
ids: [AClockworkOrange.id, AnimalFarm.id],
entities: {
[AClockworkOrange.id]: AClockworkOrange,
[AnimalFarm.id]: AnimalFarm,
},
});
});

it('should let you add remove an entity from the state', () => {
const withOneEntity = adapter.addOne(TheGreatGatsby, state);

Expand Down
3 changes: 0 additions & 3 deletions modules/entity/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ export interface EntityStateAdapter<T> {
addOne<S extends EntityState<T>>(entity: T, state: S): S;
addMany<S extends EntityState<T>>(entities: T[], state: S): S;

/** @deprecated addAll has been renamed. Use setAll instead. */
addAll<S extends EntityState<T>>(entities: T[], state: S): S;

setAll<S extends EntityState<T>>(entities: T[], state: S): S;
setOne<S extends EntityState<T>>(entity: T, state: S): S;

Expand Down
1 change: 0 additions & 1 deletion modules/entity/src/sorted_state_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ export function createSortedStateAdapter<T>(selectId: any, sort: any): any {
addOne: createStateOperator(addOneMutably),
updateOne: createStateOperator(updateOneMutably),
upsertOne: createStateOperator(upsertOneMutably),
addAll: createStateOperator(setAllMutably),
setAll: createStateOperator(setAllMutably),
setOne: createStateOperator(setOneMutably),
addMany: createStateOperator(addManyMutably),
Expand Down
1 change: 0 additions & 1 deletion modules/entity/src/unsorted_state_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ export function createUnsortedStateAdapter<T>(selectId: IdSelector<T>): any {
removeAll,
addOne: createStateOperator(addOneMutably),
addMany: createStateOperator(addManyMutably),
addAll: createStateOperator(setAllMutably),
setAll: createStateOperator(setAllMutably),
setOne: createStateOperator(setOneMutably),
updateOne: createStateOperator(updateOneMutably),
Expand Down

0 comments on commit 93a4754

Please sign in to comment.