Skip to content

Commit

Permalink
2.1.0 (#21)
Browse files Browse the repository at this point in the history
* feat: WIP serializable actions, bump normalizr version, updated docs

* refactor: assert that removeChildren is null (was an empty object) for invalid key value pairs

* test: ignore not existing else path for 100% coverage

* docs: add 2.0.0 changelog

* feat: reuse  payload interface types for action config

* docs(changelog): add breaking changes description

* docs: update action constructor description

* Use entitiesProjector to select objects by a list of ids (#19)

* chore: add codelyzer and remove platform-server from package.json

* feat: use entitiesProjector to select objects by a list of ids

* chore: add normalizr as direct dependency

* docs: update for 2.0.0

* style: apply prettier

* chore: bump 2.1.0, closes #18

* docs: remove double changelog for 2.0.0
  • Loading branch information
michaelkrone authored Nov 7, 2017
1 parent 8883417 commit 7ab4fc6
Show file tree
Hide file tree
Showing 23 changed files with 730 additions and 309 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
* _2.1.0_
entitiesProjector takes an optional array of id strings ([@juanpmarin](https://github.com/juanpmarin)) Closes #18

* _2.0.0_
* 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)
* 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

* **Breaking Changes**
* Action constructor parameters changed from `NormalizeDataPayload` to `NormalizeActionConfig` and from `NormalizeRemovePayload` to `NormalizeRemoveActionConfig`
Expand All @@ -26,4 +29,4 @@
* first production version

* _0.0.1_
* first development version
* first development version
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ npm i ngrx-normalizr
```

### Peer dependencies
*ngrx-normalizr* defines [normalizr](https://github.com/paularmstrong/normalizr) and [@ngrx-store](https://github.com/ngrx/platform/blob/master/docs/store/README.md) as its peer dependencies, so you need to install them if not present already:
*ngrx-normalizr* [@ngrx-store](https://github.com/ngrx/platform/blob/master/docs/store/README.md) as its peer dependencies, so you need to install them if not present already:

> *ngrx-normalizr* itself does not rely on any [Angular](https://angular.io) feature.
```sh
yarn add @ngrx/store normalizr
npm i @ngrx/store normalizr
yarn add @ngrx/store
npm i @ngrx/store
```

## Usage
Expand Down Expand Up @@ -173,7 +173,7 @@ const schemaSelectors = createSchemaSelectors<User>(userSchema);
`createSchemaSelectors` will return schema bound selectors (instance of `SchemaSelectors`):
* `getEntities` - ` MemoizedSelector<{}, T[]>` Returns all denormalized entities for the schema
* `getNormalizedEntities` - `MemoizedSelector<any, EntityMap>` Returns all normalized (raw) state entities of every schema (the whole entities state)
* `entitiesProjector` - `(entities: {}) => T[]` Projector function for denormalizing a the set of normalized entities to an denormalized entity array
* `entitiesProjector` - `(entities: {}, ids?: Array<string>) => T[]` Projector function for denormalizing a the set of normalized entities to an denormalized entity array
* `entityProjector` - `(entities: {}, id: string) => T` Projector function for denormalizing a single normalized entity with the given id

You might create several selectors with several schemas, i.e. a *listView* schema, which only denormalizes the data used in the list
Expand All @@ -196,7 +196,7 @@ const getUsers = createSelector(
);

```
The `entitiesProjector` simply takes an object of normalized entity data and applies the denormalization with the bound schema.
The `entitiesProjector` simply takes an object of normalized entity data and applies the denormalization with the bound schema. Optionally an array of id strings can be passed as a second parameter to perform denormalization for the given id's only.

#### Composing schema selectors
To query and denormalize specific data you can use the *@ngrx/store* [`createSelectors`](https://github.com/ngrx/platform/blob/master/docs/store/selectors.md#createselector) function and compose them with the schema bound
Expand Down
12 changes: 12 additions & 0 deletions docs/classes/_actions_normalize_.adddata.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ <h3>constructor</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<<<<<<< HEAD
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L178">actions/normalize.ts:178</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L178">actions/normalize.ts:178</a></li>
>>>>>>> origin/master
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -163,7 +167,11 @@ <h3>payload</h3>
<div class="tsd-signature tsd-kind-icon">payload<span class="tsd-signature-symbol">:</span> <a href="../interfaces/_actions_normalize_.normalizeactionpayload.html" class="tsd-signature-type">NormalizeActionPayload</a></div>
<aside class="tsd-sources">
<ul>
<<<<<<< HEAD
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L178">actions/normalize.ts:178</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L178">actions/normalize.ts:178</a></li>
>>>>>>> origin/master
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -179,7 +187,11 @@ <h3>type</h3>
<div class="tsd-signature tsd-kind-icon">type<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> =&nbsp;NormalizeActionTypes.ADD_DATA</span></div>
<aside class="tsd-sources">
<ul>
<<<<<<< HEAD
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L172">actions/normalize.ts:172</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L172">actions/normalize.ts:172</a></li>
>>>>>>> origin/master
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
12 changes: 12 additions & 0 deletions docs/classes/_actions_normalize_.normalizeactiontypes.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ <h3><span class="tsd-flag ts-flagStatic">Static</span> ADD_<wbr>DATA</h3>
<div class="tsd-signature tsd-kind-icon">ADD_<wbr>DATA<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> =&nbsp;&#x60;${ACTION_NAMESPACE} Add Data&#x60;</span></div>
<aside class="tsd-sources">
<ul>
<<<<<<< HEAD
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L131">actions/normalize.ts:131</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L131">actions/normalize.ts:131</a></li>
>>>>>>> origin/master
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -122,7 +126,11 @@ <h3><span class="tsd-flag ts-flagStatic">Static</span> REMOVE_<wbr>DATA</h3>
<div class="tsd-signature tsd-kind-icon">REMOVE_<wbr>DATA<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> =&nbsp;&#x60;${ACTION_NAMESPACE} Remove Data&#x60;</span></div>
<aside class="tsd-sources">
<ul>
<<<<<<< HEAD
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L136">actions/normalize.ts:136</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L136">actions/normalize.ts:136</a></li>
>>>>>>> origin/master
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -137,7 +145,11 @@ <h3><span class="tsd-flag ts-flagStatic">Static</span> SET_<wbr>DATA</h3>
<div class="tsd-signature tsd-kind-icon">SET_<wbr>DATA<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> =&nbsp;&#x60;${ACTION_NAMESPACE} Set Data&#x60;</span></div>
<aside class="tsd-sources">
<ul>
<<<<<<< HEAD
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L126">actions/normalize.ts:126</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L126">actions/normalize.ts:126</a></li>
>>>>>>> origin/master
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
12 changes: 12 additions & 0 deletions docs/classes/_actions_normalize_.removedata.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ <h3>constructor</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<<<<<<< HEAD
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L203">actions/normalize.ts:203</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L203">actions/normalize.ts:203</a></li>
>>>>>>> origin/master
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -150,7 +154,11 @@ <h3>payload</h3>
<div class="tsd-signature tsd-kind-icon">payload<span class="tsd-signature-symbol">:</span> <a href="../interfaces/_actions_normalize_.normalizeremoveactionpayload.html" class="tsd-signature-type">NormalizeRemoveActionPayload</a></div>
<aside class="tsd-sources">
<ul>
<<<<<<< HEAD
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L203">actions/normalize.ts:203</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L203">actions/normalize.ts:203</a></li>
>>>>>>> origin/master
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -166,7 +174,11 @@ <h3>type</h3>
<div class="tsd-signature tsd-kind-icon">type<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> =&nbsp;NormalizeActionTypes.REMOVE_DATA</span></div>
<aside class="tsd-sources">
<ul>
<<<<<<< HEAD
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L197">actions/normalize.ts:197</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L197">actions/normalize.ts:197</a></li>
>>>>>>> origin/master
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
12 changes: 12 additions & 0 deletions docs/classes/_actions_normalize_.setdata.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ <h3>constructor</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<<<<<<< HEAD
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L153">actions/normalize.ts:153</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L153">actions/normalize.ts:153</a></li>
>>>>>>> origin/master
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -163,7 +167,11 @@ <h3>payload</h3>
<div class="tsd-signature tsd-kind-icon">payload<span class="tsd-signature-symbol">:</span> <a href="../interfaces/_actions_normalize_.normalizeactionpayload.html" class="tsd-signature-type">NormalizeActionPayload</a></div>
<aside class="tsd-sources">
<ul>
<<<<<<< HEAD
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L153">actions/normalize.ts:153</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L153">actions/normalize.ts:153</a></li>
>>>>>>> origin/master
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -179,7 +187,11 @@ <h3>type</h3>
<div class="tsd-signature tsd-kind-icon">type<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> =&nbsp;NormalizeActionTypes.SET_DATA</span></div>
<aside class="tsd-sources">
<ul>
<<<<<<< HEAD
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L147">actions/normalize.ts:147</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L147">actions/normalize.ts:147</a></li>
>>>>>>> origin/master
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
10 changes: 5 additions & 5 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ <h2 id="installation">Installation</h2>
npm i ngrx-normalizr
</code></pre>
<h3 id="peer-dependencies">Peer dependencies</h3>
<p><em>ngrx-normalizr</em> defines <a href="https://github.com/paularmstrong/normalizr">normalizr</a> and <a href="https://github.com/ngrx/platform/blob/master/docs/store/README.md">@ngrx-store</a> as its peer dependencies, so you need to install them if not present already:</p>
<p><em>ngrx-normalizr</em> <a href="https://github.com/ngrx/platform/blob/master/docs/store/README.md">@ngrx-store</a> as its peer dependencies, so you need to install them if not present already:</p>
<blockquote>
<p><em>ngrx-normalizr</em> itself does not rely on any <a href="https://angular.io">Angular</a> feature.</p>
</blockquote>
<pre><code class="lang-sh">yarn add @ngrx/store normalizr
npm i @ngrx/store normalizr
<pre><code class="lang-sh">yarn add @ngrx/store
npm i @ngrx/store
</code></pre>
<h2 id="usage">Usage</h2>
<p>Also refer to the <a href="https://michaelkrone.github.io/ngrx-normalizr/">Typedoc documentation</a>.
Expand Down Expand Up @@ -209,7 +209,7 @@ <h3 id="creating-schema-selectors">Creating Schema selectors</h3>
<ul>
<li><code>getEntities</code> - <code>MemoizedSelector&lt;{}, T[]&gt;</code> Returns all denormalized entities for the schema</li>
<li><code>getNormalizedEntities</code> - <code>MemoizedSelector&lt;any, EntityMap&gt;</code> Returns all normalized (raw) state entities of every schema (the whole entities state)</li>
<li><code>entitiesProjector</code> - <code>(entities: {}) =&gt; T[]</code> Projector function for denormalizing a the set of normalized entities to an denormalized entity array</li>
<li><code>entitiesProjector</code> - <code>(entities: {}, ids?: Array&lt;string&gt;) =&gt; T[]</code> Projector function for denormalizing a the set of normalized entities to an denormalized entity array</li>
<li><code>entityProjector</code> - <code>(entities: {}, id: string) =&gt; T</code> Projector function for denormalizing a single normalized entity with the given id</li>
</ul>
<p>You might create several selectors with several schemas, i.e. a <em>listView</em> schema, which only denormalizes the data used in the list
Expand All @@ -227,7 +227,7 @@ <h3 id="using-schema-selectors">Using schema selectors</h3>
schemaSelectors.entitiesProjector
);
</code></pre>
<p>The <code>entitiesProjector</code> simply takes an object of normalized entity data and applies the denormalization with the bound schema.</p>
<p>The <code>entitiesProjector</code> simply takes an object of normalized entity data and applies the denormalization with the bound schema. Optionally an array of id strings can be passed as a second parameter to perform denormalization for the given id&#39;s only.</p>
<h4 id="composing-schema-selectors">Composing schema selectors</h4>
<p>To query and denormalize specific data you can use the <em>@ngrx/store</em> <a href="https://github.com/ngrx/platform/blob/master/docs/store/selectors.md#createselector"><code>createSelectors</code></a> function and compose them with the schema bound
selectors:</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ <h3>data</h3>
<div class="tsd-signature tsd-kind-icon">data<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">T</span><span class="tsd-signature-symbol">[]</span></div>
<aside class="tsd-sources">
<ul>
<<<<<<< HEAD:docs/interfaces/_actions_normalize_.normalizeactionconfig.html
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L78">actions/normalize.ts:78</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L78">actions/normalize.ts:78</a></li>
>>>>>>> origin/master:docs/interfaces/_actions_normalize_.normalizeactionconfig.html
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -136,7 +140,11 @@ <h3>schema</h3>
<aside class="tsd-sources">
<p>Inherited from <a href="_actions_normalize_.normalizeactionschemaconfig.html">NormalizeActionSchemaConfig</a>.<a href="_actions_normalize_.normalizeactionschemaconfig.html#schema">schema</a></p>
<ul>
<<<<<<< HEAD:docs/interfaces/_actions_normalize_.normalizeactionconfig.html
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L67">actions/normalize.ts:67</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L67">actions/normalize.ts:67</a></li>
>>>>>>> origin/master:docs/interfaces/_actions_normalize_.normalizeactionconfig.html
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
12 changes: 12 additions & 0 deletions docs/interfaces/_actions_normalize_.normalizeactioncreators.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ <h3>add<wbr>Data</h3>
<div class="tsd-signature tsd-kind-icon">add<wbr>Data<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<<<<<<< HEAD
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L111">actions/normalize.ts:111</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L111">actions/normalize.ts:111</a></li>
>>>>>>> origin/master
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -151,7 +155,11 @@ <h3>remove<wbr>Data</h3>
<div class="tsd-signature tsd-kind-icon">remove<wbr>Data<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<<<<<<< HEAD
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L116">actions/normalize.ts:116</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L116">actions/normalize.ts:116</a></li>
>>>>>>> origin/master
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -190,7 +198,11 @@ <h3>set<wbr>Data</h3>
<div class="tsd-signature tsd-kind-icon">set<wbr>Data<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
<aside class="tsd-sources">
<ul>
<<<<<<< HEAD
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/6fa4021/src/actions/normalize.ts#L106">actions/normalize.ts:106</a></li>
=======
<li>Defined in <a href="https://github.com/michaelkrone/ngrx-normalizr/blob/ab53558/src/actions/normalize.ts#L106">actions/normalize.ts:106</a></li>
>>>>>>> origin/master
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
Loading

0 comments on commit 7ab4fc6

Please sign in to comment.