├── .browserslistrc ├── .editorconfig ├── .gitignore ├── .nvmrc ├── .prettierrc.yml ├── README.md ├── angular.json ├── data ├── data.json ├── generate-data ├── generate.js └── routes.json ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.json ├── jestGlobalMocks.ts ├── package-lock.json ├── package.json ├── prettier.config.js ├── proxy.conf.json ├── setupJest.ts ├── src ├── app │ ├── app-routing.module.ts │ ├── app.component.html │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── core │ │ ├── components │ │ │ ├── index.ts │ │ │ └── shell │ │ │ │ ├── index.ts │ │ │ │ ├── shell.component.html │ │ │ │ ├── shell.component.scss │ │ │ │ ├── shell.component.spec.ts │ │ │ │ └── shell.component.ts │ │ ├── core.module.ts │ │ ├── enums │ │ │ ├── index.ts │ │ │ └── mode.enum.ts │ │ ├── models │ │ │ ├── customer.model.ts │ │ │ ├── index.ts │ │ │ ├── order.model.ts │ │ │ ├── product.model.ts │ │ │ └── response.model.ts │ │ ├── operators │ │ │ ├── index.ts │ │ │ ├── log.operator.ts │ │ │ ├── log.spec.ts │ │ │ ├── to-currency.operator.ts │ │ │ └── to-currency.spec.ts │ │ └── services │ │ │ ├── customer.service.spec.ts │ │ │ ├── customer.service.ts │ │ │ ├── index.ts │ │ │ └── route.service.ts │ ├── features │ │ ├── customers │ │ │ └── customers.module.ts │ │ └── home │ │ │ ├── components │ │ │ ├── index.ts │ │ │ └── index │ │ │ │ ├── index.component.html │ │ │ │ ├── index.component.scss │ │ │ │ ├── index.component.spec.ts │ │ │ │ ├── index.component.ts │ │ │ │ └── index.ts │ │ │ ├── home.module.ts │ │ │ └── index.ts │ ├── material │ │ ├── index.ts │ │ └── material.module.ts │ ├── state │ │ ├── interfaces │ │ │ ├── action.interface.ts │ │ │ └── index.ts │ │ └── settings │ │ │ ├── index.ts │ │ │ ├── settings-state.interface.ts │ │ │ ├── settings.actions.ts │ │ │ ├── settings.facade.ts │ │ │ ├── settings.service.ts │ │ │ └── settings.store.ts │ └── styles │ │ ├── _theme.scss │ │ ├── _typography.scss │ │ └── _variables.scss ├── assets │ └── .gitkeep ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts └── styles.scss ├── 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 = 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 | # 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 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 12.13.0 2 | -------------------------------------------------------------------------------- /.prettierrc.yml: -------------------------------------------------------------------------------- 1 | printWidth: 100 2 | tabWidth: 2 3 | semi: true 4 | singleQuote: true 5 | trailingComma: es5 6 | bracketSpacing: true 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Workshop Setup 4 | 5 | First, we recommend that you star this repo so you get notifications of any future updates. 6 | 7 | The required software for this workshop is: 8 | 9 | 1. Git 10 | 2. Node.js and npm 11 | 3. A clone of this repository and it's dependencies 12 | 13 | ### macOS 14 | 15 | We chose to list the macOS instructions first, but only for alphabetical reasons. 😁 16 | 17 | 1. Git should already be installed. You should verify this by opening the terminal (Applications > Utilities > Terminal) and running the following command: 18 | 19 | ```bash 20 | git --version 21 | ``` 22 | 23 | This should indicate the version of Git that is installed on your machine. 24 | 25 | 2. We recommend installing Node.js and npm using homebrew. Homebrew is a package manager for macOS, and it simplifies installing packages like node. 26 | 27 | If you do not have homebrew installed, you can install homebrew by executing the following in your terminal (Applications > Utilities > Terminal): 28 | 29 | ```bash 30 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" 31 | ``` 32 | 33 | After installing homebrew, run the following in your terminal to install the latest stable version of Node.js and npm: 34 | 35 | ```bash 36 | brew update 37 | brew install node 38 | ``` 39 | 40 | Verify that node was installed via the following command: 41 | 42 | ```bash 43 | node -v 44 | ``` 45 | 46 | Verify that npm was installed via the following command: 47 | 48 | ```bash 49 | npm -v 50 | ``` 51 | 52 | 3. Finally, clone this repository locally and install the necessary dependencies. 53 | 54 | When you run the following clone command a directory named "advanced-rxjs" will be created in your current working directory. You will need to change the current working directory in the terminal to the advanced-rxjs directory using the `cd` command: http://www.linfo.org/cd.html. 55 | 56 | ```bash 57 | git clone https://github.com/blove/advanced-rxjs.git 58 | cd advanced-rxjs 59 | npm install 60 | ``` 61 | 62 | The first command clones the repository, then we change directory into the newly created "advanced-rxjs" directory, and finally, we run the `npm install` command to install all of the necessary dependencies. 63 | 64 | ### Windows 65 | 66 | 1. Windows does not have Git installed by default. First, check if you already have the Git installed by checking your applications for "Gitbash". 67 | 68 | If the "Git Bash" application is not installed, go to [https://gitforwindows.org](https://gitforwindows.org) and download the installer. 69 | 70 | More advanced users _may_ wish to use Chocolatey, a package manager for windows, to install Git: [https://chocolatey.org/packages/git](https://chocolatey.org/packages/git). Note, if you are new to the terminal environment, and using package managers in a terminal, we do _not_ suggest you use Chocolatey. The link to gitforwindows.org above is your best bet. 71 | 72 | 2. Next, install Node version 12 from [https://nodejs.org](https://nodejs.org) 73 | 74 | 3. Finally, use the "Git Bash" application (not the native command prompt application) to clone the repository and install the necessary dependencies. When you run the following clone command a directory named "angular-fundamentals" will be created in your current working directory. If you want to change to another directory to place this folder, use the `cd` command: http://www.linfo.org/cd.html 75 | 76 | Open Git Bash and run the following commands at the prompt: 77 | 78 | ```bash 79 | git clone https://github.com/blove/advanced-rxjs.git 80 | cd advanced-rxjs 81 | npm install 82 | ``` 83 | 84 | ## Verify Installation 85 | 86 | Verify the project installation by executing the following command in the terminal on macOS or in Git Bash on Windows: 87 | 88 | ```bash 89 | npm start 90 | ``` 91 | 92 | Then open up a browser and browse to http://localhost:4200 and make sure that the website is running. 93 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "advanced-rxjs": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "style": "scss" 11 | } 12 | }, 13 | "root": "", 14 | "sourceRoot": "src", 15 | "prefix": "app", 16 | "architect": { 17 | "build": { 18 | "builder": "@angular-devkit/build-angular:browser", 19 | "options": { 20 | "outputPath": "dist/advanced-rxjs", 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": [ 27 | "src/favicon.ico", 28 | "src/assets" 29 | ], 30 | "styles": [ 31 | "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css", 32 | "src/styles.scss" 33 | ], 34 | "scripts": [] 35 | }, 36 | "configurations": { 37 | "production": { 38 | "fileReplacements": [ 39 | { 40 | "replace": "src/environments/environment.ts", 41 | "with": "src/environments/environment.prod.ts" 42 | } 43 | ], 44 | "optimization": true, 45 | "outputHashing": "all", 46 | "sourceMap": false, 47 | "extractCss": true, 48 | "namedChunks": false, 49 | "extractLicenses": true, 50 | "vendorChunk": false, 51 | "buildOptimizer": true, 52 | "budgets": [ 53 | { 54 | "type": "initial", 55 | "maximumWarning": "2mb", 56 | "maximumError": "5mb" 57 | }, 58 | { 59 | "type": "anyComponentStyle", 60 | "maximumWarning": "6kb", 61 | "maximumError": "10kb" 62 | } 63 | ] 64 | } 65 | } 66 | }, 67 | "serve": { 68 | "builder": "@angular-devkit/build-angular:dev-server", 69 | "options": { 70 | "browserTarget": "advanced-rxjs:build" 71 | }, 72 | "configurations": { 73 | "production": { 74 | "browserTarget": "advanced-rxjs:build:production" 75 | } 76 | } 77 | }, 78 | "extract-i18n": { 79 | "builder": "@angular-devkit/build-angular:extract-i18n", 80 | "options": { 81 | "browserTarget": "advanced-rxjs:build" 82 | } 83 | }, 84 | "test": { 85 | "builder": "@angular-devkit/build-angular:karma", 86 | "options": { 87 | "main": "src/test.ts", 88 | "polyfills": "src/polyfills.ts", 89 | "tsConfig": "tsconfig.spec.json", 90 | "karmaConfig": "karma.conf.js", 91 | "assets": [ 92 | "src/favicon.ico", 93 | "src/assets" 94 | ], 95 | "styles": [ 96 | "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css", 97 | "src/styles.scss" 98 | ], 99 | "scripts": [] 100 | } 101 | }, 102 | "lint": { 103 | "builder": "@angular-devkit/build-angular:tslint", 104 | "options": { 105 | "tsConfig": [ 106 | "tsconfig.app.json", 107 | "tsconfig.spec.json", 108 | "e2e/tsconfig.json" 109 | ], 110 | "exclude": [ 111 | "**/node_modules/**" 112 | ] 113 | } 114 | }, 115 | "e2e": { 116 | "builder": "@angular-devkit/build-angular:protractor", 117 | "options": { 118 | "protractorConfig": "e2e/protractor.conf.js", 119 | "devServerTarget": "advanced-rxjs:serve" 120 | }, 121 | "configurations": { 122 | "production": { 123 | "devServerTarget": "advanced-rxjs:serve:production" 124 | } 125 | } 126 | } 127 | } 128 | } 129 | }, 130 | "defaultProject": "advanced-rxjs" 131 | } -------------------------------------------------------------------------------- /data/generate-data: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | 6 | const DATA_PATH = path.resolve(__dirname, './data.json'); 7 | 8 | async function generate() { 9 | const data = require('./generate.js')(); 10 | await new Promise((resolve, reject) => { 11 | fs.writeFile(DATA_PATH, JSON.stringify(data), error => { 12 | if (error) { 13 | reject(error); 14 | return; 15 | } 16 | resolve(); 17 | }); 18 | }); 19 | } 20 | 21 | module.exports = generate; 22 | 23 | if (require.main === module) { 24 | function main() { 25 | generate().then(() => process.exit(0)); 26 | } 27 | 28 | main(); 29 | } 30 | -------------------------------------------------------------------------------- /data/generate.js: -------------------------------------------------------------------------------- 1 | function getRandomInt(max) { 2 | return Math.floor(Math.random() * Math.floor(max)); 3 | } 4 | 5 | module.exports = () => { 6 | const data = { 7 | customers: [], 8 | accounts: [], 9 | products: [], 10 | orders: [], 11 | orderItems: [] 12 | }; 13 | 14 | const faker = require('faker'); 15 | 16 | for (let customer = 0; customer < 500; customer++) { 17 | const id = data.customers.length + 1; 18 | data.customers.push({ 19 | id, 20 | name: faker.company.companyName(), 21 | catchPhrase: faker.company.catchPhrase(), 22 | avatar: faker.image.avatar(), 23 | address: { 24 | street1: faker.address.streetName(), 25 | city: faker.address.city(), 26 | state: faker.address.state(), 27 | zip: faker.address.zipCode() 28 | } 29 | }); 30 | for (let account = 0; account < getRandomInt(3) + 1; account++) { 31 | data.accounts.push({ 32 | id: data.accounts.length + 1, 33 | customerId: id, 34 | accountNumber: faker.finance.account(), 35 | name: faker.finance.accountName(), 36 | amount: faker.finance.amount() 37 | }); 38 | } 39 | } 40 | 41 | for (let product = 0; product < 200; product++) { 42 | data.products.push({ 43 | id: data.products.length + 1, 44 | name: faker.commerce.productName(), 45 | price: faker.commerce.price(), 46 | color: faker.commerce.color(), 47 | details: faker.commerce.productAdjective(), 48 | imageUrl: faker.image.imageUrl() 49 | }); 50 | } 51 | 52 | for (let order = 0; order < 50; order++) { 53 | const account = data.accounts[getRandomInt(data.accounts.length)]; 54 | const id = data.orders.length + 1; 55 | data.orders.push({ 56 | id, 57 | accountId: account.id, 58 | customerId: account.customerId, 59 | dateOfOrder: 60 | order < 25 && order % 2 === 0 61 | ? faker.date.past() 62 | : order < 75 63 | ? faker.date.recent() 64 | : faker.date.future() 65 | }); 66 | 67 | for (let orderItem = 0; orderItem < getRandomInt(10) + 2; orderItem++) { 68 | const product = data.products[getRandomInt(data.products.length)]; 69 | 70 | data.orderItems.push({ 71 | orderId: id, 72 | productId: product.id, 73 | quantity: getRandomInt(4) + 1 74 | }); 75 | } 76 | } 77 | 78 | return data; 79 | }; 80 | -------------------------------------------------------------------------------- /data/routes.json: -------------------------------------------------------------------------------- 1 | { 2 | "/api/*": "/$1" 3 | } 4 | -------------------------------------------------------------------------------- /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: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /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('advanced-rxjs app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo(): Promise { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText(): Promise { 9 | return element(by.css('app-root .content span')).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": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jestGlobalMocks.ts: -------------------------------------------------------------------------------- 1 | Object.defineProperty(window, 'CSS', { value: null }); 2 | Object.defineProperty(document, 'doctype', { 3 | value: '', 4 | }); 5 | Object.defineProperty(window, 'getComputedStyle', { 6 | value: () => { 7 | return { 8 | display: 'none', 9 | appearance: ['-webkit-appearance'], 10 | }; 11 | }, 12 | }); 13 | /** 14 | * ISSUE: https://github.com/angular/material2/issues/7101 15 | * Workaround for JSDOM missing transform property 16 | */ 17 | Object.defineProperty(document.body.style, 'transform', { 18 | value: () => { 19 | return { 20 | enumerable: true, 21 | configurable: true, 22 | }; 23 | }, 24 | }); 25 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "advanced-rxjs", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "concurrently --prefix-colors white.bgRed,white.bgBlue --names angular,json-server --kill-others \"npm run serve:proxy\" \"npm run serve:server\"", 7 | "serve": "ng serve --source-map", 8 | "serve:proxy": "ng serve --source-map --proxy-config proxy.conf.json", 9 | "serve:server": "json-server --watch data/data.json --routes data/routes.json", 10 | "build": "ng build", 11 | "test": "jest", 12 | "test:coverage": "jest --coverage", 13 | "test:watch": "jest --watch", 14 | "lint": "ng lint", 15 | "e2e": "ng e2e" 16 | }, 17 | "private": true, 18 | "engines": { 19 | "node": ">=10.9.0 <13.0.0", 20 | "yarn": ">=1.22.4 <2" 21 | }, 22 | "dependencies": { 23 | "@angular/animations": "~10.2.1", 24 | "@angular/cdk": "^10.2.6", 25 | "@angular/common": "~10.2.1", 26 | "@angular/compiler": "~10.2.1", 27 | "@angular/core": "~10.2.1", 28 | "@angular/forms": "~10.2.1", 29 | "@angular/material": "^10.2.6", 30 | "@angular/platform-browser": "~10.2.1", 31 | "@angular/platform-browser-dynamic": "~10.2.1", 32 | "@angular/router": "~10.2.1", 33 | "concurrently": "^5.1.0", 34 | "json-server": "^0.16.1", 35 | "rxjs": "~6.5.4", 36 | "tslib": "^2.0.0", 37 | "zone.js": "~0.10.3" 38 | }, 39 | "devDependencies": { 40 | "@angular-devkit/build-angular": "~0.1002.0", 41 | "@angular/cli": "~10.2.0", 42 | "@angular/compiler-cli": "~10.2.1", 43 | "@angular/language-service": "~10.2.1", 44 | "@types/jasmine": "~3.5.0", 45 | "@types/jasminewd2": "~2.0.3", 46 | "@types/jest": "^26.0.15", 47 | "@types/node": "^12.11.1", 48 | "codelyzer": "^5.1.2", 49 | "faker": "^4.1.0", 50 | "husky": "^4.2.3", 51 | "jasmine-core": "~3.5.0", 52 | "jasmine-spec-reporter": "~5.0.0", 53 | "jest": "^26.6.1", 54 | "jest-preset-angular": "^8.3.2", 55 | "karma": "~5.0.0", 56 | "karma-chrome-launcher": "~3.1.0", 57 | "karma-coverage-istanbul-reporter": "~3.0.2", 58 | "karma-jasmine": "~4.0.0", 59 | "karma-jasmine-html-reporter": "^1.5.0", 60 | "lint-staged": "^10.5.1", 61 | "prettier": "^1.19.1", 62 | "protractor": "~7.0.0", 63 | "ts-node": "~8.3.0", 64 | "tslint": "~6.1.0", 65 | "typescript": "~4.0.5" 66 | }, 67 | "husky": { 68 | "hooks": { 69 | "pre-commit": "lint-staged" 70 | } 71 | }, 72 | "jest": { 73 | "preset": "jest-preset-angular", 74 | "setupFilesAfterEnv": [ 75 | "/setupJest.ts" 76 | ], 77 | "moduleNameMapper": { 78 | "^@app-core/(.*)$": "/src/app/core/$1", 79 | "^@app-features/(.*)$": "/src/app/features/$1", 80 | "^@app-state/(.*)$": "/src/app/state/$1" 81 | } 82 | }, 83 | "lint-staged": { 84 | "*.{js,json,css,md,ts,html,component.html}": [ 85 | "prettier --config ./prettier.config.js --write" 86 | ] 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /prettier.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | printWidth: 100, 3 | tabWidth: 2, 4 | useTabs: false, 5 | semi: true, 6 | singleQuote: true, 7 | trailingComma: 'none', 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 | -------------------------------------------------------------------------------- /proxy.conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "/api": { 3 | "target": "http://localhost:3000", 4 | "secure": false 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /setupJest.ts: -------------------------------------------------------------------------------- 1 | import 'jest-preset-angular'; 2 | 3 | import './jestGlobalMocks'; 4 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { RouteService } from '@app-core/services/route.service'; 4 | import { IndexComponent } from '@app-features/home'; 5 | 6 | const routes: Routes = [ 7 | { 8 | path: '', 9 | pathMatch: 'full', 10 | redirectTo: '/home', 11 | }, 12 | { 13 | path: 'users', 14 | loadChildren: () => 15 | import('./features/customers/customers.module').then( 16 | ({ CustomersModule }) => CustomersModule 17 | ), 18 | }, 19 | RouteService.withShell([ 20 | { 21 | path: 'home', 22 | component: IndexComponent, 23 | }, 24 | ]), 25 | ]; 26 | 27 | @NgModule({ 28 | imports: [RouterModule.forRoot(routes)], 29 | exports: [RouterModule], 30 | }) 31 | export class AppRoutingModule {} 32 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, waitForAsync } from "@angular/core/testing"; 2 | import { RouterTestingModule } from "@angular/router/testing"; 3 | 4 | import { AppComponent } from "./app.component"; 5 | 6 | describe("AppComponent", () => { 7 | beforeEach( 8 | waitForAsync(() => { 9 | TestBed.configureTestingModule({ 10 | imports: [RouterTestingModule], 11 | declarations: [AppComponent] 12 | }).compileComponents(); 13 | }) 14 | ); 15 | 16 | it("should create the app", () => { 17 | const fixture = TestBed.createComponent(AppComponent); 18 | const app = fixture.componentInstance; 19 | expect(app).toBeTruthy(); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | }) 7 | export class AppComponent {} 8 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { BrowserModule } from '@angular/platform-browser'; 3 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 4 | import { CoreModule } from '@app-core/core.module'; 5 | import { HomeModule } from '@app-features/home/home.module'; 6 | 7 | import { AppRoutingModule } from './app-routing.module'; 8 | import { AppComponent } from './app.component'; 9 | 10 | @NgModule({ 11 | declarations: [AppComponent], 12 | imports: [BrowserModule, AppRoutingModule, BrowserAnimationsModule, CoreModule, HomeModule], 13 | bootstrap: [AppComponent], 14 | }) 15 | export class AppModule {} 16 | -------------------------------------------------------------------------------- /src/app/core/components/index.ts: -------------------------------------------------------------------------------- 1 | export * from './shell'; 2 | -------------------------------------------------------------------------------- /src/app/core/components/shell/index.ts: -------------------------------------------------------------------------------- 1 | export * from './shell.component'; 2 | -------------------------------------------------------------------------------- /src/app/core/components/shell/shell.component.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | Advanced RxJS 7 | 8 | 9 | 10 | 11 | settings 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 |
21 | 28 |
29 | -------------------------------------------------------------------------------- /src/app/core/components/shell/shell.component.scss: -------------------------------------------------------------------------------- 1 | @import '~@angular/material/theming'; 2 | @import '../../../styles/variables'; 3 | 4 | mat-toolbar { 5 | justify-content: space-between; 6 | position: fixed; 7 | top: 0; 8 | left: 0; 9 | right: 0; 10 | z-index: 2; 11 | 12 | a.primary { 13 | color: mat-color($mat-deep-orange, 500); 14 | text-decoration: none; 15 | display: flex; 16 | margin: 0 20px; 17 | 18 | .logo { 19 | height: 20px; 20 | } 21 | } 22 | 23 | .spacer { 24 | flex: auto; 25 | } 26 | } 27 | 28 | .shell { 29 | min-height: 100%; 30 | width: 100%; 31 | text-align: left; 32 | display: flex; 33 | flex-direction: column; 34 | flex: 1; 35 | box-sizing: border-box; 36 | padding-top: 64px; 37 | overflow-y: auto; 38 | 39 | .content { 40 | width: 100%; 41 | max-width: 1250px; 42 | margin: 0 auto; 43 | padding: 20px 0; 44 | flex: 1 1 auto; 45 | } 46 | 47 | footer { 48 | padding: 12px; 49 | font-size: 12px; 50 | margin-top: 40px; 51 | display: flex; 52 | flex-direction: row; 53 | justify-content: space-between; 54 | align-items: center; 55 | border-top: 1px solid mat-color($mat-gray, 400); 56 | 57 | a:hover { 58 | text-decoration: underline; 59 | text-decoration-color: mat-color($mat-deep-orange, 500); 60 | } 61 | 62 | .made-by, 63 | .spacer, 64 | .copyright { 65 | display: flex; 66 | } 67 | 68 | .made-by { 69 | display: none; 70 | } 71 | 72 | .spacer { 73 | flex: 1; 74 | } 75 | 76 | .copyright { 77 | flex-direction: column; 78 | width: 100%; 79 | text-align: center; 80 | } 81 | } 82 | 83 | @media screen and ($gt-xsmall) and ($lt-medium) { 84 | footer { 85 | .made-by { 86 | display: flex; 87 | } 88 | 89 | .copyright { 90 | width: inherit; 91 | text-align: left; 92 | } 93 | } 94 | } 95 | 96 | @media screen and (min-width: 960px) { 97 | footer { 98 | .made-by { 99 | display: flex; 100 | } 101 | 102 | .copyright { 103 | width: inherit; 104 | text-align: left; 105 | } 106 | } 107 | } 108 | } 109 | 110 | ::ng-deep .dark { 111 | .shell { 112 | footer { 113 | color: rgba(255, 255, 255, 0.75) !important; 114 | 115 | a { 116 | color: rgba(255, 255, 255, 0.75) !important; 117 | } 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/app/core/components/shell/shell.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing"; 2 | import { RouterTestingModule } from "@angular/router/testing"; 3 | 4 | import { MaterialModule } from "../../../material"; 5 | import { ShellComponent } from "./shell.component"; 6 | 7 | describe("ShellComponent", () => { 8 | let component: ShellComponent; 9 | let fixture: ComponentFixture; 10 | 11 | beforeEach( 12 | waitForAsync(() => { 13 | TestBed.configureTestingModule({ 14 | declarations: [ShellComponent], 15 | imports: [MaterialModule, RouterTestingModule] 16 | }).compileComponents(); 17 | }) 18 | ); 19 | 20 | beforeEach(() => { 21 | fixture = TestBed.createComponent(ShellComponent); 22 | component = fixture.componentInstance; 23 | fixture.detectChanges(); 24 | }); 25 | 26 | it("should create", () => { 27 | expect(component).toBeTruthy(); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /src/app/core/components/shell/shell.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Inject } from '@angular/core'; 2 | import { MatDialog } from '@angular/material/dialog'; 3 | import { Mode } from '@app-core/enums'; 4 | import { SettingsFacade } from '@app-state/settings'; 5 | import { Observable } from 'rxjs'; 6 | import { DOCUMENT } from '@angular/common'; 7 | import { tap } from 'rxjs/operators'; 8 | 9 | @Component({ 10 | selector: 'app-shell', 11 | templateUrl: './shell.component.html', 12 | styleUrls: ['./shell.component.scss'], 13 | }) 14 | export class ShellComponent { 15 | /** An enum of possible application modes. */ 16 | Mode = Mode; 17 | 18 | /** The application display mode. */ 19 | mode: Observable = this.settingsFacade.mode$.pipe( 20 | tap(mode => { 21 | if (this.document.body) { 22 | this.document.body.classList.remove(Mode.Dark); 23 | this.document.body.classList.remove(Mode.Light); 24 | this.document.body.classList.add(mode); 25 | } 26 | }) 27 | ); 28 | 29 | constructor( 30 | @Inject(DOCUMENT) private readonly document: Document, 31 | private readonly matDialog: MatDialog, 32 | private readonly settingsFacade: SettingsFacade 33 | ) {} 34 | 35 | onDarkMode(): void { 36 | this.settingsFacade.setMode(Mode.Dark); 37 | } 38 | 39 | onLightMode(): void { 40 | this.settingsFacade.setMode(Mode.Light); 41 | } 42 | 43 | onToggleMenu(): void { 44 | // this.matDialog.open(MenuDialogComponent); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/app/core/core.module.ts: -------------------------------------------------------------------------------- 1 | import { CommonModule } from '@angular/common'; 2 | import { NgModule } from '@angular/core'; 3 | import { RouterModule } from '@angular/router'; 4 | 5 | import { MaterialModule } from '../material'; 6 | import { ShellComponent } from './components'; 7 | 8 | const directives = [ShellComponent]; 9 | 10 | @NgModule({ 11 | declarations: [...directives], 12 | imports: [CommonModule, MaterialModule, RouterModule], 13 | }) 14 | export class CoreModule {} 15 | -------------------------------------------------------------------------------- /src/app/core/enums/index.ts: -------------------------------------------------------------------------------- 1 | export * from './mode.enum'; 2 | -------------------------------------------------------------------------------- /src/app/core/enums/mode.enum.ts: -------------------------------------------------------------------------------- 1 | export enum Mode { 2 | Dark = 'dark', 3 | Light = 'light', 4 | } 5 | -------------------------------------------------------------------------------- /src/app/core/models/customer.model.ts: -------------------------------------------------------------------------------- 1 | export interface Customer { 2 | id: number; 3 | name: string; 4 | catchPhrase: string; 5 | address: { 6 | street1: string; 7 | city: string; 8 | state: string; 9 | zip: string; 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /src/app/core/models/index.ts: -------------------------------------------------------------------------------- 1 | export * from './customer.model'; 2 | export * from './order.model'; 3 | export * from './product.model'; 4 | export * from './response.model'; 5 | -------------------------------------------------------------------------------- /src/app/core/models/order.model.ts: -------------------------------------------------------------------------------- 1 | export interface Order { 2 | id: number; 3 | accountId: number; 4 | customerId: number; 5 | dateOfOrder: string; 6 | } 7 | -------------------------------------------------------------------------------- /src/app/core/models/product.model.ts: -------------------------------------------------------------------------------- 1 | export interface Product { 2 | id: number; 3 | name: string; 4 | price: string; 5 | color: string; 6 | details: string; 7 | } 8 | -------------------------------------------------------------------------------- /src/app/core/models/response.model.ts: -------------------------------------------------------------------------------- 1 | export interface Response { 2 | page: number; 3 | per_page: number; 4 | total: number; 5 | total_pages: number; 6 | data: T[]; 7 | } 8 | -------------------------------------------------------------------------------- /src/app/core/operators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './log.operator'; 2 | export * from './to-currency.operator'; 3 | -------------------------------------------------------------------------------- /src/app/core/operators/log.operator.ts: -------------------------------------------------------------------------------- 1 | import { Observable } from 'rxjs'; 2 | import { tap } from 'rxjs/operators'; 3 | 4 | export function log() { 5 | return (source: Observable) => source.pipe(tap(console.log)); 6 | } 7 | -------------------------------------------------------------------------------- /src/app/core/operators/log.spec.ts: -------------------------------------------------------------------------------- 1 | import { Observable, Subscription, of } from 'rxjs'; 2 | 3 | import { log } from './log.operator'; 4 | 5 | describe('log', () => { 6 | let subscription: Subscription; 7 | 8 | afterEach(() => { 9 | subscription.unsubscribe(); 10 | }); 11 | 12 | test('it should log a next notification', () => { 13 | const message = 'test'; 14 | const spy = jest.spyOn(console, 'log'); 15 | const observable: Observable = of(message).pipe(log()); 16 | subscription = observable.subscribe(); 17 | expect(spy).toHaveBeenCalledWith(message); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /src/app/core/operators/to-currency.operator.ts: -------------------------------------------------------------------------------- 1 | import { Observable } from 'rxjs'; 2 | 3 | export const toCurrency = (precision: number) => (source$: Observable) => 4 | new Observable(observer => 5 | source$.subscribe({ 6 | next: value => { 7 | try { 8 | observer.next(Number((Math.round(Number(value) * 100) / 100).toFixed(precision))); 9 | } catch (error) { 10 | observer.error(error); 11 | } 12 | }, 13 | error: e => observer.error(e), 14 | complete: () => observer.complete(), 15 | }) 16 | ); 17 | -------------------------------------------------------------------------------- /src/app/core/operators/to-currency.spec.ts: -------------------------------------------------------------------------------- 1 | import { of } from 'rxjs'; 2 | import { TestScheduler } from 'rxjs/testing'; 3 | 4 | import { toCurrency } from './to-currency.operator'; 5 | 6 | describe('toCurrency', () => { 7 | let scheduler: TestScheduler; 8 | 9 | beforeEach(() => { 10 | scheduler = new TestScheduler((actual, expected) => { 11 | expect(actual).toEqual(expected); 12 | }); 13 | }); 14 | 15 | test('it should round up', () => { 16 | const value = '1234.009'; 17 | const expected = 1234.01; 18 | const precision = 2; 19 | scheduler.run(({ expectObservable }) => { 20 | const stream = '(a|)'; 21 | const values = { a: expected }; 22 | const source$ = of(value).pipe(toCurrency(precision)); 23 | expectObservable(source$).toBe(stream, values); 24 | }); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /src/app/core/services/customer.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { HttpClientTestingModule } from '@angular/common/http/testing'; 2 | import { TestBed } from '@angular/core/testing'; 3 | 4 | import { CustomerService } from './customer.service'; 5 | 6 | describe('CustomerService', () => { 7 | beforeEach(() => 8 | TestBed.configureTestingModule({ 9 | imports: [HttpClientTestingModule], 10 | }) 11 | ); 12 | 13 | it('should be created', () => { 14 | const service: CustomerService = TestBed.inject(CustomerService); 15 | expect(service).toBeTruthy(); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/app/core/services/customer.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 | 6 | import { environment } from '../../../environments/environment'; 7 | import { Customer } from '../models'; 8 | 9 | @Injectable({ 10 | providedIn: 'root', 11 | }) 12 | export class CustomerService { 13 | constructor(private readonly httpClient: HttpClient) {} 14 | 15 | fetch(): Observable { 16 | return this.httpClient.get(`${environment.apiBaseUrl}/customers`); 17 | } 18 | 19 | paginate(page = 1, limit = 20): Observable { 20 | return this.httpClient.get( 21 | `${environment.apiBaseUrl}/customers?_page=${page}&_limit=${limit}` 22 | ); 23 | } 24 | 25 | slice(start: number, end: number): Observable<{ customers: Customer[]; totalCount: number }> { 26 | return this.httpClient 27 | .get(`${environment.apiBaseUrl}/customers?_start=${start}&_end=${end}`, { 28 | observe: 'response', 29 | }) 30 | .pipe( 31 | map(response => ({ 32 | customers: response.body, 33 | totalCount: Number(response.headers.get('X-Total-Count')), 34 | })) 35 | ); 36 | } 37 | 38 | update(id: number, changes: Partial) { 39 | return this.httpClient.put(`${environment.apiBaseUrl}/customers/${id}`, changes); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/app/core/services/index.ts: -------------------------------------------------------------------------------- 1 | export * from './customer.service'; 2 | -------------------------------------------------------------------------------- /src/app/core/services/route.service.ts: -------------------------------------------------------------------------------- 1 | import { Routes } from '@angular/router'; 2 | 3 | import { ShellComponent } from '../components'; 4 | 5 | const defaultData = { 6 | reuse: true, 7 | }; 8 | 9 | export class RouteService { 10 | static withShell(routes: Routes, data: any = defaultData) { 11 | return { 12 | path: '', 13 | component: ShellComponent, 14 | children: routes, 15 | data, 16 | }; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/app/features/customers/customers.module.ts: -------------------------------------------------------------------------------- 1 | import { CommonModule } from '@angular/common'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | @NgModule({ 5 | declarations: [], 6 | imports: [CommonModule], 7 | }) 8 | export class CustomersModule {} 9 | -------------------------------------------------------------------------------- /src/app/features/home/components/index.ts: -------------------------------------------------------------------------------- 1 | export * from './index/index'; 2 | -------------------------------------------------------------------------------- /src/app/features/home/components/index/index.component.html: -------------------------------------------------------------------------------- 1 |

Welcome 👋

2 |

Advanced RxJS Workshop

3 | -------------------------------------------------------------------------------- /src/app/features/home/components/index/index.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blove/advanced-rxjs/a0ea96f36cc5eaa71b739fe51246199cd44febb4/src/app/features/home/components/index/index.component.scss -------------------------------------------------------------------------------- /src/app/features/home/components/index/index.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing"; 2 | 3 | import { IndexComponent } from "./index.component"; 4 | 5 | describe("IndexComponent", () => { 6 | let component: IndexComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach( 10 | waitForAsync(() => { 11 | TestBed.configureTestingModule({ 12 | declarations: [IndexComponent] 13 | }).compileComponents(); 14 | }) 15 | ); 16 | 17 | beforeEach(() => { 18 | fixture = TestBed.createComponent(IndexComponent); 19 | component = fixture.componentInstance; 20 | fixture.detectChanges(); 21 | }); 22 | 23 | it("should create", () => { 24 | expect(component).toBeTruthy(); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /src/app/features/home/components/index/index.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-index', 5 | templateUrl: './index.component.html', 6 | styleUrls: ['./index.component.scss'], 7 | }) 8 | export class IndexComponent {} 9 | -------------------------------------------------------------------------------- /src/app/features/home/components/index/index.ts: -------------------------------------------------------------------------------- 1 | export * from './index.component'; 2 | -------------------------------------------------------------------------------- /src/app/features/home/home.module.ts: -------------------------------------------------------------------------------- 1 | import { CommonModule } from '@angular/common'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { IndexComponent } from './components'; 5 | 6 | const directives = [IndexComponent]; 7 | 8 | @NgModule({ 9 | declarations: [...directives], 10 | imports: [CommonModule], 11 | exports: [...directives], 12 | }) 13 | export class HomeModule {} 14 | -------------------------------------------------------------------------------- /src/app/features/home/index.ts: -------------------------------------------------------------------------------- 1 | export * from './components'; 2 | -------------------------------------------------------------------------------- /src/app/material/index.ts: -------------------------------------------------------------------------------- 1 | export * from './material.module'; 2 | -------------------------------------------------------------------------------- /src/app/material/material.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { MatButtonModule } from '@angular/material/button'; 3 | import { MAT_DIALOG_DEFAULT_OPTIONS, MatDialogModule } from '@angular/material/dialog'; 4 | import { MatFormFieldModule } from '@angular/material/form-field'; 5 | import { MatIconModule } from '@angular/material/icon'; 6 | import { MatInputModule } from '@angular/material/input'; 7 | import { MatMenuModule } from '@angular/material/menu'; 8 | import { MatSelectModule } from '@angular/material/select'; 9 | import { MatSidenavModule } from '@angular/material/sidenav'; 10 | import { MatToolbarModule } from '@angular/material/toolbar'; 11 | 12 | const modules = [ 13 | MatButtonModule, 14 | MatDialogModule, 15 | MatFormFieldModule, 16 | MatIconModule, 17 | MatInputModule, 18 | MatMenuModule, 19 | MatSelectModule, 20 | MatSidenavModule, 21 | MatToolbarModule, 22 | ]; 23 | 24 | @NgModule({ 25 | imports: [...modules], 26 | exports: [...modules], 27 | providers: [ 28 | { 29 | provide: MAT_DIALOG_DEFAULT_OPTIONS, 30 | useValue: { panelClass: 'lkt-mat-dialog-overlay-pane' }, 31 | }, 32 | ], 33 | }) 34 | export class MaterialModule {} 35 | -------------------------------------------------------------------------------- /src/app/state/interfaces/action.interface.ts: -------------------------------------------------------------------------------- 1 | export interface Action { 2 | type: string; 3 | payload?: any; 4 | } 5 | -------------------------------------------------------------------------------- /src/app/state/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './action.interface'; 2 | -------------------------------------------------------------------------------- /src/app/state/settings/index.ts: -------------------------------------------------------------------------------- 1 | export * from './settings.facade'; 2 | -------------------------------------------------------------------------------- /src/app/state/settings/settings-state.interface.ts: -------------------------------------------------------------------------------- 1 | import { Mode } from '@app-core/enums'; 2 | 3 | export interface SettingsState { 4 | mode: Mode; 5 | } 6 | -------------------------------------------------------------------------------- /src/app/state/settings/settings.actions.ts: -------------------------------------------------------------------------------- 1 | import { Mode } from '@app-core/enums'; 2 | 3 | import { Action } from '../interfaces'; 4 | 5 | export class SetMode implements Action { 6 | readonly type = 'SET_MODE'; 7 | constructor(public payload: { mode: Mode }) {} 8 | } 9 | 10 | export type Actions = SetMode; 11 | -------------------------------------------------------------------------------- /src/app/state/settings/settings.facade.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Mode } from '@app-core/enums'; 3 | import { distinctUntilKeyChanged, pluck } from 'rxjs/operators'; 4 | 5 | import { SetMode } from './settings.actions'; 6 | import { SettingsService } from './settings.service'; 7 | import { dispatch, store$ } from './settings.store'; 8 | 9 | @Injectable({ 10 | providedIn: 'root', 11 | }) 12 | export class SettingsFacade { 13 | // RxJS + redux pattern 14 | mode$ = store$.pipe(distinctUntilKeyChanged('mode'), pluck('mode')); 15 | 16 | // RxJS + BehaviorSubject 17 | // mode$ = this.settingsService.settings$.pipe(distinctUntilKeyChanged('mode'), pluck('mode')); 18 | 19 | constructor(private readonly settingsService: SettingsService) {} 20 | 21 | // RxJS + redux pattern 22 | setMode(mode: Mode): void { 23 | dispatch(new SetMode({ mode })); 24 | } 25 | 26 | // RxJS + BehaviorSubject 27 | // setMode(mode: Mode): void { 28 | // this.settingsService.setMode(mode); 29 | // } 30 | } 31 | -------------------------------------------------------------------------------- /src/app/state/settings/settings.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Mode } from '@app-core/enums'; 3 | import { BehaviorSubject } from 'rxjs'; 4 | 5 | import { SettingsState } from './settings-state.interface'; 6 | 7 | // The initial settings state 8 | const initialState: SettingsState = { mode: Mode.Light }; 9 | 10 | @Injectable({ 11 | providedIn: 'root', 12 | }) 13 | export class SettingsService { 14 | /** Multicasting subject with initial state. */ 15 | private readonly settings = new BehaviorSubject(initialState); 16 | 17 | /** Settings observable. */ 18 | settings$ = this.settings.asObservable(); 19 | 20 | setMode(mode: Mode): void { 21 | this.settings.next({ ...this.settings.value, mode }); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/app/state/settings/settings.store.ts: -------------------------------------------------------------------------------- 1 | import { Mode } from '@app-core/enums'; 2 | import { log } from '@app-core/operators'; 3 | import { Observable, Subject } from 'rxjs'; 4 | import { scan, startWith, tap } from 'rxjs/operators'; 5 | 6 | import { Action } from '../interfaces'; 7 | import { SettingsState } from './settings-state.interface'; 8 | import { Actions } from './settings.actions'; 9 | 10 | // Settings state stream 11 | const action$ = new Subject(); 12 | 13 | // The initial settings state 14 | const initialState: SettingsState = { mode: Mode.Light }; 15 | 16 | // Pure function reducer 17 | const reducer = (state: SettingsState, action: Actions): SettingsState => { 18 | switch (action.type) { 19 | case 'SET_MODE': 20 | return { 21 | ...state, 22 | mode: action.payload.mode, 23 | }; 24 | default: 25 | return state; 26 | } 27 | }; 28 | 29 | // Simple store 30 | export const store$: Observable = action$.pipe( 31 | startWith(initialState), 32 | scan(reducer), 33 | log() 34 | ); 35 | 36 | // Dispatch actions 37 | export const dispatch = (action: Action) => action$.next(action); 38 | -------------------------------------------------------------------------------- /src/app/styles/_theme.scss: -------------------------------------------------------------------------------- 1 | @import '~@angular/material/theming'; 2 | 3 | @include mat-core(); 4 | $lookout-primary: mat-palette($mat-purple, 500, 200, 500); 5 | $lookout-accent: mat-palette($mat-deep-orange, 500, 100, 400); 6 | $lookout-warn: mat-palette($mat-red); 7 | $lookout-theme: mat-light-theme($lookout-primary, $lookout-accent, $lookout-warn); 8 | @include angular-material-theme($lookout-theme); 9 | 10 | .mat-button { 11 | border: 1px solid rgba(0, 0, 0, 0.7) !important; 12 | } 13 | 14 | .light { 15 | background: #f9f9fa; 16 | } 17 | 18 | .dark { 19 | background: #000; 20 | $lookout-dark-primary: mat-palette($mat-gray, 900, 100, 400); 21 | $lookout-dark-accent: mat-palette($mat-deep-orange, 500, 100, 400); 22 | $lookout-dark-warn: mat-palette($mat-red); 23 | $lookout-dark-theme: mat-dark-theme( 24 | $lookout-dark-primary, 25 | $lookout-dark-accent, 26 | $lookout-dark-warn 27 | ); 28 | @include angular-material-theme($lookout-dark-theme); 29 | 30 | .mat-button { 31 | border: 1px solid rgba(255, 255, 255, 0.3) !important; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/app/styles/_typography.scss: -------------------------------------------------------------------------------- 1 | @import '~@angular/material/theming'; 2 | 3 | .dark { 4 | color: $light-primary-text; 5 | } 6 | .light { 7 | color: $dark-primary-text; 8 | } 9 | -------------------------------------------------------------------------------- /src/app/styles/_variables.scss: -------------------------------------------------------------------------------- 1 | $lt-xsmall: 'max-width: 599px'; 2 | $gt-xsmall: 'min-width: 600px'; 3 | $lt-medium: 'max-width: 959px'; 4 | $gt-medium: 'min-width: 960px'; 5 | $lt-large: 'max-width: 1279px'; 6 | $gt-large: 'min-width: 1280px'; 7 | $lt-xlarge: 'max-width: 1439px'; 8 | $gt-xlarge: 'min-width: 1440px'; 9 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blove/advanced-rxjs/a0ea96f36cc5eaa71b739fe51246199cd44febb4/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | apiBaseUrl: '/api', 4 | }; 5 | -------------------------------------------------------------------------------- /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 | apiBaseUrl: '/api', 8 | }; 9 | 10 | /* 11 | * For easier debugging in development mode, you can import the following file 12 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 13 | * 14 | * This import should be commented out in production mode because it will have a negative impact 15 | * on performance if an error is thrown. 16 | */ 17 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 18 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blove/advanced-rxjs/a0ea96f36cc5eaa71b739fe51246199cd44febb4/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Advanced RxJs 6 | 7 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /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.error(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/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | 3 | html, 4 | body { 5 | height: 100%; 6 | } 7 | body { 8 | margin: 0; 9 | font-family: Roboto, 'Helvetica Neue', sans-serif; 10 | } 11 | 12 | @import './app/styles/theme'; 13 | @import './app/styles/typography'; 14 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.d.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /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 | "experimentalDecorators": true, 10 | "module": "es2020", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "lib": ["es2018", "dom"], 15 | "paths": { 16 | "@app-core/*": ["src/app/core/*"], 17 | "@app-features/*": ["src/app/features/*"], 18 | "@app-state/*": ["src/app/state/*"] 19 | } 20 | }, 21 | "angularCompilerOptions": { 22 | "fullTemplateTypeCheck": true, 23 | "strictInjectionParameters": true 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "module": "commonjs", 6 | "types": ["jest", "node"], 7 | "emitDecoratorMetadata": true, 8 | "allowJs": true 9 | }, 10 | "include": ["src/**/*.spec.ts", "src/**/*.d.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "align": { 5 | "options": [ 6 | "parameters", 7 | "statements" 8 | ] 9 | }, 10 | "array-type": false, 11 | "arrow-parens": false, 12 | "arrow-return-shorthand": true, 13 | "deprecation": { 14 | "severity": "warning" 15 | }, 16 | "component-class-suffix": true, 17 | "contextual-lifecycle": true, 18 | "curly": true, 19 | "directive-class-suffix": true, 20 | "directive-selector": [ 21 | true, 22 | "attribute", 23 | "app", 24 | "camelCase" 25 | ], 26 | "component-selector": [ 27 | true, 28 | "element", 29 | "app", 30 | "kebab-case" 31 | ], 32 | "eofline": true, 33 | "import-blacklist": [ 34 | true, 35 | "rxjs/Rx" 36 | ], 37 | "import-spacing": true, 38 | "indent": { 39 | "options": [ 40 | "spaces" 41 | ] 42 | }, 43 | "interface-name": false, 44 | "max-classes-per-file": false, 45 | "max-line-length": [ 46 | true, 47 | 140 48 | ], 49 | "member-access": false, 50 | "member-ordering": [ 51 | true, 52 | { 53 | "order": [ 54 | "static-field", 55 | "instance-field", 56 | "static-method", 57 | "instance-method" 58 | ] 59 | } 60 | ], 61 | "no-consecutive-blank-lines": false, 62 | "no-console": [ 63 | true, 64 | "debug", 65 | "info", 66 | "time", 67 | "timeEnd", 68 | "trace" 69 | ], 70 | "no-empty": false, 71 | "no-inferrable-types": [ 72 | true, 73 | "ignore-params" 74 | ], 75 | "no-non-null-assertion": true, 76 | "no-redundant-jsdoc": true, 77 | "no-switch-case-fall-through": true, 78 | "no-var-requires": false, 79 | "object-literal-key-quotes": [ 80 | true, 81 | "as-needed" 82 | ], 83 | "object-literal-sort-keys": false, 84 | "ordered-imports": false, 85 | "quotemark": [ 86 | true, 87 | "single" 88 | ], 89 | "trailing-comma": false, 90 | "no-conflicting-lifecycle": true, 91 | "no-host-metadata-property": true, 92 | "no-input-rename": true, 93 | "no-inputs-metadata-property": true, 94 | "no-output-native": true, 95 | "no-output-on-prefix": true, 96 | "no-output-rename": true, 97 | "semicolon": { 98 | "options": [ 99 | "always" 100 | ] 101 | }, 102 | "space-before-function-paren": { 103 | "options": { 104 | "anonymous": "never", 105 | "asyncArrow": "always", 106 | "constructor": "never", 107 | "method": "never", 108 | "named": "never" 109 | } 110 | }, 111 | "no-outputs-metadata-property": true, 112 | "template-banana-in-box": true, 113 | "template-no-negated-async": true, 114 | "typedef-whitespace": { 115 | "options": [ 116 | { 117 | "call-signature": "nospace", 118 | "index-signature": "nospace", 119 | "parameter": "nospace", 120 | "property-declaration": "nospace", 121 | "variable-declaration": "nospace" 122 | }, 123 | { 124 | "call-signature": "onespace", 125 | "index-signature": "onespace", 126 | "parameter": "onespace", 127 | "property-declaration": "onespace", 128 | "variable-declaration": "onespace" 129 | } 130 | ] 131 | }, 132 | "use-lifecycle-interface": true, 133 | "use-pipe-transform-interface": true, 134 | "variable-name": { 135 | "options": [ 136 | "ban-keywords", 137 | "check-format", 138 | "allow-pascal-case" 139 | ] 140 | }, 141 | "whitespace": { 142 | "options": [ 143 | "check-branch", 144 | "check-decl", 145 | "check-operator", 146 | "check-separator", 147 | "check-type", 148 | "check-typecast" 149 | ] 150 | } 151 | }, 152 | "rulesDirectory": [ 153 | "codelyzer" 154 | ] 155 | } --------------------------------------------------------------------------------