You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4-1Lines changed: 4 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,8 @@
1
+
*_2.2.0_
2
+
* Support for adding and removing child data. Adding `AddChildData` and `RemoveChildData` actions and `addChildData` and `removeChildData` action creators.
3
+
1
4
*_2.1.0_
2
-
entitiesProjector takes an optional array of id strings ([@juanpmarin](https://github.com/juanpmarin)) Closes #18
5
+
*entitiesProjector takes an optional array of id strings ([@juanpmarin](https://github.com/juanpmarin)) Closes #18
3
6
4
7
*_2.0.0_
5
8
* Serialization support for actions. _Details:_ The normalization of entities is now perfomed in the action constructor. Previously it was handled by the reducer. As ([@PachowStudios](https://github.com/PachowStudios)) pointed out in Issue #16, ngrx-normalizr actions were not serializable. This could raise issues with other redux/ngrx libraries. The normalizr `schema.Entity` is not part of the action payload anymore, hence the interfaces for describing the payload have changed and the action constructor does no longer take the payload itself as an argument. As long as you did not type any action parameters in your code or dispatched actions directly with a simle pojo by using the exported action type names, you should have no problem updating, since the arity/keys of the constructor API did not change - see Breaking Changes. Closes #16
Copy file name to clipboardExpand all lines: README.md
+51-3Lines changed: 51 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -5,11 +5,12 @@
5
5
6
6
> Managing [normalized state](https://redux.js.org/docs/recipes/reducers/NormalizingStateShape.html) in [ngrx](https://github.com/ngrx/platform) applications, transparently.
7
7
8
-
9
8
This package provides a set of actions, reducers and selectors for handling normalization and denormalization of state data **transparently**.
10
9
*ngrx-normalizr* uses [normalizr](https://github.com/paularmstrong/normalizr) for [normalizing](https://github.com/paularmstrong/normalizr/blob/master/docs/api.md#normalizedata-schema) and [denormalizing](https://github.com/paularmstrong/normalizr/blob/master/docs/api.md#denormalizeinput-schema-entities) data. All normalization and denormalization
11
10
is defined by the use of [normalizr schemas](https://github.com/paularmstrong/normalizr/blob/master/docs/api.md#schema), since that's the way normalizr works. This enables selectors to use a transparent and powerful projection of state data.
12
11
12
+
> Releases will be published from the [`master`](https://github.com/michaelkrone/ngrx-normalizr/tree/master) branch. [Go there](https://github.com/michaelkrone/ngrx-normalizr/tree/master) for documentation that aligns with the npm repo version.
13
+
13
14
## Installation
14
15
To install this package:
15
16
```sh
@@ -81,7 +82,7 @@ Actions are used to set data in - and remove data from - the normalized store.
81
82
82
83
### Adding data
83
84
To add data and automatically normalize it, *ngrx-normalizr* provides a `AddData` action. This action takes an object with `data` and `schema` as an argument. Entities are identified by their id attribute set in the passed schema.
84
-
Existing entities will be overwritten by updated data, new entities will be added to the store.
85
+
Existing entities will be overwritten by updated data, new entities will be added to the store. For adding related childs, an `AddChildData` action is provided.
85
86
86
87
###### Using `AddData` in an effect
87
88
```javascript
@@ -98,6 +99,29 @@ loadEffect$ = this.actions$
98
99
.catch(err=>Observable.of(newLoadFail(err)));
99
100
```
100
101
102
+
#### Adding child data
103
+
Adding a related child data to a parent entity can be done with the `AddChildData` action. Note that for this to work, the relation has to be defined in the schema. The action takes a couple of arguments which need to be given in an object:
104
+
105
+
*`data`: Array of child entities to add
106
+
*`childSchema`The `schema.Entity` of the child entity
107
+
*`parentSchema`: The `schema.Entity` of the parent entity
108
+
*`parentId`: The id of the entity to add child references to
The `SetData` action will overwrite all entities for a given schema with the normalized entities of the `data` property of the action constructor argument. This action can
103
127
be used for resetting entity state data instead of adding and updating existing entities.
Removing a child entity which is 1:1 related to a parent entity can be done with the `RemoveChildData` action. Note that for this to work, the relation has to be defined in the schema. The action takes a couple of arguments which need to be given in an object:
149
+
150
+
*`id`: Id of the child entity that should be removed
151
+
*`childSchema`The `schema.Entity` of the child entity
152
+
*`parentSchema`: The `schema.Entity` of the parent entity
153
+
*`parentId`: The id of the entity to remove child references from
`createSchemaSelectors` will return schema bound selectors (instance of `SchemaSelectors`):
174
222
*`getEntities` - ` MemoizedSelector<{}, T[]>` Returns all denormalized entities for the schema
175
223
*`getNormalizedEntities` - `MemoizedSelector<any, EntityMap>` Returns all normalized (raw) state entities of every schema (the whole entities state)
176
-
*`entitiesProjector` - `(entities: {}, ids?: Array<string>) => T[]` Projector function for denormalizing a the set of normalized entities to an denormalized entity array
224
+
*`entitiesProjector` - `(entities: {}, ids?: Array<string>) => T[]` Projector function for denormalizing a the set of normalized entities to an denormalized entity array. If no `ids` are given, all entities will be denormalized.
177
225
*`entityProjector` - `(entities: {}, id: string) => T` Projector function for denormalizing a single normalized entity with the given id
178
226
179
227
You might create several selectors with several schemas, i.e. a *listView* schema, which only denormalizes the data used in the list
0 commit comments