Skip to content

Commit

Permalink
feat: Add actions and model
Browse files Browse the repository at this point in the history
  • Loading branch information
reidsvilleneuve committed Jun 15, 2018
1 parent 4a35428 commit b44116f
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 4 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.9
2 changes: 2 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
singleQuote: true
printWidth: 120
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
"@angular/platform-browser": "^6.0.0",
"@angular/platform-browser-dynamic": "^6.0.0",
"@angular/router": "^6.0.0",
"@ngrx/entity": "^6.0.1",
"@ngrx/store": "^6.0.1",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "^6.0.0",
"@angular-devkit/build-angular": "~0.6.0",
"typescript": "~2.7.2",
"@angular/cli": "~6.0.0",
"@angular/compiler-cli": "^6.0.0",
"@angular/language-service": "^6.0.0",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
Expand All @@ -43,6 +44,7 @@
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
"tslint": "~5.9.1",
"typescript": "~2.7.2"
}
}
}
137 changes: 137 additions & 0 deletions src/app/state/entity/entity.actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { Action } from '@ngrx/store';
import { Update } from '@ngrx/entity';
import { Entity } from './entity.model';

export enum EntityActionTypes {
EntityInsert = '[Entity] Insert',
EntityInsertSuccess = '[Entity] Insert Success',
EntityInsertFail = '[Entity] Insert Fail',

EntitySearch = '[Entity] Search',
EntitySearchSuccess = '[Entity] Search Success',
EntitySearchFail = '[Entity] Search Fail',

EntityLoadById = '[Entity] Load',
EntityLoadByIdSuccess = '[Entity] Load Success',
EntityLoadByIdFail = '[Entity] Load Fail',

EntityUpdate = '[Entity] Update',
EntityUpdateSuccess = '[Entity] Update Success',
EntityUpdateFail = '[Entity] Update Fail',

EntityDeleteById = '[Entity] Delete',
EntityDeleteSuccess = '[Entity] Delete Success',
EntityDeleteFail = '[Entity] Delete Fail',

EntitySetPaging = '[Entity] SetPaging',
EntitySelect = '[Entity] Select'
}

// Create

export class EntityInsert implements Action {
readonly type = EntityActionTypes.EntityInsert;
constructor(public payload: { data: Entity }) {}
}

export class EntityInsertSuccess implements Action {
readonly type = EntityActionTypes.EntityInsertSuccess;
constructor(public payload: { result: Entity }) {}
}

export class EntityInsertFail implements Action {
readonly type = EntityActionTypes.EntityInsertFail;
}

// Retrieve

export class EntitySearch implements Action {
readonly type = EntityActionTypes.EntitySearch;
}

export class EntitySearchSuccess implements Action {
readonly type = EntityActionTypes.EntitySearchSuccess;
constructor(public payload: { result: Entity[] }) {}
}

export class EntitySearchFail implements Action {
readonly type = EntityActionTypes.EntitySearchFail;
}

export class EntityLoadById implements Action {
readonly type = EntityActionTypes.EntityLoadById;
constructor(public payload: { id: Number }) {}
}

export class EntityLoadByIdSuccess implements Action {
readonly type = EntityActionTypes.EntityLoadByIdSuccess;
constructor(public payload: { result: Entity }) {}
}

export class EntityLoadByIdFail implements Action {
readonly type = EntityActionTypes.EntityLoadByIdFail;
}

// Update

export class EntityUpdate implements Action {
readonly type = EntityActionTypes.EntityUpdate;
constructor(public payload: { entity: Update<Entity> }) {}
}

export class EntityUpdateSuccess implements Action {
readonly type = EntityActionTypes.EntityUpdateSuccess;
constructor(public payload: { result: Entity }) {}
}

export class EntityUpdateFail implements Action {
readonly type = EntityActionTypes.EntityUpdateFail;
}

// Delete

export class EntityDeleteById implements Action {
readonly type = EntityActionTypes.EntityDeleteById;
constructor(public payload: { id: Number }) {}
}

export class EntityDeleteSuccess implements Action {
readonly type = EntityActionTypes.EntityDeleteSuccess;
constructor(public payload: { result: Entity }) {}
}

export class EntityDeleteFail implements Action {
readonly type = EntityActionTypes.EntityDeleteFail;
}

// Utility

export class EntitySetPaging implements Action {
// TODO: Paging interface
readonly type = EntityActionTypes.EntitySetPaging;
constructor(public payload: { limit: Number; page: Number }) {}
}

export class EntitySelect implements Action {
readonly type = EntityActionTypes.EntitySelect;
constructor(public payload: { id: Number }) {}
}

export type EntityActions =
| EntityInsert
| EntityInsertSuccess
| EntityInsertFail
| EntitySearch
| EntitySearchSuccess
| EntitySearchFail
| EntityLoadById
| EntityLoadByIdSuccess
| EntityLoadByIdFail
| EntityUpdate
| EntityUpdateSuccess
| EntityUpdateFail
| EntityDeleteById
| EntityDeleteSuccess
| EntityDeleteFail
| EntitySetPaging
| EntitySelect;
5 changes: 5 additions & 0 deletions src/app/state/entity/entity.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface Entity {
id: number;
name: string;
description: string;
}
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@
dependencies:
tslib "^1.9.0"

"@ngrx/entity@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/@ngrx/entity/-/entity-6.0.1.tgz#a07fe95d39671f3be10143fe999f5a9ee00f4edc"

"@ngrx/store@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/@ngrx/store/-/store-6.0.1.tgz#02c806ce20c698b997e81f5671e0edc07d32cf86"

"@ngtools/webpack@6.0.8":
version "6.0.8"
resolved "https://registry.yarnpkg.com/@ngtools/webpack/-/webpack-6.0.8.tgz#a05bce526aee9da62bb230a95fba83fee99d0bca"
Expand Down

0 comments on commit b44116f

Please sign in to comment.