Skip to content

Commit

Permalink
docs(entity): add mapOne
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Jul 24, 2020
1 parent 8f72ca3 commit 2def007
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions projects/ngrx.io/content/guide/entity/adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,19 @@ The entity adapter also provides methods for operations against an entity. These
one to many records at a time. Each method returns the newly modified state if changes were made and the same
state if no changes were made.

- `addOne`: Add one entity to the collection
- `addMany`: Add multiple entities to the collection
- `setAll`: Replace current collection with provided collection
- `setOne`: Add or Replace one entity in the collection
- `removeOne`: Remove one entity from the collection
- `removeMany`: Remove multiple entities from the collection, by id or by predicate
- `removeAll`: Clear entity collection
- `addOne`: Add one entity to the collection.
- `addMany`: Add multiple entities to the collection.
- `setAll`: Replace current collection with provided collection.
- `setOne`: Add or Replace one entity in the collection.
- `removeOne`: Remove one entity from the collection.
- `removeMany`: Remove multiple entities from the collection, by id or by predicate.
- `removeAll`: Clear entity collection.
- `updateOne`: Update one entity in the collection. Supports partial updates.
- `updateMany`: Update multiple entities in the collection. Supports partial updates.
- `upsertOne`: Add or Update one entity in the collection. Supports partial updates.
- `upsertMany`: Add or Update multiple entities in the collection. Supports partial updates.
- `map`: Update multiple entities in the collection by defining a map function, similar to [Array.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
- `mapOne`: Update one entity in the collection by defining a map function.
- `map`: Update multiple entities in the collection by defining a map function, similar to [Array.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).

Usage:

Expand All @@ -107,7 +108,7 @@ export interface User {

<code-example header="user.actions.ts">
import { createAction, props } from '@ngrx/store';
import { Update, EntityMap, Predicate } from '@ngrx/entity';
import { Update, EntityMap, EntityMapOne, Predicate } from '@ngrx/entity';

import { User } from '../models/user.model';

Expand All @@ -119,6 +120,7 @@ export const addUsers = createAction('[User/API] Add Users', props<{ users: User
export const upsertUsers = createAction('[User/API] Upsert Users', props<{ users: User[] }>());
export const updateUser = createAction('[User/API] Update User', props<{ update: Update&lt;User&gt; }>());
export const updateUsers = createAction('[User/API] Update Users', props<{ updates: Update&lt;User&gt;[] }>());
export const mapUser = createAction('[User/API] Map User', props<{ entityMap: EntityMapOne&lt;User&gt; }>());
export const mapUsers = createAction('[User/API] Map Users', props<{ entityMap: EntityMap&lt;User&gt; }>());
export const deleteUser = createAction('[User/API] Delete User', props<{ id: string }>());
export const deleteUsers = createAction('[User/API] Delete Users', props<{ ids: string[] }>());
Expand Down Expand Up @@ -168,6 +170,9 @@ const userReducer = createReducer(
on(UserActions.updateUsers, (state, { updates }) => {
return adapter.updateMany(updates, state);
}),
on(UserActions.mapUser, (state, { entityMap }) => {
return adapter.map(entityMap, state);
}),
on(UserActions.mapUsers, (state, { entityMap }) => {
return adapter.map(entityMap, state);
}),
Expand Down

0 comments on commit 2def007

Please sign in to comment.