Skip to content

Commit

Permalink
6.1.0-beta.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wardbell committed Oct 10, 2018
1 parent b45501e commit 122d033
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ You can make your own calls to the server and update the cached entity collectio

You can see the _ngrx machinery_ at work with the [_redux developer tools_](#redux-dev-tools). You can listen to the flow of actions directly. You can _intercept and override anything_ ... but you only have to intervene where you want to add custom logic.

### Show me
### Learn about it

For a hands-on experience, try the [QuickStart](https://github.com/johnpapa/ngrx-data-lab/blob/master/README.md).
In this section, we summarize the key points.
For a hands-on experience, try the [QuickStart](https://github.com/johnpapa/ngrx-data-lab/blob/master/README.md)
in the tutorial git repo, **[ngrx-data-lab](https://github.com/johnpapa/ngrx-data-lab/)**,
which guides you on the few, simple steps necessary to migrate from a typical service-based Angular app, to an app that manages state with _ngrx-data_.

_This_ **ngrx-data repository** has the main documentation and its own sample app.

The sample app in the `src/client/app/` folder presents an editor for viewing and changing _Heroes_ and _Villains_.

The _ngrx-data_ repository includes a demo app for editing _Heroes_ and _Villains_ in the `src/client/app/` folder.
The following _reduced_ extract from that demo illustrates the essential mechanics of configuring and using _ngrx-data_.

You begin with a description of the entity model in a few lines of metadata.
Expand Down
11 changes: 7 additions & 4 deletions docs/entity-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,17 @@ The `HttpUrlGenerator` can't pluralize the entity type name on its own. It deleg

The `Pluralizer` class has a _pluralize()_ method that takes the singular string and returns the plural string.

The default `Pluralizer` handles many of the common English pluralization rules such as appending an `'s'`. That's fine for the `Villain` type (which becomes "villains").
That's the wrong technique for pluralizing the `Hero` type (which becomes "heros").
The default `Pluralizer` handles many of the common English pluralization rules such as appending an `'s'`.
That's fine for the `Villain` type (which becomes "Villains") and even for `Company` (which becomes "Companies").

It's far from perfect. For example, it incorrectly turns `Hero` into "Heros" instead of "Heroes".

Fortunately, the default `Pluralizer` also injects a map of singular to plural strings (with the `PLURAL_NAMES_TOKEN`).

Its `pluralize()` method looks for the singular entity name in that map and uses the corresponding plural value if found. Otherwise, it returns the entity name plus `'s'`.
Its `pluralize()` method looks for the singular entity name in that map and uses the corresponding plural value if found.
Otherwise, it returns the default pluralization of the entity name.

If this scheme works for you, create a map of _singular-to-plural_ entity names for the exceptional cases, as the demo app does:
If this scheme works for you, create a map of _singular-to-plural_ entity names for the exceptional cases:

```javascript
export const pluralNames = {
Expand Down
6 changes: 6 additions & 0 deletions lib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ as this will keep you from installing `6.1.x`.
<hr>
<a id="6.1.0-alpha.4"></a>

# 6.1.0-beta.0 (2018-10-09)

Advance to Beta. No changes. The new APIs are working well in a production application and there are no reported issues with them.

<a id="6.1.0-alpha.4"></a>

# 6.1.0-alpha.4 (2018-10-01)

Fix: missing `@Optional()` on `EntityCacheDataService` constructor parameter
Expand Down
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngrx-data",
"version": "6.1.0-alpha.4",
"version": "6.1.0-beta.0",
"repository": "https://github.com/johnpapa/angular-ngrx-data.git",
"license": "MIT",
"peerDependencies": {
Expand Down
28 changes: 15 additions & 13 deletions src/app/store/entity/entity-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
defaultSelectId,
EntityMetadataMap,
PropsFilterFnFactory
} from 'ngrx-data';
import { defaultSelectId, EntityMetadataMap, PropsFilterFnFactory } from 'ngrx-data';

export const entityMetadata: EntityMetadataMap = {
Hero: {
Expand All @@ -24,20 +20,26 @@ export const entityMetadata: EntityMetadataMap = {
}
};

// Special pluralization mapping for words the defaultPluralizer can't pluralize
// The plural of "Hero" is not "Heros"; it's "Heroes"
// Important: Case matters. Match the case of the entity name.
export const pluralNames = {
// Not needed for data access when set Hero's HttpResourceUrls; see `entity-store.module.ts`.
// Case matters. Match the case of the entity name.
Hero: 'Heroes'
};

// Can't just put the function in the entityMetadata literal
// AOT obliges us to encapsulate the logic in wrapper functions
// ----------------
// In _this particular example_, this pluralNames mapping is not actually needed
// because the example set the Hero's `HttpResourceUrls` directly rather than relying on pluralization;
// see `entity-store.module.ts`.
// ----------------

// FILTERS AND SORTERS

// Can't embed these functions directly in the entityMetadata literal because
// AOT requires us to encapsulate the logic in wrapper functions

/** Filter for entities whose name matches the case-insensitive pattern */
export function nameFilter<T extends { name: string }>(
entities: T[],
pattern: string
) {
export function nameFilter<T extends { name: string }>(entities: T[], pattern: string) {
return PropsFilterFnFactory(['name'])(entities, pattern);
}

Expand Down

0 comments on commit 122d033

Please sign in to comment.