Skip to content

Commit

Permalink
refactor: minor EntityActionFactory change - v6.0.2-beta.8 (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
wardbell committed Jun 27, 2018
1 parent 7f68498 commit c83e3a8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
20 changes: 20 additions & 0 deletions lib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

<a id="6.0.2-beta.7"></a>

# 6.0.2-beta.8 (2018-06-27)

Minor internal refactoring

* `EntityActionFactory` - Polymorphic `create` method delegates to mono-morphic `createCore` method
which makes the factory easier to sub-class.

<a id="6.0.2-beta.7"></a>

# 6.0.2-beta.7 (2018-06-26)

This **major release** is primarily about the new, _change tracking_ feature,
Expand Down Expand Up @@ -523,6 +532,17 @@ Developers can petition to re-expose them if they can offer good reasons.

This change, described earlier, affects those developers who worked directly with `EntityAction` instances.

#### `EntityActionFactory.create` signature changed.

The relocation of `EntityAction` properties to the payload forced changes to the `EntityActionFactory`,
most significantly its `create` signatures.

The `create` method no longer accepts a source action.
Use `createFromAction` instead.

This is a breaking change for anyone sub-classing `EntityActionFactory` or calling it directly with
one of its lesser used `create` signatures.

#### `EntityAction.op` property renamed `entityOp`

While moving entity action properties to `EntityAction.payload`, the `op` property was renamed `entityOp` for three reasons.
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.0.2-beta.7",
"version": "6.0.2-beta.8",
"repository": "https://github.com/johnpapa/angular-ngrx-data.git",
"license": "MIT",
"peerDependencies": {
Expand Down
16 changes: 12 additions & 4 deletions lib/src/actions/entity-action-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class EntityActionFactory {
*/
create<P = any>(payload: EntityActionPayload<P>): EntityAction<P>;

// polymorphic create for the two signatures
create<P = any>(
nameOrPayload: EntityActionPayload<P> | string,
entityOp?: EntityOp,
Expand All @@ -30,16 +31,23 @@ export class EntityActionFactory {
): EntityAction<P> {
const payload: EntityActionPayload<P> =
typeof nameOrPayload === 'string' ? { ...(options || {}), entityName: nameOrPayload, entityOp, data } : nameOrPayload;
return this.createCore(payload);
}

const { entityName, entityOp: op, tag } = payload;

/**
* Create an EntityAction to perform an operation (op) for a particular entity type
* (entityName) with optional data and other optional flags
* @param payload Defines the EntityAction and its options
*/
protected createCore<P = any>(payload: EntityActionPayload<P>) {
const { entityName, entityOp, tag } = payload;
if (!entityName) {
throw new Error('Missing entity name for new action');
}
if (op == null) {
if (entityOp == null) {
throw new Error('Missing EntityOp for new action');
}
const type = this.formatActionType(op, tag || entityName);
const type = this.formatActionType(entityOp, tag || entityName);
return { type, payload };
}

Expand Down

0 comments on commit c83e3a8

Please sign in to comment.