From 2def00788eca70c9397f61821543b3a3f6dfe8ae Mon Sep 17 00:00:00 2001 From: timdeschryver <28659384+timdeschryver@users.noreply.github.com> Date: Fri, 24 Jul 2020 09:08:54 +0200 Subject: [PATCH] docs(entity): add mapOne --- .../ngrx.io/content/guide/entity/adapter.md | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/projects/ngrx.io/content/guide/entity/adapter.md b/projects/ngrx.io/content/guide/entity/adapter.md index 8812a6bd7e..de8296ae8c 100644 --- a/projects/ngrx.io/content/guide/entity/adapter.md +++ b/projects/ngrx.io/content/guide/entity/adapter.md @@ -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: @@ -107,7 +108,7 @@ export interface User { 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'; @@ -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<User> }>()); export const updateUsers = createAction('[User/API] Update Users', props<{ updates: Update<User>[] }>()); +export const mapUser = createAction('[User/API] Map User', props<{ entityMap: EntityMapOne<User> }>()); export const mapUsers = createAction('[User/API] Map Users', props<{ entityMap: EntityMap<User> }>()); export const deleteUser = createAction('[User/API] Delete User', props<{ id: string }>()); export const deleteUsers = createAction('[User/API] Delete Users', props<{ ids: string[] }>()); @@ -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); }),