├── .angular-cli.json
├── .editorconfig
├── .gitignore
├── .vscode
└── settings.json
├── README.md
├── e2e
├── app.e2e-spec.ts
├── app.po.ts
└── tsconfig.e2e.json
├── karma.conf.js
├── package-lock.json
├── package.json
├── protractor.conf.js
├── src
├── app
│ ├── actions
│ │ └── company.actions.ts
│ ├── app-routing.module.ts
│ ├── app.component.html
│ ├── app.component.scss
│ ├── app.component.spec.ts
│ ├── app.component.ts
│ ├── app.module.ts
│ ├── company
│ │ ├── company-edit
│ │ │ ├── company-edit.component.html
│ │ │ ├── company-edit.component.scss
│ │ │ └── company-edit.component.ts
│ │ ├── company-list
│ │ │ ├── company-list.component.html
│ │ │ ├── company-list.component.scss
│ │ │ ├── company-list.component.spec.ts
│ │ │ └── company-list.component.ts
│ │ ├── company-table
│ │ │ ├── company-table.component.html
│ │ │ ├── company-table.component.scss
│ │ │ └── company-table.component.ts
│ │ └── company.service.ts
│ ├── core
│ │ └── rxjs-extensions.ts
│ ├── effects
│ │ └── company.effects.ts
│ ├── home
│ │ ├── home-routing.module.ts
│ │ ├── home.module.ts
│ │ └── home
│ │ │ ├── home.component.html
│ │ │ ├── home.component.scss
│ │ │ └── home.component.ts
│ ├── models
│ │ ├── appState.ts
│ │ ├── company.ts
│ │ └── index.ts
│ ├── reducers
│ │ ├── company.reducer.spec.ts
│ │ └── company.reducer.ts
│ └── wallabyTest.ts
├── assets
│ ├── .gitkeep
│ └── ngrx.png
├── environments
│ ├── environment.prod.ts
│ └── environment.ts
├── favicon.ico
├── index.html
├── main.ts
├── polyfills.ts
├── styles.scss
├── test.ts
├── tsconfig.app.json
├── tsconfig.spec.json
└── typings.d.ts
├── tsconfig.json
├── tslint.json
└── wallaby.js
/.angular-cli.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "project": {
4 | "name": "ngrx"
5 | },
6 | "apps": [
7 | {
8 | "root": "src",
9 | "outDir": "dist",
10 | "assets": [
11 | "assets",
12 | "favicon.ico"
13 | ],
14 | "index": "index.html",
15 | "main": "main.ts",
16 | "polyfills": "polyfills.ts",
17 | "test": "test.ts",
18 | "tsconfig": "tsconfig.app.json",
19 | "testTsconfig": "tsconfig.spec.json",
20 | "prefix": "app",
21 | "styles": [
22 | "styles.scss",
23 | "../node_modules/bootstrap/dist/css/bootstrap.min.css"
24 | ],
25 | "scripts": [],
26 | "environmentSource": "environments/environment.ts",
27 | "environments": {
28 | "dev": "environments/environment.ts",
29 | "prod": "environments/environment.prod.ts"
30 | }
31 | }
32 | ],
33 | "e2e": {
34 | "protractor": {
35 | "config": "./protractor.conf.js"
36 | }
37 | },
38 | "lint": [
39 | {
40 | "project": "src/tsconfig.app.json"
41 | },
42 | {
43 | "project": "src/tsconfig.spec.json"
44 | },
45 | {
46 | "project": "e2e/tsconfig.e2e.json"
47 | }
48 | ],
49 | "test": {
50 | "karma": {
51 | "config": "./karma.conf.js"
52 | }
53 | },
54 | "defaults": {
55 | "styleExt": "scss",
56 | "component": {}
57 | }
58 | }
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | max_line_length = off
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 |
8 | # dependencies
9 | /node_modules
10 |
11 | # IDEs and editors
12 | /.idea
13 | .project
14 | .classpath
15 | .c9/
16 | *.launch
17 | .settings/
18 | *.sublime-workspace
19 |
20 | # IDE - VSCode
21 | .vscode/*
22 | !.vscode/settings.json
23 | !.vscode/tasks.json
24 | !.vscode/launch.json
25 | !.vscode/extensions.json
26 |
27 | # misc
28 | /.sass-cache
29 | /connect.lock
30 | /coverage
31 | /libpeerconnection.log
32 | npm-debug.log
33 | testem.log
34 | /typings
35 |
36 | # e2e
37 | /e2e/*.js
38 | /e2e/*.map
39 |
40 | # System Files
41 | .DS_Store
42 | Thumbs.db
43 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "typescript.tsdk": "node_modules/typescript/lib"
3 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Pluralsight Course - Play by Play with Angular and ngrx
2 |
3 | ***This project runs with the current version 4 of ngrx. If you want the old version from the course use the ngrx-3 branch. It is amost the same except for registering the reducer and effects in the app module as the syntax changed in v4 of ngrx***
4 |
5 | ## To run this project
6 | 1. Install these if you do not already have them on your machine cli.angular.io, https://nodejs.org/en/ and https://git-scm.com/downloads
7 |
8 | 2. git clone this repo and cd into it
9 |
10 | ```
11 | git clone https://github.com/duncanhunter/ngrx-play-by-play && cd ngrx-play-by-play
12 | ```
13 |
14 |
15 |
16 | 3. npm install
17 |
18 |
19 |
20 | ```
21 | npm i
22 | ```
23 |
24 |
25 |
26 | 4. Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
27 |
28 |
29 |
30 | ```
31 | ng s
32 | ```
33 |
34 |
35 |
--------------------------------------------------------------------------------
/e2e/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { NgrxPage } from './app.po';
2 |
3 | describe('ngrx App', () => {
4 | let page: NgrxPage;
5 |
6 | beforeEach(() => {
7 | page = new NgrxPage();
8 | });
9 |
10 | it('should display welcome message', () => {
11 | page.navigateTo();
12 | expect(page.getParagraphText()).toEqual('Welcome to app!!');
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/e2e/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class NgrxPage {
4 | navigateTo() {
5 | return browser.get('/');
6 | }
7 |
8 | getParagraphText() {
9 | return element(by.css('app-root h1')).getText();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/e2e/tsconfig.e2e.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/e2e",
5 | "module": "commonjs",
6 | "target": "es5",
7 | "types": [
8 | "jasmine",
9 | "node"
10 | ]
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/0.13/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular/cli'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular/cli/plugins/karma')
14 | ],
15 | client:{
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | reports: [ 'html', 'lcovonly' ],
20 | fixWebpackSourcePaths: true
21 | },
22 | angularCli: {
23 | environment: 'dev'
24 | },
25 | reporters: ['progress', 'kjhtml'],
26 | port: 9876,
27 | colors: true,
28 | logLevel: config.LOG_INFO,
29 | autoWatch: true,
30 | browsers: ['Chrome'],
31 | singleRun: false
32 | });
33 | };
34 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ngrx",
3 | "version": "0.0.0",
4 | "license": "MIT",
5 | "scripts": {
6 | "ng": "ng",
7 | "start": "ng serve",
8 | "build": "ng build",
9 | "test": "ng test",
10 | "lint": "ng lint",
11 | "e2e": "ng e2e"
12 | },
13 | "private": true,
14 | "dependencies": {
15 | "@angular/animations": "^4.2.2",
16 | "@angular/common": "^4.0.0",
17 | "@angular/compiler": "^4.0.0",
18 | "@angular/core": "^4.0.0",
19 | "@angular/flex-layout": "^2.0.0-beta.8",
20 | "@angular/forms": "^4.0.0",
21 | "@angular/http": "^4.0.0",
22 | "@angular/material": "^2.0.0-beta.6",
23 | "@angular/platform-browser": "^4.0.0",
24 | "@angular/platform-browser-dynamic": "^4.0.0",
25 | "@angular/router": "^4.0.0",
26 | "@ngrx/effects": "^4.1.1",
27 | "@ngrx/store": "^4.1.1",
28 | "@ngrx/store-devtools": "^4.1.1",
29 | "bootstrap": "^4.0.0-alpha.6",
30 | "core-js": "^2.4.1",
31 | "hammerjs": "^2.0.8",
32 | "ngrx-store-freeze": "^0.1.9",
33 | "reselect": "^3.0.1",
34 | "rxjs": "5.5.2",
35 | "zone.js": "^0.8.4"
36 | },
37 | "devDependencies": {
38 | "@angular/cli": "1.1.1",
39 | "@angular/compiler-cli": "^4.0.0",
40 | "@angular/language-service": "^4.0.0",
41 | "@types/jasmine": "2.5.45",
42 | "@types/node": "~6.0.60",
43 | "angular2-template-loader": "^0.6.2",
44 | "codelyzer": "~3.0.1",
45 | "electron": "^1.6.11",
46 | "jasmine-core": "~2.6.2",
47 | "jasmine-spec-reporter": "~4.1.0",
48 | "karma": "~1.7.0",
49 | "karma-chrome-launcher": "~2.1.1",
50 | "karma-cli": "~1.0.1",
51 | "karma-coverage-istanbul-reporter": "^1.2.1",
52 | "karma-jasmine": "~1.1.0",
53 | "karma-jasmine-html-reporter": "^0.2.2",
54 | "protractor": "~5.1.2",
55 | "ts-node": "~3.0.4",
56 | "tslint": "~5.3.2",
57 | "typescript": "2.6.2",
58 | "wallaby-webpack": "0.0.38"
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './e2e/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: 'e2e/tsconfig.e2e.json'
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/src/app/actions/company.actions.ts:
--------------------------------------------------------------------------------
1 | import { Action } from '@ngrx/store';
2 | import { Company } from '../models';
3 |
4 | export const LOAD_COMPANIES = 'LOAD_COMPANIES';
5 | export const LOAD_COMPANIES_SUCCESS = 'LOAD_COMPANIES_SUCCESS';
6 | export const DELETE_COMPANY = 'DELETE_COMPANY';
7 | export const DELETE_COMPANY_SUCCESS = 'DELETE_COMPANY_SUCCESS';
8 |
9 | export class LoadCompaniesAction implements Action {
10 | readonly type = LOAD_COMPANIES;
11 |
12 | constructor() { }
13 | }
14 |
15 | export class LoadCompaniesSuccessAction implements Action {
16 | readonly type = LOAD_COMPANIES_SUCCESS;
17 |
18 | constructor(public payload: Company[]) { }
19 | }
20 |
21 | export class DeleteCompanyAction implements Action {
22 | readonly type = DELETE_COMPANY;
23 |
24 | constructor(public payload: number) { }
25 | }
26 |
27 | export class DeleteCompanySuccessAction implements Action {
28 | readonly type = DELETE_COMPANY_SUCCESS;
29 |
30 | constructor(public payload: number) { }
31 | }
32 |
33 | export type Actions
34 | = LoadCompaniesAction
35 | | LoadCompaniesSuccessAction
36 | | DeleteCompanyAction
37 | | DeleteCompanySuccessAction
38 |
39 |
--------------------------------------------------------------------------------
/src/app/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 | import { CompanyListComponent } from './company/company-list/company-list.component';
4 | import { HomeComponent } from './home/home/home.component';
5 | import { CompanyEditComponent } from './company/company-edit/company-edit.component';
6 |
7 | const routes: Routes = [
8 | { path: '', redirectTo: 'home', pathMatch: 'full' },
9 | { path: 'company/list', component: CompanyListComponent },
10 | { path: 'company/edit/:id', component: CompanyEditComponent },
11 | { path: 'home', loadChildren: 'app/home/home.module#HomeModule' }
12 | ];
13 |
14 | @NgModule({
15 | imports: [RouterModule.forRoot(routes)],
16 | exports: [RouterModule]
17 | })
18 | export class AppRoutingModule { }
19 |
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/app/app.component.scss:
--------------------------------------------------------------------------------
1 | .navbar {
2 | flex-direction: row;
3 | margin-bottom: 10px;
4 | }
--------------------------------------------------------------------------------
/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 |
2 | import { AppComponent } from './app.component';
3 |
4 | describe(`AppComponent`, () => {
5 | it(`should add 1 + 1`, () => {
6 | expect(1 + 1).toEqual(2);
7 | });
8 |
9 | it(`should have a component`, () => {
10 | const component = new AppComponent();
11 | expect(component.title).toEqual('hello sydney, welcome to fbc');
12 | });
13 |
14 | });
15 |
16 | // import { TestBed, async } from '@angular/core/testing';
17 | // import { RouterTestingModule } from '@angular/router/testing';
18 |
19 | // import { AppComponent } from './app.component';
20 |
21 | // describe('AppComponent', () => {
22 | // beforeEach(async(() => {
23 | // TestBed.configureTestingModule({
24 | // imports: [
25 | // RouterTestingModule
26 | // ],
27 | // declarations: [
28 | // AppComponent
29 | // ],
30 | // }).compileComponents();
31 | // }));
32 |
33 | // it('should create the app', async(() => {
34 | // const fixture = TestBed.createComponent(AppComponent);
35 | // const app = fixture.debugElement.componentInstance;
36 | // expect(app).toBeTruthy();
37 | // }));
38 |
39 | // it(`should have as title 'fbc works!'`, async(() => {
40 | // const fixture = TestBed.createComponent(AppComponent);
41 | // const app = fixture.debugElement.componentInstance;
42 | // expect(app.title).toEqual('fbc works!');
43 | // }));
44 |
45 | // it('should render title in a h1 tag', async(() => {
46 | // const fixture = TestBed.createComponent(AppComponent);
47 | // fixture.detectChanges();
48 | // const compiled = fixture.debugElement.nativeElement;
49 | // expect(compiled.querySelector('h1').textContent).toContain('fbc works!');
50 | // }));
51 | // });
52 |
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-root',
5 | templateUrl: './app.component.html',
6 | styleUrls: ['./app.component.scss']
7 | })
8 | export class AppComponent implements OnInit {
9 | title = 'hello sydney, welcome to fbc';
10 | companiesCount = 0;
11 |
12 | // constructor(private companiesStateService: CompanyStateService) {
13 | // }
14 |
15 | ngOnInit() {
16 | // console.log("app component on init");
17 | // this.companiesStateService.loadCompanies();
18 | // this.companiesStateService.companies$
19 | // .do(x => console.log('ngoninint1', x))
20 | // .subscribe(list => {if (list) this.companiesCount = list.length});
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import './core/rxjs-extensions';
2 | import { BrowserModule } from '@angular/platform-browser';
3 | import { NgModule } from '@angular/core';
4 | import { FormsModule, ReactiveFormsModule } from '@angular/forms';
5 | import { HttpModule } from '@angular/http';
6 | import { AppRoutingModule } from './app-routing.module';
7 | import { AppComponent } from './app.component';
8 | import { CompanyListComponent } from './company/company-list/company-list.component';
9 | import { CompanyService } from './company/company.service';
10 | import { CompanyTableComponent } from './company/company-table/company-table.component';
11 | import { CompanyEditComponent } from './company/company-edit/company-edit.component';
12 |
13 | import { StoreModule } from '@ngrx/store';
14 | import { StoreDevtoolsModule } from '@ngrx/store-devtools';
15 | import { EffectsModule } from '@ngrx/effects';
16 | import { CompanyEffects } from './effects/company.effects';
17 | import { companyReducer } from './reducers/company.reducer';
18 |
19 | @NgModule({
20 | declarations: [
21 | AppComponent,
22 | CompanyListComponent,
23 | CompanyTableComponent,
24 | CompanyEditComponent
25 | ],
26 | imports: [
27 | BrowserModule,
28 | FormsModule,
29 | ReactiveFormsModule,
30 | HttpModule,
31 | AppRoutingModule,
32 | StoreModule.forRoot({companies: companyReducer}),
33 | EffectsModule.forRoot([CompanyEffects]),
34 | StoreDevtoolsModule.instrument({maxAge: 25})
35 | ],
36 | providers: [
37 | CompanyService,
38 | ],
39 | bootstrap: [AppComponent]
40 | })
41 | export class AppModule { }
42 |
--------------------------------------------------------------------------------
/src/app/company/company-edit/company-edit.component.html:
--------------------------------------------------------------------------------
1 |
21 |
--------------------------------------------------------------------------------
/src/app/company/company-edit/company-edit.component.scss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duncanhunter/Pluralsight-NgRx-Play-by-Play/5a034c46bd34de399f8dda0d1ba9dfef1c347dfc/src/app/company/company-edit/company-edit.component.scss
--------------------------------------------------------------------------------
/src/app/company/company-edit/company-edit.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { Router, ActivatedRoute } from '@angular/router';
3 |
4 | import { CompanyService } from '../company.service';
5 | import { FormBuilder, Validators, FormGroup } from '@angular/forms';
6 | import { Store } from '@ngrx/store';
7 | import * as companyActions from './../../actions/company.actions';
8 | import { AppState } from './../../models/appState';
9 |
10 | @Component({
11 | selector: 'app-company-edit',
12 | templateUrl: './company-edit.component.html',
13 | styleUrls: ['./company-edit.component.scss']
14 | })
15 | export class CompanyEditComponent implements OnInit {
16 | companyForm: FormGroup;
17 | isNewCompany: boolean;
18 | companyId: any;
19 |
20 | constructor(
21 | private store: Store,
22 | private router: Router,
23 | private activatedRoute: ActivatedRoute,
24 | private companyService: CompanyService,
25 | private fb: FormBuilder
26 | ) {
27 |
28 | }
29 |
30 | ngOnInit() {
31 | this.companyId = this.activatedRoute.snapshot.params['id'];
32 | this.isNewCompany = this.companyId === 'new';
33 | this.buildForm();
34 | if (!this.isNewCompany) {
35 | this.getCompany();
36 | }
37 |
38 | }
39 |
40 | getCompany() {
41 | this.companyService.getCompany(this.companyId)
42 | .subscribe(company => this.companyForm.patchValue(company));
43 | // this.store.dispatch(new companyActions.SelectCompanyAction(this.companyId));
44 | // this.store.select(fromRoot.getSelectedCompany)
45 | // .do(console.log)
46 | // .filter(company => company != null)
47 | // .subscribe(company => this.companyForm.patchValue(company));
48 | }
49 |
50 | buildForm() {
51 | this.companyForm = this.fb.group({
52 | name: ['', Validators.required],
53 | email: [''],
54 | phone: ['']
55 | });
56 | }
57 |
58 | saveCompany() {
59 | if (this.isNewCompany) {
60 | this.companyService.addCompany(this.companyForm.value)
61 | .subscribe(() => this.router.navigate([`/company/list`]));
62 | } else {
63 | // this.companyForm.value['id'] = this.companyId;
64 | const companyToUpdate = { ...this.companyForm.value, id: this.companyId };
65 | this.companyService.updateCompany(companyToUpdate)
66 | .subscribe(() => this.router.navigate([`/company/list`]));
67 | }
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/app/company/company-list/company-list.component.html:
--------------------------------------------------------------------------------
1 |
2 | Companies
3 |
4 |
5 |
8 |
--------------------------------------------------------------------------------
/src/app/company/company-list/company-list.component.scss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duncanhunter/Pluralsight-NgRx-Play-by-Play/5a034c46bd34de399f8dda0d1ba9dfef1c347dfc/src/app/company/company-list/company-list.component.scss
--------------------------------------------------------------------------------
/src/app/company/company-list/company-list.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 | import { CompanyListComponent } from './company-list.component';
3 | import { CompanyTableComponent } from '../company-table/company-table.component';
4 | import { CUSTOM_ELEMENTS_SCHEMA, DebugElement } from '@angular/core';
5 | import { RouterTestingModule } from '@angular/router/testing';
6 | import { CompanyService } from '../company.service';
7 | import { HttpModule } from '@angular/http';
8 | import 'rxjs/Rx';
9 | import { Observable } from 'rxjs/Observable';
10 | import { By } from '@angular/platform-browser';
11 | import { Company } from '../../models';
12 |
13 | xdescribe('CompanyListComponent', () => {
14 | let component: CompanyListComponent;
15 | let fixture: ComponentFixture;
16 | let companyService: CompanyService;
17 | let de: DebugElement;
18 |
19 | const fakeCompany = { name: 'Duncan', email: 'email', phone: 123 } as Company;
20 |
21 | beforeEach(async(() => {
22 |
23 | const companyServiceStub = {
24 | getCompanies: () => Observable.of([fakeCompany, fakeCompany])
25 | };
26 |
27 | TestBed.configureTestingModule({
28 | declarations: [CompanyListComponent, CompanyTableComponent],
29 | providers: [CompanyService],
30 | // providers: [{ provide: CompanyService, useValue: companyServiceStub }],
31 | imports: [RouterTestingModule, HttpModule],
32 | schemas: [CUSTOM_ELEMENTS_SCHEMA]
33 | })
34 | .compileComponents();
35 | }));
36 |
37 | beforeEach(() => {
38 | fixture = TestBed.createComponent(CompanyListComponent);
39 | component = fixture.componentInstance;
40 | de = fixture.debugElement;
41 | companyService = fixture.debugElement.injector.get(CompanyService);
42 | });
43 |
44 | it('should create', () => {
45 | const spy = spyOn(companyService, 'getCompanies').and.returnValue(Observable.of(fakeCompany));
46 | expect(component).toBeTruthy();
47 | });
48 |
49 | it(`should have a inital item in the template`, (done) => {
50 | const spy = spyOn(companyService, 'getCompanies').and.returnValue(Observable.of([fakeCompany]));
51 |
52 | fixture.detectChanges();
53 | component.companies$.subscribe(c => {
54 | // companyService.getCompanies().subscribe(c => {
55 | fixture.detectChanges();
56 | console.log('c', c);
57 | // console.log('fake', fakeCompany);
58 | expect(c[0]).toBe(fakeCompany);
59 | done();
60 | });
61 | });
62 |
63 | it(`should have a inital item in the template`, async(() => {
64 | spyOn(companyService, 'getCompanies').and.returnValue(Observable.of([fakeCompany, fakeCompany]));
65 |
66 | fixture.detectChanges();
67 | // expect(companyService.getCompanies).toHaveBeenCalledTimes(1);
68 | const companyRows = de.queryAll(By.css('.company-row'));
69 | fixture.whenStable().then(() => {
70 | expect(companyRows.length).toEqual(2);
71 | });
72 | }));
73 | });
74 |
--------------------------------------------------------------------------------
/src/app/company/company-list/company-list.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { CompanyService } from '../company.service';
3 | import { Observable } from 'rxjs/Observable';
4 | import { Store } from '@ngrx/store';
5 | import { Company } from '../../models';
6 | import { AppState } from 'app/models/appState';
7 | import * as companyAcitons from './../../actions/company.actions';
8 |
9 | @Component({
10 | selector: 'app-company-list',
11 | templateUrl: './company-list.component.html',
12 | styleUrls: ['./company-list.component.scss'],
13 | })
14 | export class CompanyListComponent implements OnInit {
15 |
16 | companies$: Observable;
17 |
18 | constructor(private store: Store) { }
19 |
20 | ngOnInit() {
21 | this.loadCompanies();
22 | this.companies$ = this.store.select(state => state.companies.companies);
23 | }
24 |
25 | loadCompanies() {
26 | this.store.dispatch(new companyAcitons.LoadCompaniesAction());
27 | }
28 |
29 | deleteCompany(companyId: number) {
30 | this.store.dispatch(new companyAcitons.DeleteCompanyAction(companyId));
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/app/company/company-table/company-table.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Name |
5 | Email |
6 | Phone |
7 | |
8 |
9 |
10 |
11 |
12 | {{company.name}} |
13 | {{company.email}} |
14 | {{company.phone}} |
15 |
16 |
17 |
18 | |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/app/company/company-table/company-table.component.scss:
--------------------------------------------------------------------------------
1 | .company-row {
2 | width: 140px;
3 | white-space: nowrap;
4 | }
--------------------------------------------------------------------------------
/src/app/company/company-table/company-table.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
2 | import { Company } from '../../models';
3 |
4 | @Component({
5 | selector: 'app-company-table',
6 | templateUrl: './company-table.component.html',
7 | styleUrls: ['./company-table.component.scss']
8 | })
9 | export class CompanyTableComponent {
10 | @Input() companies: Company[];
11 | @Output() deleteCompany = new EventEmitter();
12 | }
13 |
--------------------------------------------------------------------------------
/src/app/company/company.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { Http, Response, RequestOptions, Headers } from '@angular/http';
3 | import { Observable } from 'rxjs/Observable';
4 | import { Company } from '../models';
5 |
6 | @Injectable()
7 | export class CompanyService {
8 |
9 | API_BASE = 'http://firebootcamp-crm-api.azurewebsites.net/api';
10 |
11 | constructor(private http: Http) { }
12 |
13 | getCompany(companyId: number): Observable {
14 | return this.http.get(`${this.API_BASE}/company/${companyId}`)
15 | .map(data => data.json())
16 | .catch(this.errorHandler);
17 | }
18 |
19 | loadCompanies() {
20 | return this.http.get(`${this.API_BASE}/company`)
21 | .map(data => data.json())
22 | .catch(this.errorHandler)
23 | }
24 |
25 | getCompanies(): Observable {
26 | return this.http.get(`${this.API_BASE}/company`)
27 | .map(data => data.json())
28 | .catch(this.errorHandler);
29 | }
30 |
31 | deleteCompany(companyId: number): Observable {
32 | return this.http.delete(`${this.API_BASE}/company/${companyId}`)
33 | .map((response: Response) => response.json());
34 | }
35 |
36 | addCompany(company: Company) {
37 | const headers = new Headers({ 'content-type': 'application/json' });
38 | const options = new RequestOptions({ headers: headers });
39 |
40 | return this.http.post(`${this.API_BASE}/company`, JSON.stringify(company), options)
41 | .map(response => response.json())
42 | .catch(this.errorHandler);
43 | ;
44 | }
45 |
46 | updateCompany(company: Company) {
47 | const headers = new Headers({ 'content-type': 'application/json' });
48 | const options = new RequestOptions({ headers: headers });
49 | return this.http.put(`${this.API_BASE}/company/${company.id}`, JSON.stringify(company), options)
50 | .map(response => response.json())
51 | .catch(this.errorHandler);
52 | ;
53 | }
54 |
55 | errorHandler(error) {
56 | console.error('CUSTOM ERROR');
57 | return Observable.throw(error);
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/app/core/rxjs-extensions.ts:
--------------------------------------------------------------------------------
1 | import 'rxjs/add/observable/of';
2 | import 'rxjs/add/operator/map';
3 | import 'rxjs/add/operator/catch';
4 | import 'rxjs/add/operator/count';
5 | import 'rxjs/add/operator/do';
6 | import 'rxjs/add/observable/throw';
7 |
--------------------------------------------------------------------------------
/src/app/effects/company.effects.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { Actions, Effect, toPayload } from '@ngrx/effects';
3 | import 'rxjs/add/operator/switchMap';
4 |
5 | import { CompanyService } from '../company/company.service';
6 | import * as companyActions from './../actions/company.actions';
7 | import { DeleteCompanySuccessAction } from '../actions/company.actions';
8 |
9 | @Injectable()
10 | export class CompanyEffects {
11 | constructor(
12 | private actions$: Actions,
13 | private companyService: CompanyService
14 | ) { }
15 |
16 | // tslint:disable-next-line:member-ordering
17 | @Effect() loadCompanies$ = this.actions$
18 | .ofType(companyActions.LOAD_COMPANIES)
19 | .switchMap(() => {
20 | return this.companyService.loadCompanies()
21 | .map(companies => new companyActions.LoadCompaniesSuccessAction(companies));
22 | });
23 |
24 | // tslint:disable-next-line:member-ordering
25 | @Effect() deleteCompany$ = this.actions$
26 | .ofType(companyActions.DELETE_COMPANY)
27 | .switchMap((action: companyActions.DeleteCompanyAction) => {
28 | return this.companyService.deleteCompany(action.payload)
29 | .map(company => new companyActions.DeleteCompanySuccessAction(company.id));
30 | });
31 |
32 | };
33 |
--------------------------------------------------------------------------------
/src/app/home/home-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 | import { HomeComponent } from './home/home.component';
4 |
5 | const routes: Routes = [
6 | {path: '', component: HomeComponent}
7 | ];
8 |
9 | @NgModule({
10 | imports: [RouterModule.forChild(routes)],
11 | exports: [RouterModule]
12 | })
13 | export class HomeRoutingModule { }
14 |
--------------------------------------------------------------------------------
/src/app/home/home.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { CommonModule } from '@angular/common';
3 |
4 | import { HomeRoutingModule } from './home-routing.module';
5 | import { HomeComponent } from './home/home.component';
6 |
7 | @NgModule({
8 | imports: [
9 | CommonModule,
10 | HomeRoutingModule
11 | ],
12 | declarations: [
13 | HomeComponent
14 | ]
15 | })
16 | export class HomeModule { }
17 |
--------------------------------------------------------------------------------
/src/app/home/home/home.component.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/app/home/home/home.component.scss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duncanhunter/Pluralsight-NgRx-Play-by-Play/5a034c46bd34de399f8dda0d1ba9dfef1c347dfc/src/app/home/home/home.component.scss
--------------------------------------------------------------------------------
/src/app/home/home/home.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-home',
5 | templateUrl: './home.component.html',
6 | styleUrls: ['./home.component.scss']
7 | })
8 | export class HomeComponent implements OnInit {
9 |
10 | constructor() { }
11 |
12 | ngOnInit() {
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/app/models/appState.ts:
--------------------------------------------------------------------------------
1 | import { Company } from './company';
2 |
3 | export interface AppState {
4 | companies: { companies: Company[] }
5 | }
6 |
--------------------------------------------------------------------------------
/src/app/models/company.ts:
--------------------------------------------------------------------------------
1 | export interface Company {
2 | id?: number;
3 | name: string;
4 | email: string;
5 | phone: number;
6 | }
7 |
--------------------------------------------------------------------------------
/src/app/models/index.ts:
--------------------------------------------------------------------------------
1 | export { Company } from './company';
2 |
3 |
--------------------------------------------------------------------------------
/src/app/reducers/company.reducer.spec.ts:
--------------------------------------------------------------------------------
1 | import { companyReducer } from './company.reducer';
2 | import * as companyActions from './../actions/company.actions';
3 |
4 | describe(`companyReducer`, () => {
5 |
6 | describe(`deleteCompanyAction`, () => {
7 |
8 | it(`should delete a company`, () => {
9 | const currentState = {
10 | companies: [
11 | { id: 1, name: 'SSW', email: 'email', phone: 123 },
12 | { id: 2, name: 'Microsoft' , email: 'email', phone: 123 },
13 | ]
14 | };
15 | const expectedResult = {
16 | companies: [{ id: 2, name: 'Microsoft', email: 'email', phone: 123 }]
17 | };
18 |
19 | const action = new companyActions.DeleteCompanySuccessAction(1);
20 | const result = companyReducer(currentState, action);
21 | expect(result).toEqual(expectedResult);
22 | });
23 |
24 | });
25 | });
26 |
27 |
--------------------------------------------------------------------------------
/src/app/reducers/company.reducer.ts:
--------------------------------------------------------------------------------
1 | import { Company } from './../models';
2 | import * as fromCompanies from './../actions/company.actions';
3 |
4 | export interface State {
5 | companies: Company[];
6 | };
7 |
8 | const initialState: State = {
9 | companies: []
10 | };
11 |
12 | export function companyReducer(state = initialState, action: fromCompanies.Actions): State {
13 | switch (action.type) {
14 | case fromCompanies.LOAD_COMPANIES_SUCCESS: {
15 | return state = {
16 | companies: action.payload
17 | };
18 | }
19 | case fromCompanies.DELETE_COMPANY_SUCCESS: {
20 | return state = {
21 | companies: state.companies.filter(company => company.id !== action.payload)
22 | };
23 | }
24 | default: {
25 | return state;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/app/wallabyTest.ts:
--------------------------------------------------------------------------------
1 | import './polyfills';
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 |
10 | import { getTestBed } from '@angular/core/testing';
11 | import {
12 | BrowserDynamicTestingModule,
13 | platformBrowserDynamicTesting
14 | } from '@angular/platform-browser-dynamic/testing';
15 |
16 | getTestBed().initTestEnvironment(
17 | BrowserDynamicTestingModule,
18 | platformBrowserDynamicTesting()
19 | );
20 |
--------------------------------------------------------------------------------
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duncanhunter/Pluralsight-NgRx-Play-by-Play/5a034c46bd34de399f8dda0d1ba9dfef1c347dfc/src/assets/.gitkeep
--------------------------------------------------------------------------------
/src/assets/ngrx.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duncanhunter/Pluralsight-NgRx-Play-by-Play/5a034c46bd34de399f8dda0d1ba9dfef1c347dfc/src/assets/ngrx.png
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // The file contents for the current environment will overwrite these during build.
2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do
3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead.
4 | // The list of which env maps to which file can be found in `.angular-cli.json`.
5 |
6 | export const environment = {
7 | production: false
8 | };
9 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/duncanhunter/Pluralsight-NgRx-Play-by-Play/5a034c46bd34de399f8dda0d1ba9dfef1c347dfc/src/favicon.ico
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Ngrx
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule);
12 |
--------------------------------------------------------------------------------
/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/
22 | // import 'core-js/es6/symbol';
23 | // import 'core-js/es6/object';
24 | // import 'core-js/es6/function';
25 | // import 'core-js/es6/parse-int';
26 | // import 'core-js/es6/parse-float';
27 | // import 'core-js/es6/number';
28 | // import 'core-js/es6/math';
29 | // import 'core-js/es6/string';
30 | // import 'core-js/es6/date';
31 | // import 'core-js/es6/array';
32 | // import 'core-js/es6/regexp';
33 | // import 'core-js/es6/map';
34 | // import 'core-js/es6/weak-map';
35 | // import 'core-js/es6/set';
36 |
37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
38 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
39 |
40 | /** IE10 and IE11 requires the following to support `@angular/animation`. */
41 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
42 |
43 |
44 | /** Evergreen browsers require these. **/
45 | import 'core-js/es6/reflect';
46 | import 'core-js/es7/reflect';
47 |
48 |
49 | /** ALL Firefox browsers require the following to support `@angular/animation`. **/
50 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
51 |
52 |
53 |
54 | /***************************************************************************************************
55 | * Zone JS is required by Angular itself.
56 | */
57 | import 'zone.js/dist/zone'; // Included with Angular CLI.
58 |
59 |
60 |
61 | /***************************************************************************************************
62 | * APPLICATION IMPORTS
63 | */
64 |
65 | /**
66 | * Date, currency, decimal and percent pipes.
67 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
68 | */
69 | // import 'intl'; // Run `npm install --save intl`.
70 | /**
71 | * Need to import at least one locale-data with intl.
72 | */
73 | // import 'intl/locale-data/jsonp/en';
74 |
--------------------------------------------------------------------------------
/src/styles.scss:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 | @import '~@angular/material/prebuilt-themes/deeppurple-amber.css';
3 | @import url(https://fonts.googleapis.com/css?family=Roboto);
4 | @import url(https://fonts.googleapis.com/icon?family=Material+Icons);
5 |
6 | body {
7 | margin: 15px;
8 |
9 | }
--------------------------------------------------------------------------------
/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/src/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "module": "es2015",
6 | "baseUrl": "",
7 | "types": []
8 | },
9 | "exclude": [
10 | "test.ts",
11 | "**/*.spec.ts"
12 | ]
13 | }
14 |
--------------------------------------------------------------------------------
/src/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/spec",
5 | "module": "commonjs",
6 | "target": "es5",
7 | "baseUrl": "",
8 | "types": [
9 | "jasmine",
10 | "node"
11 | ]
12 | },
13 | "files": [
14 | "test.ts"
15 | ],
16 | "include": [
17 | "**/*.spec.ts",
18 | "**/*.d.ts"
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/src/typings.d.ts:
--------------------------------------------------------------------------------
1 | /* SystemJS module definition */
2 | declare var module: NodeModule;
3 | interface NodeModule {
4 | id: string;
5 | }
6 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "outDir": "./dist/out-tsc",
5 | "baseUrl": "src",
6 | "sourceMap": true,
7 | "declaration": false,
8 | "moduleResolution": "node",
9 | "emitDecoratorMetadata": true,
10 | "experimentalDecorators": true,
11 | "target": "es5",
12 | "typeRoots": [
13 | "node_modules/@types"
14 | ],
15 | "lib": [
16 | "es2016",
17 | "dom"
18 | ]
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/codelyzer"
4 | ],
5 | "rules": {
6 | "arrow-return-shorthand": true,
7 | "callable-types": true,
8 | "class-name": true,
9 | "comment-format": [
10 | true,
11 | "check-space"
12 | ],
13 | "curly": true,
14 | "eofline": true,
15 | "forin": true,
16 | "import-blacklist": [
17 | true,
18 | "rxjs"
19 | ],
20 | "import-spacing": true,
21 | "indent": [
22 | true,
23 | "spaces"
24 | ],
25 | "interface-over-type-literal": true,
26 | "label-position": true,
27 | "max-line-length": [
28 | true,
29 | 140
30 | ],
31 | "member-access": false,
32 | "member-ordering": [
33 | true,
34 | "static-before-instance",
35 | "variables-before-functions"
36 | ],
37 | "no-arg": true,
38 | "no-bitwise": true,
39 | "no-console": [
40 | true,
41 | "debug",
42 | "info",
43 | "time",
44 | "timeEnd",
45 | "trace"
46 | ],
47 | "no-construct": true,
48 | "no-debugger": true,
49 | "no-duplicate-super": true,
50 | "no-empty": false,
51 | "no-empty-interface": true,
52 | "no-eval": true,
53 | "no-inferrable-types": [
54 | true,
55 | "ignore-params"
56 | ],
57 | "no-misused-new": true,
58 | "no-non-null-assertion": true,
59 | "no-shadowed-variable": true,
60 | "no-string-literal": false,
61 | "no-string-throw": true,
62 | "no-switch-case-fall-through": true,
63 | "no-trailing-whitespace": true,
64 | "no-unnecessary-initializer": true,
65 | "no-unused-expression": true,
66 | "no-use-before-declare": true,
67 | "no-var-keyword": true,
68 | "object-literal-sort-keys": false,
69 | "one-line": [
70 | true,
71 | "check-open-brace",
72 | "check-catch",
73 | "check-else",
74 | "check-whitespace"
75 | ],
76 | "prefer-const": true,
77 | "quotemark": [
78 | true,
79 | "single"
80 | ],
81 | "radix": true,
82 | "semicolon": [
83 | "always"
84 | ],
85 | "triple-equals": [
86 | true,
87 | "allow-null-check"
88 | ],
89 | "typedef-whitespace": [
90 | true,
91 | {
92 | "call-signature": "nospace",
93 | "index-signature": "nospace",
94 | "parameter": "nospace",
95 | "property-declaration": "nospace",
96 | "variable-declaration": "nospace"
97 | }
98 | ],
99 | "typeof-compare": true,
100 | "unified-signatures": true,
101 | "variable-name": false,
102 | "whitespace": [
103 | true,
104 | "check-branch",
105 | "check-decl",
106 | "check-operator",
107 | "check-separator",
108 | "check-type"
109 | ],
110 | "directive-selector": [
111 | true,
112 | "attribute",
113 | "app",
114 | "camelCase"
115 | ],
116 | "component-selector": [
117 | true,
118 | "element",
119 | "app",
120 | "kebab-case"
121 | ],
122 | "use-input-property-decorator": true,
123 | "use-output-property-decorator": true,
124 | "use-host-property-decorator": true,
125 | "no-input-rename": true,
126 | "no-output-rename": true,
127 | "use-life-cycle-interface": true,
128 | "use-pipe-transform-interface": true,
129 | "component-class-suffix": true,
130 | "directive-class-suffix": true,
131 | "no-access-missing-member": true,
132 | "templates-use-public": true,
133 | "invoke-injectable": true
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/wallaby.js:
--------------------------------------------------------------------------------
1 | var wallabyWebpack = require('wallaby-webpack');
2 | var path = require('path');
3 |
4 |
5 | var compilerOptions = Object.assign(
6 | require('./tsconfig.json').compilerOptions,
7 | require('./src/tsconfig.spec.json').compilerOptions);
8 | console.log('compilerOptions', compilerOptions)
9 |
10 | module.exports = function (wallaby) {
11 | // process.env.NODE_PATH += path.delimiter + path.join(wallaby.projectCacheDir, 'lib');
12 |
13 | var webpackPostprocessor = wallabyWebpack({
14 | entryPatterns: [
15 | 'src/wallabyTest.js',
16 | 'src/**/*spec.js'
17 | ],
18 |
19 | module: {
20 | loaders: [
21 | { test: /\.css$/, loader: 'raw-loader' },
22 | { test: /\.html$/, loader: 'raw-loader' },
23 | { test: /\.js$/, loader: 'angular2-template-loader', exclude: /node_modules/ },
24 | { test: /\.json$/, loader: 'json-loader' },
25 | { test: /\.styl$/, loaders: ['raw-loader', 'stylus-loader'] },
26 | { test: /\.less$/, loaders: ['raw-loader', 'less-loader'] },
27 | { test: /\.scss$|\.sass$/, loaders: ['raw-loader', 'sass-loader'] },
28 | { test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000' }
29 | ]
30 | },
31 |
32 | resolve: {
33 | modules: [
34 | path.join(wallaby.projectCacheDir, 'src/app'),
35 | path.join(wallaby.projectCacheDir, 'src')
36 | ]
37 | }
38 | });
39 |
40 | return {
41 | files: [
42 | { pattern: 'src/**/*.ts', load: false },
43 | { pattern: 'src/**/*.d.ts', ignore: true },
44 | { pattern: 'src/**/*.css', load: false },
45 | { pattern: 'src/**/*.less', load: false },
46 | { pattern: 'src/**/*.scss', load: false },
47 | { pattern: 'src/**/*.sass', load: false },
48 | { pattern: 'src/**/*.styl', load: false },
49 | { pattern: 'src/**/*.html', load: false },
50 | { pattern: 'src/**/*.json', load: false },
51 | { pattern: 'src/**/*spec.ts', ignore: true }
52 | ],
53 |
54 | tests: [
55 | { pattern: 'src/**/*spec.ts', load: false }
56 | ],
57 |
58 | testFramework: 'jasmine',
59 |
60 | compilers: {
61 | '**/*.ts': wallaby.compilers.typeScript(compilerOptions)
62 | },
63 |
64 | middleware: function (app, express) {
65 | var path = require('path');
66 | app.use('/favicon.ico', express.static(path.join(__dirname, 'src/favicon.ico')));
67 | app.use('/assets', express.static(path.join(__dirname, 'src/assets')));
68 | },
69 |
70 | env: {
71 | kind: 'electron'
72 | },
73 |
74 | postprocessor: webpackPostprocessor,
75 |
76 | setup: function () {
77 | window.__moduleBundler.loadTests();
78 | },
79 |
80 | debug: true
81 | };
82 | };
--------------------------------------------------------------------------------