Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: minor EntityActionFactory change - v6.0.2-beta.8 #164

Merged
merged 1 commit into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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