├── .browserslistrc ├── .editorconfig ├── .gitignore ├── .nvmrc ├── .prettierignore ├── README.md ├── angular.json ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── prettier.config.js ├── src ├── app │ ├── app.component.ts │ ├── app.module.ts │ ├── components │ │ ├── content │ │ │ └── content.component.ts │ │ ├── footer │ │ │ └── footer.component.ts │ │ ├── header │ │ │ └── header.component.ts │ │ ├── hero-badge │ │ │ └── hero-badge.component.ts │ │ ├── hero-details │ │ │ └── hero-details.component.ts │ │ └── hero-table │ │ │ ├── hero-table.component.html │ │ │ ├── hero-table.component.scss │ │ │ └── hero-table.component.ts │ └── services │ │ └── hero.service.ts ├── assets │ └── .gitkeep ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── styles │ ├── _vars.scss │ └── styles.scss └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json /.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 4 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 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events.json 15 | speed-measure-plugin.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.angular/cache 36 | /.sass-cache 37 | /connect.lock 38 | /coverage 39 | /libpeerconnection.log 40 | npm-debug.log 41 | yarn-error.log 42 | testem.log 43 | /typings 44 | 45 | # System Files 46 | .DS_Store 47 | Thumbs.db 48 | 49 | src/environments/* -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v14.18.1 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | package.json 2 | package-lock.json 3 | dist 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Reactive Angular Workshop 2 | 3 | ## What will be covered? 4 | 5 | This workshop will teach attendees how to use reactive techniques in your Angular app. It will be 6 | based heavily on RxJS. 7 | 8 | - Intermediate Reactive concepts 9 | - BehaviorSubjects 10 | - combineLatest 11 | - several new operators: pluck, map, tap, distinctUntilChanged 12 | - Intermediate Angular patterns 13 | - Intermediate TypeScript 14 | - Basic State Management 15 | - Angular Performance 16 | 17 | ## What will NOT be covered? 18 | 19 | The following topics will not be covered in this class. To be fair to all involved, any questions 20 | that dive into these topics will be deferred until breaks, until after the workshop is over, or 21 | indefinitely. 22 | 23 | - Angular Basics, or beginner Angular questions 24 | - TypeScript Basics, or beginner TypeScript questions 25 | - Reactive Basics, or anything that TOO basic around Observables 26 | 27 | ## Before you come to class 28 | 29 | In order to work on this project and go through the trainings, please do each of the following: 30 | 31 | - Install `git` on your machine. 32 | - Install node & npm 33 | - Install node v14 (or higher) 34 | - Installing node v14 automatically installs `npm` 35 | - Install latest Angular CLI . 36 | - `npm install -g @angular/cli` 37 | - Install your favorite IDE 38 | - Most people use VSCode 39 | - Frosty uses Webstorm 40 | - Clone the project 41 | - Open your Terminal/Powershell 42 | - `cd` into where you want the code 43 | - Run `git clone https://github.com/aaronfrost/reactive-angular-workshop` 44 | - Run `npm install` 45 | 46 | - `cd` into the folder you just cloned 47 | - Run `npm install` 48 | 49 | - Get APIKEY from [developer.marvel.com](https://developer.marvel.com/) 50 | - Go to [https://developer.marvel.com/](https://developer.marvel.com/) 51 | - Create a developer account 52 | - Add `localhost` to the `Your Authorized Referers` section 53 | - Add your public and private keys into `environments.ts` files 54 | - Read [Don't Unsubscribe](https://medium.com/@benlesh/rxjs-dont-unsubscribe-6753ed4fda87) blog by Ben Lesh 55 | 56 | Please do all of this before the training starts. Otherwise we will have to spend the first 57 | part of the training up and running. If there are any questions, reach out to me (Frosty) me on Twitter. 58 | 59 | ## Start Developing 60 | 61 | 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. 62 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "reactive-angular": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "style": "scss" 11 | } 12 | }, 13 | "root": "", 14 | "sourceRoot": "src", 15 | "prefix": "rx", 16 | "architect": { 17 | "build": { 18 | "builder": "@angular-devkit/build-angular:browser", 19 | "options": { 20 | "outputPath": "dist/reactive-angular", 21 | "index": "src/index.html", 22 | "main": "src/main.ts", 23 | "polyfills": "src/polyfills.ts", 24 | "tsConfig": "tsconfig.app.json", 25 | "aot": true, 26 | "assets": ["src/favicon.ico", "src/assets"], 27 | "styles": ["src/styles/styles.scss"], 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 | "namedChunks": false, 42 | "extractLicenses": true, 43 | "vendorChunk": false, 44 | "buildOptimizer": true, 45 | "budgets": [ 46 | { 47 | "type": "initial", 48 | "maximumWarning": "2mb", 49 | "maximumError": "5mb" 50 | }, 51 | { 52 | "type": "anyComponentStyle", 53 | "maximumWarning": "6kb" 54 | } 55 | ] 56 | } 57 | } 58 | }, 59 | "serve": { 60 | "builder": "@angular-devkit/build-angular:dev-server", 61 | "options": { 62 | "browserTarget": "reactive-angular:build" 63 | }, 64 | "configurations": { 65 | "production": { 66 | "browserTarget": "reactive-angular:build:production" 67 | } 68 | } 69 | }, 70 | "extract-i18n": { 71 | "builder": "@angular-devkit/build-angular:extract-i18n", 72 | "options": { 73 | "browserTarget": "reactive-angular:build" 74 | } 75 | }, 76 | "test": { 77 | "builder": "@angular-devkit/build-angular:karma", 78 | "options": { 79 | "main": "src/test.ts", 80 | "polyfills": "src/polyfills.ts", 81 | "tsConfig": "tsconfig.spec.json", 82 | "karmaConfig": "karma.conf.js", 83 | "assets": ["src/favicon.ico", "src/assets"], 84 | "styles": ["src/styles.scss"], 85 | "scripts": [] 86 | } 87 | }, 88 | "e2e": { 89 | "builder": "@angular-devkit/build-angular:protractor", 90 | "options": { 91 | "protractorConfig": "e2e/protractor.conf.js", 92 | "devServerTarget": "reactive-angular:serve" 93 | }, 94 | "configurations": { 95 | "production": { 96 | "devServerTarget": "reactive-angular:serve:production" 97 | } 98 | } 99 | } 100 | } 101 | } 102 | }, 103 | "defaultProject": "reactive-angular", 104 | "cli": { 105 | "analytics": "019cfc57-c65c-4902-a1ac-a999f70e9666" 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: ['./src/**/*.e2e-spec.ts'], 13 | capabilities: { 14 | browserName: 'chrome', 15 | }, 16 | directConnect: true, 17 | baseUrl: 'http://localhost:4200/', 18 | framework: 'jasmine', 19 | jasmineNodeOpts: { 20 | showColors: true, 21 | defaultTimeoutInterval: 30000, 22 | print: function() {}, 23 | }, 24 | onPrepare() { 25 | require('ts-node').register({ 26 | project: require('path').join(__dirname, './tsconfig.json'), 27 | }); 28 | jasmine 29 | .getEnv() 30 | .addReporter( 31 | new SpecReporter({ spec: { displayStacktrace: true } }), 32 | ); 33 | }, 34 | }; 35 | -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('Welcome to reactive-angular!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser 19 | .manage() 20 | .logs() 21 | .get(logging.Type.BROWSER); 22 | expect(logs).not.toContain( 23 | jasmine.objectContaining({ 24 | level: logging.Level.SEVERE, 25 | } as logging.Entry), 26 | ); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root h1')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es2018", 7 | "types": ["jasmine", "jasminewd2", "node"] 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /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/reactive-angular'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 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 | restartOnFileChange: true, 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "reactive-angular", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "prettier": "prettier --write \"**/*.{js,json,css,scss,less,md,ts,html,component.html}\"", 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": "~13.0.1", 16 | "@angular/common": "~13.0.1", 17 | "@angular/compiler": "~13.0.1", 18 | "@angular/core": "~13.0.1", 19 | "@angular/forms": "~13.0.1", 20 | "@angular/platform-browser": "~13.0.1", 21 | "@angular/platform-browser-dynamic": "~13.0.1", 22 | "@angular/router": "~13.0.1", 23 | "rxjs": "~6.6.3", 24 | "tslib": "^2.0.0", 25 | "zone.js": "~0.11.4" 26 | }, 27 | "devDependencies": { 28 | "@angular-devkit/build-angular": "~13.0.2", 29 | "@angular/cli": "~13.0.2", 30 | "@angular/compiler-cli": "~13.0.1", 31 | "@angular/language-service": "~13.0.1", 32 | "@types/node": "^12.11.1", 33 | "@types/jasmine": "~3.6.0", 34 | "@types/jasminewd2": "~2.0.3", 35 | "codelyzer": "^6.0.0", 36 | "husky": "3.0.5", 37 | "jasmine-core": "~3.6.0", 38 | "jasmine-spec-reporter": "~5.0.0", 39 | "karma": "~6.3.8", 40 | "karma-chrome-launcher": "~3.1.0", 41 | "karma-coverage-istanbul-reporter": "~3.0.2", 42 | "karma-jasmine": "~4.0.0", 43 | "karma-jasmine-html-reporter": "^1.5.0", 44 | "lint-staged": "9.2.5", 45 | "prettier": "1.18.2", 46 | "protractor": "~7.0.0", 47 | "ts-node": "~7.0.0", 48 | "tslint": "~6.1.0", 49 | "tslint-config-prettier": "1.18.0", 50 | "typescript": "~4.4.4" 51 | }, 52 | "husky": { 53 | "hooks": { 54 | "pre-commit": "lint-staged" 55 | } 56 | }, 57 | "lint-staged": { 58 | "*.{js,json,css,scss,less,md,ts,html,component.html}": [ 59 | "prettier --write", 60 | "git add" 61 | ] 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /prettier.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | printWidth: 80, 3 | tabWidth: 4, 4 | useTabs: false, 5 | semi: true, 6 | singleQuote: true, 7 | trailingComma: 'all', 8 | bracketSpacing: true, 9 | jsxBracketSameLine: false, 10 | arrowParens: 'avoid', 11 | rangeStart: 0, 12 | rangeEnd: Infinity, 13 | requirePragma: false, 14 | insertPragma: false, 15 | proseWrap: 'preserve', 16 | }; 17 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'rx-root', 5 | template: ` 6 | 7 | 8 | 9 | `, 10 | 11 | styles: [ 12 | ` 13 | :host { 14 | max-height: 100vh; 15 | min-height: 100vh; 16 | display: flex; 17 | flex-direction: column; 18 | align-items: stretch; 19 | } 20 | `, 21 | ], 22 | }) 23 | export class AppComponent {} 24 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { HttpClientModule } from '@angular/common/http'; 2 | import { BrowserModule } from '@angular/platform-browser'; 3 | import { NgModule } from '@angular/core'; 4 | import { RouterModule, Routes } from '@angular/router'; 5 | 6 | import { AppComponent } from './app.component'; 7 | import { ContentComponent } from './components/content/content.component'; 8 | import { FooterComponent } from './components/footer/footer.component'; 9 | import { HeaderComponent } from './components/header/header.component'; 10 | import { HeroBadgeComponent } from './components/hero-badge/hero-badge.component'; 11 | import { HeroTableComponent } from './components/hero-table/hero-table.component'; 12 | import { HeroDetailsComponent } from './components/hero-details/hero-details.component'; 13 | 14 | const routes: Routes = [ 15 | { 16 | path: '', 17 | component: HeroTableComponent, 18 | pathMatch: 'full', 19 | }, 20 | { 21 | path: 'hero/:heroId', 22 | component: HeroDetailsComponent, 23 | }, 24 | ]; 25 | 26 | @NgModule({ 27 | declarations: [ 28 | AppComponent, 29 | HeaderComponent, 30 | FooterComponent, 31 | ContentComponent, 32 | HeroTableComponent, 33 | HeroBadgeComponent, 34 | HeroDetailsComponent, 35 | ], 36 | imports: [ 37 | BrowserModule, 38 | HttpClientModule, 39 | RouterModule.forRoot(routes, { relativeLinkResolution: 'legacy' }), 40 | ], 41 | providers: [], 42 | bootstrap: [AppComponent], 43 | }) 44 | export class AppModule {} 45 | -------------------------------------------------------------------------------- /src/app/components/content/content.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'rx-content', 5 | template: ` 6 | 7 | `, 8 | styles: [ 9 | ` 10 | :host { 11 | flex-grow: 1; 12 | max-height: calc(100vh - 200px); 13 | overflow: auto; 14 | padding: 40px; 15 | background-color: var(--backcolor2); 16 | } 17 | `, 18 | ], 19 | }) 20 | export class ContentComponent implements OnInit { 21 | constructor() {} 22 | 23 | ngOnInit() {} 24 | } 25 | -------------------------------------------------------------------------------- /src/app/components/footer/footer.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'rx-footer', 5 | template: ` 6 | Reactive Angular 13 | - 14 | @aaronfrost 19 | `, 20 | styles: [ 21 | ` 22 | :host { 23 | height: 100px; 24 | background: var(--header-dark); 25 | color: whitesmoke; 26 | display: flex; 27 | flex-direction: row; 28 | justify-content: center; 29 | align-items: center; 30 | font-size: 25px; 31 | font-weight: 100; 32 | } 33 | .spacer { 34 | margin: 0px 10px; 35 | } 36 | a:visited { 37 | color: var(--header); 38 | } 39 | `, 40 | ], 41 | }) 42 | export class FooterComponent implements OnInit { 43 | constructor() {} 44 | 45 | ngOnInit() {} 46 | } 47 | -------------------------------------------------------------------------------- /src/app/components/header/header.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'rx-header', 5 | template: ` 6 |

Welcome to {{ title }}!

7 | `, 8 | styles: [ 9 | ` 10 | :host { 11 | height: 100px; 12 | background: var(--header); 13 | text-align: center; 14 | } 15 | h1 { 16 | font-size: 33px; 17 | } 18 | `, 19 | ], 20 | }) 21 | export class HeaderComponent { 22 | title = 'reactive-angular'; 23 | } 24 | -------------------------------------------------------------------------------- /src/app/components/hero-badge/hero-badge.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input, OnInit } from '@angular/core'; 2 | 3 | export const Layouts = { 4 | portrait: 'portrait', 5 | standard: 'standard', 6 | landscape: 'landscape', 7 | }; 8 | 9 | export const Sizes = { 10 | small: 'small', 11 | medium: 'medium', 12 | large: 'large', 13 | xlarge: 'xlarge', 14 | }; 15 | 16 | @Component({ 17 | selector: 'rx-hero-badge', 18 | template: ` 19 | 20 |
21 | 33 |
{{ hero.name }}
34 |
35 |
36 | `, 37 | styles: [ 38 | ` 39 | :host { 40 | display: flex; 41 | flex-direction: column; 42 | height: 140px; 43 | width: 100px; 44 | transition: opacity 250ms linear, transform 100ms linear; 45 | transform: scale(1); 46 | } 47 | :host:not(.loaded) { 48 | opacity: 0; 49 | } 50 | :host.loaded { 51 | opacity: 1; 52 | } 53 | :host:hover { 54 | transform: scale(1.05); 55 | } 56 | `, 57 | ], 58 | host: { 59 | '[class.loaded]': 'loaded', 60 | }, 61 | }) 62 | export class HeroBadgeComponent implements OnInit { 63 | @Input() hero = null; 64 | @Input() layout = Layouts.standard; 65 | @Input() size = Sizes.medium; 66 | loaded = false; 67 | 68 | constructor() {} 69 | 70 | ngOnInit() {} 71 | } 72 | -------------------------------------------------------------------------------- /src/app/components/hero-details/hero-details.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'rx-hero-details', 5 | template: ` 6 |

7 | hero-details works! 8 |

9 | `, 10 | styles: [], 11 | }) 12 | export class HeroDetailsComponent implements OnInit { 13 | constructor() {} 14 | 15 | ngOnInit(): void {} 16 | } 17 | -------------------------------------------------------------------------------- /src/app/components/hero-table/hero-table.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | 22 | 23 | 24 |
25 |
26 | 27 |
28 | -------------------------------------------------------------------------------- /src/app/components/hero-table/hero-table.component.scss: -------------------------------------------------------------------------------- 1 | .tool-bar { 2 | display: flex; 3 | flex-direction: row; 4 | height: 20px; 5 | align-items: center; 6 | justify-content: space-between; 7 | } 8 | 9 | label[for='herosearch'] { 10 | line-height: 20px; 11 | vertical-align: center; 12 | } 13 | 14 | input[name='herosearch'] { 15 | background-color: var(--backcolor2); 16 | border: 2px solid gray; 17 | border-radius: 5px; 18 | height: 100%; 19 | font-size: 18px; 20 | padding: 0 5px; 21 | margin-left: 5px; 22 | 23 | &:focus { 24 | background-color: var(--backcolor2); 25 | border: 2px solid gray; 26 | border-radius: 5px; 27 | height: 100%; 28 | box-shadow: 0 0 5px rgba(20, 20, 255, 0.8); 29 | filter: brightness(115%); 30 | outline: none; 31 | } 32 | } 33 | 34 | .tool-bar > * { 35 | margin: 0px 10px; 36 | 37 | &:first-child { 38 | margin-left: 0; 39 | } 40 | 41 | &:last-child { 42 | margin-right: 0; 43 | } 44 | } 45 | 46 | .buttons { 47 | display: flex; 48 | 49 | button { 50 | height: 30px; 51 | background: #eee; 52 | 53 | &:first-child { 54 | border-bottom-left-radius: 20px; 55 | border-top-left-radius: 20px; 56 | } 57 | &:last-child { 58 | border-bottom-right-radius: 20px; 59 | border-top-right-radius: 20px; 60 | } 61 | &:focus { 62 | outline: none; 63 | box-shadow: 0 0 5px rgba(20, 20, 255, 0.8); 64 | } 65 | 66 | &:disabled { 67 | filter: brightness(85%); 68 | } 69 | } 70 | } 71 | 72 | .table-content { 73 | margin-top: 20px; 74 | display: flex; 75 | flex-direction: row; 76 | justify-content: flex-start; 77 | flex-wrap: wrap; 78 | 79 | rx-hero-badge { 80 | margin: 10px; 81 | } 82 | } 83 | 84 | .page-tool, 85 | .result-tool, 86 | .total-tool { 87 | display: flex; 88 | flex-direction: column; 89 | width: 150px; 90 | } 91 | -------------------------------------------------------------------------------- /src/app/components/hero-table/hero-table.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Hero, HeroService } from '../../services/hero.service'; 3 | 4 | @Component({ 5 | selector: 'rx-hero-table', 6 | templateUrl: './hero-table.component.html', 7 | styleUrls: ['./hero-table.component.scss'], 8 | }) 9 | export class HeroTableComponent implements OnInit { 10 | heroes: Hero[]; 11 | 12 | constructor(public hero: HeroService) { 13 | hero.heroes$.subscribe(heroes => { 14 | this.heroes = heroes; 15 | }); 16 | } 17 | 18 | ngOnInit() {} 19 | } 20 | -------------------------------------------------------------------------------- /src/app/services/hero.service.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@angular/common/http'; 2 | import { Injectable } from '@angular/core'; 3 | import { Observable } from 'rxjs'; 4 | import { map } from 'rxjs/operators'; 5 | import { environment } from '../../environments/environment'; 6 | 7 | export interface Hero { 8 | id: number; 9 | name: string; 10 | description: string; 11 | thumbnail: HeroThumbnail; 12 | resourceURI: string; 13 | comics: HeroSubItems; 14 | events: HeroSubItems; 15 | series: HeroSubItems; 16 | stories: HeroSubItems; 17 | } 18 | 19 | export interface HeroThumbnail { 20 | path: string; 21 | extendion: string; 22 | } 23 | 24 | export interface HeroSubItems { 25 | available: number; 26 | returned: number; 27 | collectionURI: string; 28 | items: HeroSubItem[]; 29 | } 30 | 31 | export interface HeroSubItem { 32 | resourceURI: string; 33 | name: string; 34 | } 35 | 36 | // The URL to the Marvel API 37 | const HERO_API = `${environment.MARVEL_API.URL}/v1/public/characters`; 38 | 39 | // Our Limits for Search 40 | const LIMIT_LOW = 10; 41 | const LIMIT_MID = 25; 42 | const LIMIT_HIGH = 100; 43 | const LIMITS = [LIMIT_LOW, LIMIT_MID, LIMIT_HIGH]; 44 | 45 | @Injectable({ 46 | providedIn: 'root', 47 | }) 48 | export class HeroService { 49 | limits = LIMITS; 50 | 51 | heroes$: Observable = this.http 52 | .get(HERO_API, { 53 | params: { 54 | apikey: environment.MARVEL_API.PUBLIC_KEY, 55 | limit: `${LIMIT_LOW}`, 56 | // nameStartsWith: 'iron', // once we have search 57 | offset: `${0}`, // page * limit 58 | }, 59 | }) 60 | .pipe(map((res: any) => res.data.results)); 61 | 62 | constructor(private http: HttpClient) {} 63 | } 64 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aaronfrost/reactive-angular-workshop/635825da9fc4aa607b9f44fd113c84e53a46413f/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | MARVEL_API: { 4 | URL: 'https://gateway.marvel.com:443', 5 | PUBLIC_KEY: 'INSERT YOUR KEY FIRST', 6 | PRIVATE_KEY: 'INSERT YOUR KEY FIRST', 7 | }, 8 | }; 9 | 10 | if (environment.MARVEL_API.PUBLIC_KEY === 'INSERT YOUR KEY FIRST') { 11 | /** 12 | * To get access to the marvel API, you need to go to their site and sign up for an account. 13 | * Go Here: https://developer.marvel.com/ 14 | * 15 | * Once you have done that, in their portal, you will need to add http://localhost to their 16 | * whitelisted domains. If you don't do this, it will fail for you. 17 | */ 18 | document.write('INSERT YOUR KEY FIRST'); 19 | throw new Error('You must setup a public and private API key first.'); 20 | } 21 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: false, 3 | MARVEL_API: { 4 | URL: 'https://gateway.marvel.com:443', 5 | PUBLIC_KEY: 'INSERT YOUR KEY FIRST', 6 | PRIVATE_KEY: 'INSERT YOUR KEY FIRST', 7 | }, 8 | }; 9 | 10 | if (environment.MARVEL_API.PUBLIC_KEY === 'INSERT YOUR KEY FIRST') { 11 | /** 12 | * To get access to the marvel API, you need to go to their site and sign up for an account. 13 | * Go Here: https://developer.marvel.com/ 14 | * 15 | * Once you have done that, in their portal, you will need to add http://localhost to their 16 | * whitelisted domains. If you don't do this, it will fail for you. 17 | */ 18 | document.body.innerHTML = 19 | 'INSERT YOUR KEY FIRST
See environments.ts for instructions'; 20 | throw new Error('You must setup a public and private API key first.'); 21 | } 22 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aaronfrost/reactive-angular-workshop/635825da9fc4aa607b9f44fd113c84e53a46413f/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ReactiveAngular 6 | 7 | 8 | 9 | 10 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /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() 12 | .bootstrapModule(AppModule) 13 | .catch(err => console.error(err)); 14 | -------------------------------------------------------------------------------- /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/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** 22 | * By default, zone.js will patch all possible macroTask and DomEvents 23 | * user can disable parts of macroTask/DomEvents patch by setting following flags 24 | * because those flags need to be set before `zone.js` being loaded, and webpack 25 | * will put import in the top of bundle, so user need to create a separate file 26 | * in this directory (for example: zone-flags.ts), and put the following flags 27 | * into that file, and then add the following code before importing zone.js. 28 | * import './zone-flags.ts'; 29 | * 30 | * The flags allowed in zone-flags.ts are listed here. 31 | * 32 | * The following flags will work for all browsers. 33 | * 34 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 35 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 36 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 37 | * 38 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 39 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 40 | * 41 | * (window as any).__Zone_enable_cross_context_check = true; 42 | * 43 | */ 44 | 45 | /*************************************************************************************************** 46 | * Zone JS is required by default for Angular itself. 47 | */ 48 | import 'zone.js/dist/zone'; // Included with Angular CLI. 49 | 50 | /*************************************************************************************************** 51 | * APPLICATION IMPORTS 52 | */ 53 | -------------------------------------------------------------------------------- /src/styles/_vars.scss: -------------------------------------------------------------------------------- 1 | :root { 2 | // https://coolors.co/ff16dc-494947-bfc0c0-ef5d60-30343f 3 | /* RGB */ 4 | --highlight: rgba(255, 22, 220, 1); 5 | --backcolor: rgba(73, 73, 71, 1); 6 | --backcolor2: rgba(191, 192, 192, 1); 7 | --header: rgba(239, 93, 96, 1); 8 | --header-dark: rgba(48, 52, 63, 1); 9 | } 10 | -------------------------------------------------------------------------------- /src/styles/styles.scss: -------------------------------------------------------------------------------- 1 | @import './vars'; 2 | 3 | .stencil { 4 | font-family: 'Saira Stencil One', cursive; 5 | } 6 | .bungee { 7 | font-family: 'Bungee Shade', cursive; 8 | } 9 | html, 10 | body { 11 | margin: 0px; 12 | width: 100%; 13 | height: 100%; 14 | max-height: 100vh; 15 | } 16 | 17 | .background-scroll-shadows { 18 | background: 19 | /* Shadow covers */ linear-gradient( 20 | var(--backcolor2) 30%, 21 | rgba(255, 255, 255, 0) 22 | ), 23 | linear-gradient(rgba(255, 255, 255, 0), var(--backcolor2) 70%) 0 100%, 24 | /* Shadows */ 25 | radial-gradient( 26 | farthest-side at 50% 0, 27 | rgba(0, 0, 0, 0.3), 28 | rgba(0, 0, 0, 0) 29 | ), 30 | radial-gradient( 31 | farthest-side at 50% 100%, 32 | rgba(0, 0, 0, 0.3), 33 | rgba(0, 0, 0, 0) 34 | ) 35 | 0 100%; 36 | background: 37 | /* Shadow covers */ linear-gradient( 38 | var(--backcolor2) 30%, 39 | rgba(255, 255, 255, 0) 40 | ), 41 | linear-gradient(rgba(255, 255, 255, 0), var(--backcolor2) 70%) 0 100%, 42 | /* Shadows */ 43 | radial-gradient( 44 | farthest-side at 50% 0, 45 | rgba(0, 0, 0, 0.3), 46 | rgba(0, 0, 0, 0) 47 | ), 48 | radial-gradient( 49 | farthest-side at 50% 100%, 50 | rgba(0, 0, 0, 0.3), 51 | rgba(0, 0, 0, 0) 52 | ) 53 | 0 100%; 54 | background-repeat: no-repeat; 55 | background-color: var(--backcolor2); 56 | background-size: 100% 40px, 100% 40px, 100% 14px, 100% 14px; 57 | 58 | /* Opera doesn't support this in the shorthand */ 59 | background-attachment: local, local, scroll, scroll; 60 | } 61 | -------------------------------------------------------------------------------- /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 | teardown: { destroyAfterEach: false }, 18 | }, 19 | ); 20 | // Then we find all the tests. 21 | const context = require.context('./', true, /\.spec\.ts$/); 22 | // And load the modules. 23 | context.keys().map(context); 24 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": ["src/main.ts", "src/polyfills.ts"], 8 | "include": ["src/**/*.d.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "emitDecoratorMetadata": true, 10 | "experimentalDecorators": true, 11 | "module": "es2020", 12 | "moduleResolution": "node", 13 | "importHelpers": true, 14 | "target": "es2015", 15 | "typeRoots": ["node_modules/@types"], 16 | "lib": ["es2018", "dom"] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": ["jasmine", "node"] 6 | }, 7 | "files": ["src/test.ts", "src/polyfills.ts"], 8 | "include": ["src/**/*.spec.ts", "src/**/*.d.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["tslint:recommended", "tslint-config-prettier"], 3 | "rules": { 4 | "array-type": false, 5 | "arrow-parens": false, 6 | "deprecation": { 7 | "severity": "warn" 8 | }, 9 | "component-class-suffix": true, 10 | "contextual-lifecycle": true, 11 | "directive-class-suffix": true, 12 | "directive-selector": [true, "attribute", "app", "camelCase"], 13 | "component-selector": [true, "element", "app", "kebab-case"], 14 | "import-blacklist": [true, "rxjs/Rx"], 15 | "interface-name": false, 16 | "max-classes-per-file": false, 17 | "max-line-length": [true, 140], 18 | "member-access": false, 19 | "member-ordering": [ 20 | true, 21 | { 22 | "order": [ 23 | "static-field", 24 | "instance-field", 25 | "static-method", 26 | "instance-method" 27 | ] 28 | } 29 | ], 30 | "no-consecutive-blank-lines": false, 31 | "no-console": [true, "debug", "info", "time", "timeEnd", "trace"], 32 | "no-empty": false, 33 | "no-inferrable-types": [true, "ignore-params"], 34 | "no-non-null-assertion": true, 35 | "no-redundant-jsdoc": true, 36 | "no-switch-case-fall-through": true, 37 | "no-var-requires": false, 38 | "object-literal-key-quotes": [true, "as-needed"], 39 | "object-literal-sort-keys": false, 40 | "ordered-imports": false, 41 | "quotemark": [true, "single"], 42 | "trailing-comma": false, 43 | "no-conflicting-lifecycle": true, 44 | "no-host-metadata-property": true, 45 | "no-input-rename": true, 46 | "no-inputs-metadata-property": true, 47 | "no-output-native": true, 48 | "no-output-on-prefix": true, 49 | "no-output-rename": true, 50 | "no-outputs-metadata-property": true, 51 | "template-banana-in-box": true, 52 | "template-no-negated-async": true, 53 | "use-lifecycle-interface": true, 54 | "use-pipe-transform-interface": true 55 | }, 56 | "rulesDirectory": ["codelyzer"] 57 | } 58 | --------------------------------------------------------------------------------