├── .editorconfig ├── .gitignore ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── angular.json ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.e2e.json ├── package-lock.json ├── package.json ├── src ├── app │ ├── app-routing.module.ts │ ├── app.component.css │ ├── app.component.html │ ├── app.component.ts │ ├── app.module.ts │ ├── models │ │ └── star-ship.model.ts │ ├── starships │ │ ├── ship-detail │ │ │ ├── ship-detail.component.css │ │ │ ├── ship-detail.component.html │ │ │ └── ship-detail.component.ts │ │ ├── ship-list │ │ │ ├── ship-list.component.css │ │ │ ├── ship-list.component.html │ │ │ └── ship-list.component.ts │ │ ├── starships-routing.module.ts │ │ ├── starships.module.ts │ │ └── store │ │ │ ├── actions │ │ │ └── ships.actions.ts │ │ │ ├── effects │ │ │ └── ships.effects.ts │ │ │ └── reducers │ │ │ ├── index.ts │ │ │ └── ships.reducer.ts │ ├── store │ │ ├── actions │ │ │ └── auth.actions.ts │ │ ├── effects │ │ │ └── auth.effects.ts │ │ └── reducers │ │ │ ├── auth.reducer.ts │ │ │ └── index.ts │ └── welcome │ │ ├── welcome.component.css │ │ ├── welcome.component.html │ │ ├── welcome.component.spec.ts │ │ └── welcome.component.ts ├── assets │ └── .gitkeep ├── browserslist ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── karma.conf.js ├── main.ts ├── polyfills.ts ├── styles.css ├── test.ts ├── tsconfig.app.json ├── tsconfig.spec.json └── tslint.json ├── tsconfig.json └── tslint.json /.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 | yarn-error.log 34 | testem.log 35 | /typings 36 | 37 | # System Files 38 | .DS_Store 39 | Thumbs.db 40 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "node_modules\\typescript\\lib" 3 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ngrx-tutorial -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "ngrx-tutorial": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "prefix": "app", 11 | "schematics": {}, 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/ngrx-tutorial", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "src/tsconfig.app.json", 21 | "assets": [ 22 | "src/favicon.ico", 23 | "src/assets" 24 | ], 25 | "styles": [ 26 | "src/styles.css" 27 | ], 28 | "scripts": [] 29 | }, 30 | "configurations": { 31 | "production": { 32 | "fileReplacements": [ 33 | { 34 | "replace": "src/environments/environment.ts", 35 | "with": "src/environments/environment.prod.ts" 36 | } 37 | ], 38 | "optimization": true, 39 | "outputHashing": "all", 40 | "sourceMap": false, 41 | "extractCss": true, 42 | "namedChunks": false, 43 | "aot": true, 44 | "extractLicenses": true, 45 | "vendorChunk": false, 46 | "buildOptimizer": true 47 | } 48 | } 49 | }, 50 | "serve": { 51 | "builder": "@angular-devkit/build-angular:dev-server", 52 | "options": { 53 | "browserTarget": "ngrx-tutorial:build" 54 | }, 55 | "configurations": { 56 | "production": { 57 | "browserTarget": "ngrx-tutorial:build:production" 58 | } 59 | } 60 | }, 61 | "extract-i18n": { 62 | "builder": "@angular-devkit/build-angular:extract-i18n", 63 | "options": { 64 | "browserTarget": "ngrx-tutorial:build" 65 | } 66 | }, 67 | "test": { 68 | "builder": "@angular-devkit/build-angular:karma", 69 | "options": { 70 | "main": "src/test.ts", 71 | "polyfills": "src/polyfills.ts", 72 | "tsConfig": "src/tsconfig.spec.json", 73 | "karmaConfig": "src/karma.conf.js", 74 | "styles": [ 75 | "src/styles.css" 76 | ], 77 | "scripts": [], 78 | "assets": [ 79 | "src/favicon.ico", 80 | "src/assets" 81 | ] 82 | } 83 | }, 84 | "lint": { 85 | "builder": "@angular-devkit/build-angular:tslint", 86 | "options": { 87 | "tsConfig": [ 88 | "src/tsconfig.app.json", 89 | "src/tsconfig.spec.json" 90 | ], 91 | "exclude": [ 92 | "**/node_modules/**" 93 | ] 94 | } 95 | } 96 | } 97 | }, 98 | "ngrx-tutorial-e2e": { 99 | "root": "e2e/", 100 | "projectType": "application", 101 | "architect": { 102 | "e2e": { 103 | "builder": "@angular-devkit/build-angular:protractor", 104 | "options": { 105 | "protractorConfig": "e2e/protractor.conf.js", 106 | "devServerTarget": "ngrx-tutorial:serve" 107 | }, 108 | "configurations": { 109 | "production": { 110 | "devServerTarget": "ngrx-tutorial:serve:production" 111 | } 112 | } 113 | }, 114 | "lint": { 115 | "builder": "@angular-devkit/build-angular:tslint", 116 | "options": { 117 | "tsConfig": "e2e/tsconfig.e2e.json", 118 | "exclude": [ 119 | "**/node_modules/**" 120 | ] 121 | } 122 | } 123 | } 124 | } 125 | }, 126 | "defaultProject": "ngrx-tutorial", 127 | "cli": { 128 | "defaultCollection": "@ngrx/schematics" 129 | } 130 | } -------------------------------------------------------------------------------- /e2e/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 | './src/**/*.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: require('path').join(__dirname, './tsconfig.e2e.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('workspace-project App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('Welcome to ngrx-tutorial!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 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/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ngrx-tutorial", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "^6.0.3", 15 | "@angular/common": "^6.0.3", 16 | "@angular/compiler": "^6.0.3", 17 | "@angular/core": "^6.0.3", 18 | "@angular/forms": "^6.0.3", 19 | "@angular/http": "^6.0.3", 20 | "@angular/platform-browser": "^6.0.3", 21 | "@angular/platform-browser-dynamic": "^6.0.3", 22 | "@angular/router": "^6.0.3", 23 | "@ngrx/effects": "^6.0.1", 24 | "@ngrx/router-store": "^6.0.1", 25 | "@ngrx/store": "^6.0.1", 26 | "@ngrx/store-devtools": "^6.0.1", 27 | "core-js": "^2.5.4", 28 | "rxjs": "^6.0.0", 29 | "zone.js": "^0.8.26" 30 | }, 31 | "devDependencies": { 32 | "@angular-devkit/build-angular": "~0.6.8", 33 | "@angular/cli": "~6.0.8", 34 | "@angular/compiler-cli": "^6.0.3", 35 | "@angular/language-service": "^6.0.3", 36 | "@ngrx/schematics": "^6.0.1", 37 | "@types/jasmine": "~2.8.6", 38 | "@types/jasminewd2": "~2.0.3", 39 | "@types/node": "~8.9.4", 40 | "codelyzer": "~4.2.1", 41 | "jasmine-core": "~2.99.1", 42 | "jasmine-spec-reporter": "~4.2.1", 43 | "karma": "~1.7.1", 44 | "karma-chrome-launcher": "~2.2.0", 45 | "karma-coverage-istanbul-reporter": "~2.0.0", 46 | "karma-jasmine": "~1.1.1", 47 | "karma-jasmine-html-reporter": "^0.2.2", 48 | "protractor": "~5.3.0", 49 | "ts-node": "~5.0.1", 50 | "tslint": "~5.9.1", 51 | "typescript": "~2.7.2" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from "@angular/core"; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | 4 | import { AppComponent } from './app.component'; 5 | import { WelcomeComponent } from "./welcome/welcome.component"; 6 | 7 | const appRoutes: Routes = [ 8 | { path: 'app', component: WelcomeComponent }, 9 | { path: 'ships', loadChildren: './starships/starships.module#StarshipsModule' }, 10 | { path: '', redirectTo: '/app', pathMatch: 'full' }, 11 | ]; 12 | 13 | @NgModule({ 14 | imports: [ 15 | RouterModule.forRoot(appRoutes) 16 | ], 17 | exports: [ 18 | RouterModule 19 | ] 20 | }) 21 | export class AppRoutingModule {} 22 | -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntertechInc/ngrx-tutorial/f7f68b68d6f0acee52d6d6b5d0fd398e3a85b723/src/app/app.component.css -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Store } from '@ngrx/store'; 3 | 4 | import * as fromRoot from './store/reducers'; 5 | import * as authActions from './store/actions/auth.actions'; 6 | 7 | @Component({ 8 | selector: 'app-root', 9 | templateUrl: './app.component.html', 10 | styleUrls: ['./app.component.css'] 11 | }) 12 | export class AppComponent implements OnInit { 13 | title = 'app'; 14 | 15 | constructor(private store: Store) {} 16 | 17 | ngOnInit() { 18 | this.store.dispatch(new authActions.LoadAuths()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from "@angular/platform-browser"; 2 | import { NgModule } from "@angular/core"; 3 | import { HttpClientModule } from "@angular/common/http"; 4 | 5 | import { AppComponent } from "./app.component"; 6 | import { StoreModule } from "@ngrx/store"; 7 | import { reducers, metaReducers, CustomSerializer } from "./store/reducers"; 8 | import { StoreDevtoolsModule } from "@ngrx/store-devtools"; 9 | import { environment } from "../environments/environment"; 10 | import { EffectsModule } from "@ngrx/effects"; 11 | import { AuthEffects } from "./store/effects/auth.effects"; 12 | import { WelcomeComponent } from "./welcome/welcome.component"; 13 | import { AppRoutingModule } from "./app-routing.module"; 14 | import { 15 | StoreRouterConnectingModule, 16 | RouterStateSerializer 17 | } from "@ngrx/router-store"; 18 | 19 | @NgModule({ 20 | declarations: [AppComponent, WelcomeComponent], 21 | imports: [ 22 | BrowserModule, 23 | HttpClientModule, 24 | AppRoutingModule, 25 | StoreModule.forRoot(reducers, { metaReducers }), 26 | !environment.production ? StoreDevtoolsModule.instrument() : [], 27 | EffectsModule.forRoot([AuthEffects]), 28 | StoreRouterConnectingModule 29 | ], 30 | providers: [{ provide: RouterStateSerializer, useClass: CustomSerializer }], 31 | bootstrap: [AppComponent] 32 | }) 33 | export class AppModule {} 34 | -------------------------------------------------------------------------------- /src/app/models/star-ship.model.ts: -------------------------------------------------------------------------------- 1 | export class StarShip { 2 | id: number; 3 | name: string; 4 | model: string; 5 | url: string; 6 | manufacturer: string; 7 | cost_in_credits: string; 8 | length: string; 9 | crew: string; 10 | passengers: string; 11 | starship_class: string; 12 | } 13 | -------------------------------------------------------------------------------- /src/app/starships/ship-detail/ship-detail.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntertechInc/ngrx-tutorial/f7f68b68d6f0acee52d6d6b5d0fd398e3a85b723/src/app/starships/ship-detail/ship-detail.component.css -------------------------------------------------------------------------------- /src/app/starships/ship-detail/ship-detail.component.html: -------------------------------------------------------------------------------- 1 |

Ship Detail

2 |
3 |

{{(starShip$ | async).name}}

4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
Manufacturer{{(starShip$ | async).manufacturer}}
Cost In Credits{{(starShip$ | async).cost_in_credits}}
Length{{(starShip$ | async).length}}
Crew{{(starShip$ | async).crew}}
Passengers{{(starShip$ | async).passengers}}
Class{{(starShip$ | async).starship_class}}
30 |
-------------------------------------------------------------------------------- /src/app/starships/ship-detail/ship-detail.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from "@angular/core"; 2 | import { Store } from "@ngrx/store"; 3 | import { Observable } from "rxjs"; 4 | 5 | import * as fromStore from "../store/reducers"; 6 | import { StarShip } from "../../models/star-ship.model"; 7 | 8 | @Component({ 9 | selector: "app-ship-detail", 10 | templateUrl: "./ship-detail.component.html", 11 | styleUrls: ["./ship-detail.component.css"] 12 | }) 13 | export class ShipDetailComponent implements OnInit { 14 | starShip$: Observable; 15 | 16 | constructor(private store: Store) {} 17 | 18 | ngOnInit() { 19 | this.starShip$ = this.store.select(fromStore.getCurrentShip); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/app/starships/ship-list/ship-list.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntertechInc/ngrx-tutorial/f7f68b68d6f0acee52d6d6b5d0fd398e3a85b723/src/app/starships/ship-list/ship-list.component.css -------------------------------------------------------------------------------- /src/app/starships/ship-list/ship-list.component.html: -------------------------------------------------------------------------------- 1 |

{{user$ | async}}

2 |
3 |

First 10 Starships from API

4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
IDNameModel
{{ship.id}}{{ship.name}}{{ship.model}}
-------------------------------------------------------------------------------- /src/app/starships/ship-list/ship-list.component.ts: -------------------------------------------------------------------------------- 1 | import { StarShip } from "src/app/models/star-ship.model"; 2 | import { Component, OnInit } from "@angular/core"; 3 | import { Store } from "@ngrx/store"; 4 | import { Observable } from "rxjs"; 5 | 6 | import * as fromStore from "../store/reducers"; 7 | import * as fromRoot from "src/app/store/reducers"; 8 | import { LoadShips } from "../store/actions/ships.actions"; 9 | 10 | @Component({ 11 | selector: "app-ship-list", 12 | templateUrl: "./ship-list.component.html", 13 | styleUrls: ["./ship-list.component.css"] 14 | }) 15 | export class ShipListComponent implements OnInit { 16 | starships$: Observable; 17 | user$: Observable; 18 | 19 | constructor(private store: Store) {} 20 | 21 | ngOnInit() { 22 | this.starships$ = this.store.select(fromStore.getAllShipsWithId); 23 | this.user$ = this.store.select(fromRoot.getFriendlyName); 24 | 25 | this.store.dispatch(new LoadShips()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/app/starships/starships-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from "@angular/core"; 2 | import { RouterModule, Routes } from "@angular/router"; 3 | 4 | import { ShipListComponent } from "./ship-list/ship-list.component"; 5 | import { ShipDetailComponent } from "./ship-detail/ship-detail.component"; 6 | 7 | const starshipRoutes: Routes = [ 8 | { path: "", component: ShipListComponent }, 9 | { path: ":shipId/detail", component: ShipDetailComponent } 10 | ]; 11 | 12 | @NgModule({ 13 | imports: [RouterModule.forChild(starshipRoutes)], 14 | exports: [RouterModule] 15 | }) 16 | export class StarshipRoutingModule {} 17 | -------------------------------------------------------------------------------- /src/app/starships/starships.module.ts: -------------------------------------------------------------------------------- 1 | import { HttpClientModule } from '@angular/common/http'; 2 | import { NgModule } from '@angular/core'; 3 | import { CommonModule } from '@angular/common'; 4 | import { StoreModule } from '@ngrx/store'; 5 | import { EffectsModule } from '@ngrx/effects'; 6 | 7 | import * as fromShips from './store/reducers/index'; 8 | import { ShipsEffects } from './store/effects/ships.effects'; 9 | import { ShipListComponent } from './ship-list/ship-list.component'; 10 | import { StarshipRoutingModule } from './starships-routing.module'; 11 | import { ShipDetailComponent } from './ship-detail/ship-detail.component'; 12 | 13 | @NgModule({ 14 | imports: [ 15 | CommonModule, 16 | HttpClientModule, 17 | StarshipRoutingModule, 18 | StoreModule.forFeature('starships', fromShips.reducers), 19 | EffectsModule.forFeature([ShipsEffects]) 20 | ], 21 | declarations: [ShipListComponent, ShipDetailComponent] 22 | }) 23 | export class StarshipsModule { } 24 | -------------------------------------------------------------------------------- /src/app/starships/store/actions/ships.actions.ts: -------------------------------------------------------------------------------- 1 | import { StarShip } from './../../../models/star-ship.model'; 2 | import { Action } from '@ngrx/store'; 3 | 4 | export enum ShipsActionTypes { 5 | LoadShips = '[Ships] Load Ships', 6 | SetShips = '[Ships] Set Ships' 7 | } 8 | 9 | export class LoadShips implements Action { 10 | readonly type = ShipsActionTypes.LoadShips; 11 | } 12 | 13 | export class SetShips implements Action { 14 | readonly type = ShipsActionTypes.SetShips; 15 | 16 | constructor(public payload: StarShip[]) {} 17 | } 18 | 19 | export type ShipsActions = LoadShips | SetShips; 20 | -------------------------------------------------------------------------------- /src/app/starships/store/effects/ships.effects.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from "@angular/common/http"; 2 | import { Injectable } from "@angular/core"; 3 | import { Actions, Effect, ofType } from "@ngrx/effects"; 4 | import { ShipsActions, ShipsActionTypes } from "../actions/ships.actions"; 5 | import { switchMap, map } from "rxjs/operators"; 6 | import { StarShip } from "src/app/models/star-ship.model"; 7 | import * as shipActions from "src/app/starships/store/actions/ships.actions"; 8 | 9 | @Injectable() 10 | export class ShipsEffects { 11 | @Effect() 12 | loadShips$ = this.actions$.pipe( 13 | ofType(ShipsActionTypes.LoadShips), 14 | switchMap(() => { 15 | return this.http.get(`https://swapi.co/api/starships`).pipe( 16 | map(response => { 17 | return new shipActions.SetShips(response.results); 18 | }) 19 | ); 20 | }) 21 | ); 22 | 23 | constructor(private actions$: Actions, private http: HttpClient) {} 24 | } 25 | -------------------------------------------------------------------------------- /src/app/starships/store/reducers/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createSelector, 3 | createFeatureSelector, 4 | ActionReducerMap 5 | } from "@ngrx/store"; 6 | 7 | import * as fromShips from "./ships.reducer"; 8 | import * as fromRoot from "../../../store/reducers"; 9 | 10 | export interface StarshipsState { 11 | ships: fromShips.State; 12 | } 13 | 14 | export interface State extends fromRoot.State { 15 | starships: StarshipsState; 16 | } 17 | 18 | export const reducers: ActionReducerMap = { 19 | ships: fromShips.reducer 20 | }; 21 | 22 | export const selectStarshipsState = createFeatureSelector( 23 | "starships" 24 | ); 25 | 26 | export const selectShips = createSelector( 27 | selectStarshipsState, 28 | state => state.ships 29 | ); 30 | export const getAllShips = createSelector(selectShips, fromShips.getAllShips); 31 | export const getAllShipsWithId = createSelector(getAllShips, allShips => { 32 | if (allShips && allShips.length > 0) { 33 | allShips.forEach(s => { 34 | const regex = new RegExp(/.*\/(\d+)\/$/g); 35 | const match = regex.exec(s.url); 36 | if (match.length > 1) { 37 | s.id = +match[1]; 38 | } 39 | }); 40 | } 41 | return allShips; 42 | }); 43 | export const getCurrentShip = createSelector( 44 | getAllShipsWithId, 45 | fromRoot.getRouterInfo, 46 | (ships, routerInfo) => { 47 | if (ships && ships.length > 0 && routerInfo) { 48 | const id = +routerInfo.params.shipId; 49 | if (id >= 0) { 50 | return ships.find(s => s.id === id); 51 | } 52 | } 53 | 54 | return null; 55 | } 56 | ); 57 | -------------------------------------------------------------------------------- /src/app/starships/store/reducers/ships.reducer.ts: -------------------------------------------------------------------------------- 1 | import { Action } from "@ngrx/store"; 2 | import { 3 | ShipsActions, 4 | ShipsActionTypes, 5 | SetShips 6 | } from "../actions/ships.actions"; 7 | import { StarShip } from "../../../models/star-ship.model"; 8 | 9 | export interface State { 10 | allShips: StarShip[]; 11 | } 12 | 13 | const initialState: State = { 14 | allShips: [] 15 | }; 16 | 17 | export function reducer(state = initialState, action: ShipsActions): State { 18 | switch (action.type) { 19 | case ShipsActionTypes.SetShips: 20 | return handleSetShips(state, action); 21 | 22 | default: 23 | return state; 24 | } 25 | } 26 | 27 | function handleSetShips(state, action: SetShips): State { 28 | return { 29 | ...state, 30 | allShips: action.payload 31 | }; 32 | } 33 | 34 | export const getAllShips = (state: State) => state.allShips; 35 | -------------------------------------------------------------------------------- /src/app/store/actions/auth.actions.ts: -------------------------------------------------------------------------------- 1 | import { Action } from '@ngrx/store'; 2 | 3 | export enum AuthActionTypes { 4 | LoadAuths = '[Auth] Load Auths', 5 | SetAuths = '[Auth] Set Auths' 6 | } 7 | 8 | export class LoadAuths implements Action { 9 | readonly type = AuthActionTypes.LoadAuths; 10 | } 11 | 12 | export interface SetAuthsPayload { 13 | userName: string; 14 | friendlyName: string; 15 | } 16 | 17 | export class SetAuths implements Action { 18 | readonly type = AuthActionTypes.SetAuths; 19 | 20 | constructor(public payload: SetAuthsPayload) {} 21 | } 22 | 23 | export type AuthActions = LoadAuths | SetAuths; 24 | -------------------------------------------------------------------------------- /src/app/store/effects/auth.effects.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | import { Actions, Effect, ofType } from '@ngrx/effects'; 4 | import { Action } from '@ngrx/store'; 5 | import { Observable } from 'rxjs'; 6 | import { switchMap, map } from 'rxjs/operators'; 7 | 8 | import * as authActions from '../actions/auth.actions'; 9 | 10 | @Injectable() 11 | export class AuthEffects { 12 | 13 | constructor(private actions$: Actions, 14 | private http: HttpClient) {} 15 | 16 | @Effect() 17 | loadAuths$: Observable = this.actions$.pipe( 18 | ofType(authActions.AuthActionTypes.LoadAuths), 19 | switchMap(() => { 20 | return this.http.get(`https://swapi.co/api/people/1/`) 21 | .pipe( 22 | map((person) => { 23 | const name: string = person.name; 24 | return new authActions.SetAuths({ 25 | userName: name.replace(" ", ""), 26 | friendlyName: name 27 | }); 28 | }) 29 | ) 30 | }) 31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /src/app/store/reducers/auth.reducer.ts: -------------------------------------------------------------------------------- 1 | import * as authActions from '../actions/auth.actions'; 2 | 3 | export interface State { 4 | userName?: string; 5 | friendlyName?: string; 6 | } 7 | 8 | export const initialState: State = { 9 | userName: null, 10 | friendlyName: null 11 | }; 12 | 13 | export function reducer(state = initialState, action: authActions.AuthActions): State { 14 | switch (action.type) { 15 | case authActions.AuthActionTypes.SetAuths: 16 | return handleSetAuths(state, action); 17 | 18 | default: 19 | return state; 20 | } 21 | } 22 | 23 | function handleSetAuths(state: State, action: authActions.SetAuths): State { 24 | return { 25 | ...state, 26 | userName: action.payload.userName, 27 | friendlyName: action.payload.friendlyName 28 | }; 29 | } 30 | 31 | export const getUserName = (state: State) => state.userName; 32 | export const getFriendlyName = (state: State) => state.friendlyName; 33 | -------------------------------------------------------------------------------- /src/app/store/reducers/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ActionReducer, 3 | ActionReducerMap, 4 | createFeatureSelector, 5 | createSelector, 6 | MetaReducer 7 | } from "@ngrx/store"; 8 | import { 9 | StoreRouterConnectingModule, 10 | routerReducer, 11 | RouterReducerState, 12 | RouterStateSerializer 13 | } from "@ngrx/router-store"; 14 | 15 | import { environment } from "../../../environments/environment"; 16 | import * as fromAuth from "./auth.reducer"; 17 | import { Params, RouterStateSnapshot } from "@angular/router"; 18 | import { Injectable } from "@angular/core"; 19 | 20 | export interface State { 21 | auth: fromAuth.State; 22 | router: RouterReducerState; 23 | } 24 | 25 | export const reducers: ActionReducerMap = { 26 | auth: fromAuth.reducer, 27 | router: routerReducer 28 | }; 29 | 30 | export const metaReducers: MetaReducer[] = !environment.production 31 | ? [] 32 | : []; 33 | 34 | export interface RouterStateUrl { 35 | url: string; 36 | params: Params; 37 | queryParams: Params; 38 | } 39 | 40 | @Injectable() 41 | export class CustomSerializer implements RouterStateSerializer { 42 | serialize(routerState: RouterStateSnapshot): RouterStateUrl { 43 | let route = routerState.root; 44 | 45 | while (route.firstChild) { 46 | route = route.firstChild; 47 | } 48 | 49 | const { 50 | url, 51 | root: { queryParams } 52 | } = routerState; 53 | const { params } = route; 54 | 55 | // Only return an object including the URL, params and query params 56 | // instead of the entire snapshot 57 | return { url, params, queryParams }; 58 | } 59 | } 60 | // Auth selectors 61 | export const selectAuthState = createFeatureSelector("auth"); 62 | export const getUserName = createSelector( 63 | selectAuthState, 64 | fromAuth.getUserName 65 | ); 66 | export const getFriendlyName = createSelector( 67 | selectAuthState, 68 | fromAuth.getFriendlyName 69 | ); 70 | 71 | // Reducer selectors 72 | export const selectReducerState = createFeatureSelector< 73 | RouterReducerState 74 | >("router"); 75 | export const getRouterInfo = createSelector( 76 | selectReducerState, 77 | state => state.state 78 | ); 79 | -------------------------------------------------------------------------------- /src/app/welcome/welcome.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntertechInc/ngrx-tutorial/f7f68b68d6f0acee52d6d6b5d0fd398e3a85b723/src/app/welcome/welcome.component.css -------------------------------------------------------------------------------- /src/app/welcome/welcome.component.html: -------------------------------------------------------------------------------- 1 |

Welcome to the NgRx Tutorial Application, {{name$ | async}}!

2 |
3 | View Starships 4 | -------------------------------------------------------------------------------- /src/app/welcome/welcome.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { WelcomeComponent } from './welcome.component'; 4 | import { Store, StoreModule } from '@ngrx/store'; 5 | 6 | describe('WelcomeComponent', () => { 7 | let component: WelcomeComponent; 8 | let fixture: ComponentFixture; 9 | let store: Store; 10 | 11 | beforeEach(async() => { 12 | TestBed.configureTestingModule({ 13 | imports: [ StoreModule.forRoot({}) ], 14 | declarations: [ WelcomeComponent ] 15 | }); 16 | 17 | await TestBed.compileComponents(); 18 | }); 19 | 20 | beforeEach(() => { 21 | fixture = TestBed.createComponent(WelcomeComponent); 22 | component = fixture.componentInstance; 23 | store = TestBed.get(Store); 24 | 25 | spyOn(store, 'dispatch').and.callThrough(); 26 | fixture.detectChanges(); 27 | }); 28 | 29 | it('should create', () => { 30 | expect(component).toBeTruthy(); 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /src/app/welcome/welcome.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Store } from '@ngrx/store'; 3 | import { Observable } from 'rxjs'; 4 | 5 | import * as fromStore from '../store/reducers'; 6 | 7 | @Component({ 8 | selector: 'app-welcome', 9 | templateUrl: './welcome.component.html', 10 | styleUrls: ['./welcome.component.css'] 11 | }) 12 | export class WelcomeComponent implements OnInit { 13 | name$: Observable; 14 | 15 | constructor(private store: Store) { } 16 | 17 | ngOnInit() { 18 | this.name$ = this.store.select(fromStore.getFriendlyName); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntertechInc/ngrx-tutorial/f7f68b68d6f0acee52d6d6b5d0fd398e3a85b723/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/browserslist: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # For IE 9-11 support, please uncomment the last line of the file and adjust as needed 5 | > 0.5% 6 | last 2 versions 7 | Firefox ESR 8 | not dead 9 | # IE 9-11 -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build ---prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * In development mode, to ignore zone related error stack frames such as 11 | * `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can 12 | * import the following file, but please comment it out in production mode 13 | * because it will have performance impact when throw error 14 | */ 15 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 16 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntertechInc/ngrx-tutorial/f7f68b68d6f0acee52d6d6b5d0fd398e3a85b723/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NgrxTutorial 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 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-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../coverage'), 20 | reports: ['html', 'lcovonly'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; -------------------------------------------------------------------------------- /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 | .catch(err => console.log(err)); 13 | -------------------------------------------------------------------------------- /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 for the Reflect API. */ 41 | // import 'core-js/es6/reflect'; 42 | 43 | 44 | /** Evergreen browsers require these. **/ 45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. 46 | import 'core-js/es7/reflect'; 47 | 48 | 49 | /** 50 | * Web Animations `@angular/platform-browser/animations` 51 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 52 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 53 | **/ 54 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 55 | 56 | /** 57 | * By default, zone.js will patch all possible macroTask and DomEvents 58 | * user can disable parts of macroTask/DomEvents patch by setting following flags 59 | */ 60 | 61 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 62 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 63 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 64 | 65 | /* 66 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 67 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 68 | */ 69 | // (window as any).__Zone_enable_cross_context_check = true; 70 | 71 | /*************************************************************************************************** 72 | * Zone JS is required by default for Angular itself. 73 | */ 74 | import 'zone.js/dist/zone'; // Included with Angular CLI. 75 | 76 | 77 | 78 | /*************************************************************************************************** 79 | * APPLICATION IMPORTS 80 | */ 81 | -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /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/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "es2015", 6 | "types": [] 7 | }, 8 | "exclude": [ 9 | "src/test.ts", 10 | "**/*.spec.ts" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "module": "commonjs", 6 | "types": [ 7 | "jasmine", 8 | "node" 9 | ] 10 | }, 11 | "files": [ 12 | "test.ts", 13 | "polyfills.ts" 14 | ], 15 | "include": [ 16 | "**/*.spec.ts", 17 | "**/*.d.ts" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 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 | "es2017", 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 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | true, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-shadowed-variable": true, 69 | "no-string-literal": false, 70 | "no-string-throw": true, 71 | "no-switch-case-fall-through": true, 72 | "no-trailing-whitespace": true, 73 | "no-unnecessary-initializer": true, 74 | "no-unused-expression": true, 75 | "no-use-before-declare": true, 76 | "no-var-keyword": true, 77 | "object-literal-sort-keys": false, 78 | "one-line": [ 79 | true, 80 | "check-open-brace", 81 | "check-catch", 82 | "check-else", 83 | "check-whitespace" 84 | ], 85 | "prefer-const": true, 86 | "quotemark": [ 87 | true, 88 | "single" 89 | ], 90 | "radix": true, 91 | "semicolon": [ 92 | true, 93 | "always" 94 | ], 95 | "triple-equals": [ 96 | true, 97 | "allow-null-check" 98 | ], 99 | "typedef-whitespace": [ 100 | true, 101 | { 102 | "call-signature": "nospace", 103 | "index-signature": "nospace", 104 | "parameter": "nospace", 105 | "property-declaration": "nospace", 106 | "variable-declaration": "nospace" 107 | } 108 | ], 109 | "unified-signatures": true, 110 | "variable-name": false, 111 | "whitespace": [ 112 | true, 113 | "check-branch", 114 | "check-decl", 115 | "check-operator", 116 | "check-separator", 117 | "check-type" 118 | ], 119 | "no-output-on-prefix": true, 120 | "use-input-property-decorator": true, 121 | "use-output-property-decorator": true, 122 | "use-host-property-decorator": true, 123 | "no-input-rename": true, 124 | "no-output-rename": true, 125 | "use-life-cycle-interface": true, 126 | "use-pipe-transform-interface": true, 127 | "component-class-suffix": true, 128 | "directive-class-suffix": true 129 | } 130 | } 131 | --------------------------------------------------------------------------------