├── .angular-cli.json ├── .editorconfig ├── .gitignore ├── .travis.yml ├── README.md ├── angular.json ├── browserslist ├── e2e ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src ├── app │ ├── abstract-change-detection.component.ts │ ├── app.component.html │ ├── app.component.scss │ ├── app.component.ts │ ├── app.module.ts │ ├── change-detection.component.scss │ ├── change-detection.component.template.ts │ ├── color.service.ts │ ├── comp-tree │ │ ├── comp-1-1.component.ts │ │ ├── comp-1-2.component.ts │ │ ├── comp-1-x-1-1.component.ts │ │ ├── comp-1-x-1-2.component.ts │ │ ├── comp-1-x-1-3.component.ts │ │ ├── comp-1-x-1-4.component.ts │ │ ├── comp-1-x-1.component.ts │ │ ├── comp-1-x-2-1.component.ts │ │ ├── comp-1-x-2-2.component.ts │ │ ├── comp-1-x-2-3.component.ts │ │ ├── comp-1-x-2-4.component.ts │ │ ├── comp-1-x-2.component.ts │ │ ├── comp-1-x-3-1.component.ts │ │ ├── comp-1-x-3-2.component.ts │ │ ├── comp-1-x-3-3.component.ts │ │ ├── comp-1-x-3-4.component.ts │ │ ├── comp-1-x-3.component.ts │ │ ├── comp-1-x-4-1.component.ts │ │ ├── comp-1-x-4-2.component.ts │ │ ├── comp-1-x-4-3.component.ts │ │ ├── comp-1-x-4-4.component.ts │ │ ├── comp-1-x-4.component.ts │ │ └── comp-1.component.ts │ ├── delayed-scheduler.service.ts │ ├── dirty-check-coloring.service.ts │ ├── expand-collapse.service.ts │ └── number-holder.ts ├── assets │ └── .gitkeep ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── styles.scss └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json /.angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "project": { 4 | "name": "edu-change-detection" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets", 12 | "favicon.ico" 13 | ], 14 | "index": "index.html", 15 | "main": "main.ts", 16 | "polyfills": "polyfills.ts", 17 | "test": "test.ts", 18 | "tsconfig": "tsconfig.app.json", 19 | "testTsconfig": "tsconfig.spec.json", 20 | "prefix": "app", 21 | "styles": [ 22 | "styles.scss" 23 | ], 24 | "scripts": [], 25 | "environmentSource": "environments/environment.ts", 26 | "environments": { 27 | "dev": "environments/environment.ts", 28 | "prod": "environments/environment.prod.ts" 29 | } 30 | } 31 | ], 32 | "e2e": { 33 | "protractor": { 34 | "config": "./protractor.conf.js" 35 | } 36 | }, 37 | "lint": [ 38 | { 39 | "project": "src/tsconfig.app.json" 40 | }, 41 | { 42 | "project": "src/tsconfig.spec.json" 43 | }, 44 | { 45 | "project": "e2e/tsconfig.e2e.json" 46 | } 47 | ], 48 | "test": { 49 | "karma": { 50 | "config": "./karma.conf.js" 51 | } 52 | }, 53 | "defaults": { 54 | "styleExt": "scss", 55 | "component": {} 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | testem.log 34 | /typings 35 | 36 | # e2e 37 | /e2e/*.js 38 | /e2e/*.map 39 | 40 | # System Files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # This file contains instructions for the build server Travis 2 | # The build is running on https://travis-ci.com/. 3 | sudo: required 4 | dist: trusty 5 | language: node_js 6 | node_js: 7 | - '10.16.0' 8 | env: 9 | global: 10 | # $GH_TOKEN Token to access GitHub repo for deploying to GitHub Pages 11 | secure: MkDemB4Dtt3jr1XJmLdmQUdP3gKJ4uNitKyi00SeslVj4P3P2LRbTdRGu7U9WYT9hSW5VocvwVvYqz6WuTnSK1ODw772WTRAwxBbfSrMCkYb8IF7HbNqbIvDtlptnKl7vePMVs+F/ZWEd9ALlJ+fjpFqPmBc8LrGJY2fbBnprxQjQo3iQg0N7ThLc6xlMKdTlio+QFuVythC26Ni7w25Bz3ZeA5dd/0+mF3rPKRQzCrIapADBO2pG+WQ2PuQQpJb/WX9cnSkcKMsjBfvlA/Apsr875qvfprAS68/zRhGzssKn578blEhzi61w1Jz+0VM+dgTuYSp7y+0vNhmNZcI5h3fh6wEntWEWi57isKkf355mNIo65UWqATR2jFntX85qEQoyr1HgYUYr2QdqJIorIn2YrjS1VxmxeGGCvlqQIz/nUr+bePoqBdUM4hOhuGS0xcG74Sh7HMpj8UqIT0prfteO9RKY3jJdBAaUORe1y2L7RFVUO5P9CQzZAWv1s/UppXxKu3KfrbeooW0Uc80Y7b79t+FTiHOn8PwLPtxR9AkkHk9pvPyELRWOvr7O8qhIz966ZzR5rCL8/FYENlI11XLZD/IR2mCIRsX14aGLkwhLX7hSXeS1sjW5CfF4nJ14dGRr9zd5r+/+z3ItnwyFPS1aasXv01YbSWK4fd2VzY= 12 | install: 13 | - npm install 14 | script: 15 | - ng lint 16 | - npm run build-ghpages 17 | deploy: 18 | provider: pages 19 | skip_cleanup: true 20 | github_token: $GH_TOKEN 21 | local_dir: dist/change-detection 22 | on: 23 | branch: master 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EduChangeDetection 2 | 3 | This project illustrates how Angular change detection works. 4 | 5 | ## Live demo URL 6 | https://danielwiehl.github.io/edu-angular-change-detection/ 7 | 8 | ## Development server 9 | 10 | 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. 11 | 12 | ## Code scaffolding 13 | 14 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|module`. 15 | 16 | ## Build 17 | 18 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build. 19 | 20 | ## Running unit tests 21 | 22 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 23 | 24 | ## Running end-to-end tests 25 | 26 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 27 | Before running the tests make sure you are serving the app via `ng serve`. 28 | 29 | ## Further help 30 | 31 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 32 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "change-detection": { 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/change-detection", 21 | "index": "src/index.html", 22 | "main": "src/main.ts", 23 | "polyfills": "src/polyfills.ts", 24 | "tsConfig": "tsconfig.app.json", 25 | "aot": false, 26 | "assets": [ 27 | "src/favicon.ico", 28 | "src/assets" 29 | ], 30 | "styles": [ 31 | "src/styles.scss" 32 | ], 33 | "scripts": [] 34 | }, 35 | "configurations": { 36 | "production": { 37 | "fileReplacements": [ 38 | { 39 | "replace": "src/environments/environment.ts", 40 | "with": "src/environments/environment.prod.ts" 41 | } 42 | ], 43 | "optimization": true, 44 | "outputHashing": "all", 45 | "sourceMap": false, 46 | "extractCss": true, 47 | "namedChunks": false, 48 | "aot": true, 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": "change-detection:build" 71 | }, 72 | "configurations": { 73 | "production": { 74 | "browserTarget": "change-detection:build:production" 75 | } 76 | } 77 | }, 78 | "extract-i18n": { 79 | "builder": "@angular-devkit/build-angular:extract-i18n", 80 | "options": { 81 | "browserTarget": "change-detection: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 | "src/styles.scss" 97 | ], 98 | "scripts": [] 99 | } 100 | }, 101 | "lint": { 102 | "builder": "@angular-devkit/build-angular:tslint", 103 | "options": { 104 | "tsConfig": [ 105 | "tsconfig.app.json", 106 | "tsconfig.spec.json", 107 | "e2e/tsconfig.json" 108 | ], 109 | "exclude": [ 110 | "**/node_modules/**" 111 | ] 112 | } 113 | }, 114 | "e2e": { 115 | "builder": "@angular-devkit/build-angular:protractor", 116 | "options": { 117 | "protractorConfig": "e2e/protractor.conf.js", 118 | "devServerTarget": "change-detection:serve" 119 | }, 120 | "configurations": { 121 | "production": { 122 | "devServerTarget": "change-detection:serve:production" 123 | } 124 | } 125 | } 126 | } 127 | }}, 128 | "defaultProject": "change-detection" 129 | } -------------------------------------------------------------------------------- /browserslist: -------------------------------------------------------------------------------- 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'. -------------------------------------------------------------------------------- /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('change-detection 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() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 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": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /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/change-detection'), 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": "edu-change-detection", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "build-ghpages": "ng build --prod --base-href \"https://danielwiehl.github.io/edu-angular-change-detection/\"", 7 | "deploy-ghpages": "ngh --message=\"Deploy to https://danielwiehl.github.io/edu-angular-change-detection/\"" 8 | }, 9 | "private": true, 10 | "dependencies": { 11 | "@angular/animations": "~8.2.11", 12 | "@angular/common": "~8.2.11", 13 | "@angular/compiler": "~8.2.11", 14 | "@angular/core": "~8.2.11", 15 | "@angular/forms": "~8.2.11", 16 | "@angular/platform-browser": "~8.2.11", 17 | "@angular/platform-browser-dynamic": "~8.2.11", 18 | "@angular/router": "~8.2.11", 19 | "rxjs": "~6.4.0", 20 | "tslib": "^1.10.0", 21 | "zone.js": "~0.9.1" 22 | }, 23 | "devDependencies": { 24 | "@angular-devkit/build-angular": "~0.803.12", 25 | "@angular/cli": "~8.3.12", 26 | "@angular/compiler-cli": "~8.2.11", 27 | "@angular/language-service": "~8.2.11", 28 | "@types/node": "~8.9.4", 29 | "@types/jasmine": "~3.3.8", 30 | "@types/jasminewd2": "~2.0.3", 31 | "codelyzer": "^5.0.0", 32 | "jasmine-core": "~3.4.0", 33 | "jasmine-spec-reporter": "~4.2.1", 34 | "karma": "~4.1.0", 35 | "karma-chrome-launcher": "~2.2.0", 36 | "karma-coverage-istanbul-reporter": "~2.0.1", 37 | "karma-jasmine": "~2.0.1", 38 | "karma-jasmine-html-reporter": "^1.4.0", 39 | "protractor": "~5.4.0", 40 | "ts-node": "~7.0.0", 41 | "tslint": "~5.15.0", 42 | "typescript": "~3.5.3" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/app/abstract-change-detection.component.ts: -------------------------------------------------------------------------------- 1 | import { 2 | AfterViewInit, 3 | ChangeDetectionStrategy, 4 | ChangeDetectorRef, 5 | DoCheck, 6 | ElementRef, 7 | HostBinding, 8 | Input, 9 | NgZone, 10 | OnChanges, 11 | OnDestroy, 12 | SimpleChanges, 13 | ViewChild 14 | } from '@angular/core'; 15 | import { filter, takeUntil, tap } from 'rxjs/operators'; 16 | import { ColorService } from './color.service'; 17 | import { Observable, Subject, fromEvent } from 'rxjs'; 18 | import { NumberHolder } from './number-holder'; 19 | import { DirtyCheckColoringService } from './dirty-check-coloring.service'; 20 | import { ExpandCollapseService, State } from './expand-collapse.service'; 21 | 22 | export abstract class AbstractChangeDetectionComponent implements AfterViewInit, OnChanges, DoCheck, OnDestroy { 23 | 24 | private _destroy$ = new Subject(); 25 | private _destroyInputObservable$ = new Subject(); 26 | private _expandCollapseState = State.Expand; 27 | private _childType = ChildType.ViewChild; 28 | 29 | @ViewChild('component', { static: true }) 30 | private _componentField: ElementRef; 31 | 32 | @ViewChild('mfc_button', { static: true }) // mark for check 33 | private _mfcButton: ElementRef; 34 | 35 | @ViewChild('dc_button', { static: true }) // detect changes 36 | private _dcButton: ElementRef; 37 | 38 | @ViewChild('detach_button', { static: true }) // detach change detector 39 | private _detachButton: ElementRef; 40 | 41 | @ViewChild('attach_button', { static: true }) // attach change detector 42 | private _attachButton: ElementRef; 43 | 44 | @ViewChild('click_button', { static: true }) // attach change detector 45 | private _clickButton: ElementRef; 46 | 47 | @ViewChild('toggle_visiblity', { static: true }) 48 | private _toggleVisiblity: ElementRef; 49 | 50 | @ViewChild('cd_state_box', { static: true }) 51 | private _cdStateBox: ElementRef; 52 | 53 | @ViewChild('ng_do_check_box', { static: true }) 54 | private _ngDoCheckBox: ElementRef; 55 | 56 | @ViewChild('ng_on_changes_box', { static: true }) 57 | private _ngOnChangesBox: ElementRef; 58 | 59 | @Input() 60 | public inputByRef: NumberHolder; 61 | 62 | @Input() 63 | public inputByVal: number; 64 | 65 | @Input() 66 | public inputObservable: Observable; 67 | 68 | @Input() 69 | public set contentChild(contentChild: boolean) { 70 | this._childType = contentChild ? ChildType.ContentChild : ChildType.ViewChild; 71 | } 72 | 73 | @HostBinding('attr.class') 74 | public get hostClass(): string { 75 | const childType = (this._childType === ChildType.ViewChild ? 'view-child' : 'content-child'); 76 | return `${this.cdStrategyName} ${childType} level-${this._level}`; 77 | } 78 | 79 | public inputObservableValue: number; 80 | public cdStrategyName: string; 81 | 82 | constructor(public name: string, private _level: number, private _hostRef: ElementRef, private _colorService: ColorService, private _dirtyCheckColoringService: DirtyCheckColoringService, private _expandCollapseService: ExpandCollapseService, private _cd: ChangeDetectorRef, private _zone: NgZone, cdStrategy: ChangeDetectionStrategy) { 83 | this.cdStrategyName = resolveChangeDetectionStrategyName(cdStrategy); 84 | } 85 | 86 | public ngAfterViewInit(): void { 87 | this._attachButton.nativeElement.style.display = 'none'; 88 | 89 | // install outside Angular zone to not trigger change detection upon button click 90 | this._zone.runOutsideAngular(() => { 91 | // Detect Changes manually 92 | fromEvent(this._dcButton.nativeElement, 'click').pipe( 93 | takeUntil(this._destroy$), 94 | tap(() => this._dirtyCheckColoringService.clearColoring()) 95 | ) 96 | .subscribe(event => { 97 | console.log(`ChangeDetectorRef.detectChanges() for ${this.name}`); 98 | this._cd.detectChanges(); 99 | }); 100 | 101 | // Mark for check 102 | fromEvent(this._mfcButton.nativeElement, 'click').pipe( 103 | takeUntil(this._destroy$), 104 | tap(() => this._dirtyCheckColoringService.clearColoring()) 105 | ) 106 | .subscribe(event => { 107 | console.log(`ChangeDetectorRef.markForCheck() for ${this.name}`); 108 | this._cd.markForCheck(); 109 | }); 110 | 111 | // Detach change detector 112 | fromEvent(this._detachButton.nativeElement, 'click').pipe( 113 | takeUntil(this._destroy$), 114 | tap(() => this._dirtyCheckColoringService.clearColoring()) 115 | ) 116 | .subscribe(event => { 117 | console.log(`ChangeDetectorRef.detach() for ${this.name}`); 118 | this._cd.detach(); 119 | this._colorService.colorChangeDetectorDetached(this._cdStateBox); 120 | this._detachButton.nativeElement.style.display = 'none'; // because outside Angular zone 121 | this._attachButton.nativeElement.style.display = 'inline'; 122 | }); 123 | 124 | // Attach change detector 125 | fromEvent(this._attachButton.nativeElement, 'click').pipe( 126 | takeUntil(this._destroy$), 127 | tap(() => this._dirtyCheckColoringService.clearColoring()) 128 | ) 129 | .subscribe(event => { 130 | console.log(`ChangeDetectorRef.reattach() for ${this.name}`); 131 | this._cd.reattach(); 132 | this._colorService.colorChangeDetectorAttached(this._cdStateBox); 133 | this._detachButton.nativeElement.style.display = 'inline'; // because outside Angular zone 134 | this._attachButton.nativeElement.style.display = 'none'; 135 | }); 136 | 137 | // Toggle visibility 138 | fromEvent(this._toggleVisiblity.nativeElement, 'click').pipe( 139 | takeUntil(this._destroy$) 140 | ) 141 | .subscribe(event => { 142 | const toggledState = (this._expandCollapseState === State.Expand ? State.Collapse : State.Expand); 143 | this.setExpandCollapseState(toggledState); 144 | }); 145 | 146 | this._dirtyCheckColoringService.busy$.pipe( 147 | takeUntil(this._destroy$) 148 | ) 149 | .subscribe(busy => { 150 | this._dcButton.nativeElement.disabled = busy; 151 | this._mfcButton.nativeElement.disabled = busy; 152 | this._attachButton.nativeElement.disabled = busy; 153 | this._detachButton.nativeElement.disabled = busy; 154 | this._clickButton.nativeElement.disabled = busy; 155 | }); 156 | 157 | this._expandCollapseService.contentChildren$.pipe( 158 | takeUntil(this._destroy$), 159 | filter(_ => this._childType === ChildType.ContentChild) 160 | ) 161 | .subscribe(state => this.setExpandCollapseState(state)); 162 | }); 163 | } 164 | 165 | 166 | public ngOnChanges(changes: SimpleChanges): void { 167 | if (changes.inputObservable) { 168 | this._destroyInputObservable$.next(); 169 | this.inputObservable.pipe( 170 | takeUntil(this._destroy$), 171 | takeUntil(this._destroyInputObservable$) 172 | ) 173 | .subscribe(value => this.inputObservableValue = value); 174 | } 175 | this._colorService.colorNgOnChanges(this._ngOnChangesBox); 176 | } 177 | 178 | public ngDoCheck(): void { 179 | this._colorService.colorNgDoCheck(this._ngDoCheckBox); 180 | } 181 | 182 | public ngOnDestroy(): void { 183 | this._destroy$.complete(); 184 | } 185 | 186 | public get touch(): string { 187 | this._colorService.colorDirtyCheck(this._hostRef); 188 | return null; 189 | } 190 | 191 | public onClick(): void { 192 | console.log(`Click for ${this.name}`); 193 | } 194 | 195 | private setExpandCollapseState(state: State): void { 196 | this._expandCollapseState = state; 197 | if (state === State.Expand) { 198 | this._componentField.nativeElement.style.display = 'inline'; 199 | this._toggleVisiblity.nativeElement.innerHTML = '-'; 200 | } else { 201 | this._componentField.nativeElement.style.display = 'none'; 202 | this._toggleVisiblity.nativeElement.innerHTML = '+'; 203 | } 204 | } 205 | } 206 | 207 | function resolveChangeDetectionStrategyName(strategy: any): string { 208 | for (const name in ChangeDetectionStrategy) { 209 | if (ChangeDetectionStrategy[ name ] === strategy && ChangeDetectionStrategy.hasOwnProperty(name)) { 210 | return name; 211 | } 212 | } 213 | 214 | return undefined; 215 | } 216 | 217 | enum ChildType { 218 | ViewChild, ContentChild 219 | } 220 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
Trigger global actions
4 | 9 |
10 | 11 |
12 |
Control dirty check coloring
13 | 18 |
19 | 20 |
21 |
Play with component input - current value: n/a
22 | 29 |
30 | 31 |
32 |
Expand or collapse ContentChildren
33 | 36 |
37 |
38 | 39 |
40 | 41 | 42 |
43 |
44 |
ngDoCheck
45 |
46 |

Lifecycle hook that is called when Angular dirty checks a directive.


47 | 'ngDoCheck' gets called to check the changes in the directives in addition to the default algorithm. The default 48 | change detection algorithm looks for differences by comparing bound-property values by reference across change 49 | detection runs.
50 | The ngDoCheck lifecycle hook is triggered even if the the component uses OnPush strategy. 51 |
52 |
53 | 54 |
55 |
ngOnChanges
56 |
57 |

Lifecycle hook that is called when any data-bound property of a directive changes.


58 | `ngOnChanges` is called right after the data-bound properties have been checked and before view and content 59 | children are checked if at least one of them has changed. 60 |
61 |
62 | 63 |
64 |
Good readings
65 | 69 |
70 |
71 |
72 | -------------------------------------------------------------------------------- /src/app/app.component.scss: -------------------------------------------------------------------------------- 1 | :host { 2 | display: flex; 3 | flex-flow: column nowrap; 4 | position: absolute; 5 | top: 0; 6 | right: 0; 7 | bottom: 0; 8 | left: 0; 9 | 10 | .control { 11 | flex: none; 12 | display: flex; 13 | flex-wrap: wrap; 14 | font-size: 11px; 15 | button { 16 | font-size: 11px; 17 | } 18 | 19 | nav { 20 | display: flex; 21 | padding: 5px; 22 | align-items: center; 23 | 24 | > * { 25 | margin-right: 5px; 26 | flex: none; 27 | } 28 | 29 | .filler { 30 | flex: auto; 31 | } 32 | } 33 | 34 | label { 35 | display: flex; 36 | align-items: center; 37 | } 38 | } 39 | 40 | main { 41 | position: relative; // positioned anchor 42 | overflow-y: scroll; 43 | flex: auto; 44 | 45 | .explanation { 46 | article { 47 | padding: 5px; 48 | } 49 | } 50 | } 51 | 52 | section { 53 | border: 1px solid black; 54 | background-color: #f2f2f2; 55 | margin: 20px 10px; 56 | flex: auto; 57 | 58 | > header { 59 | padding: 5px 5px; 60 | display: block; 61 | background-color: #b3b3b3; 62 | font-weight: bold; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Subject, fromEvent } from 'rxjs'; 2 | import { AfterViewInit, ApplicationRef, Component, ElementRef, NgZone, OnDestroy, ViewChild } from '@angular/core'; 3 | import { map, takeUntil, tap } from 'rxjs/operators'; 4 | import { NumberHolder } from './number-holder'; 5 | import { DirtyCheckColoringService } from './dirty-check-coloring.service'; 6 | import { ExpandCollapseService, State } from './expand-collapse.service'; 7 | 8 | @Component({ 9 | selector : 'app-root', 10 | templateUrl: './app.component.html', 11 | styleUrls : ['./app.component.scss'] 12 | }) 13 | export class AppComponent implements AfterViewInit, OnDestroy { 14 | 15 | private _destroy$ = new Subject(); 16 | 17 | private value = 0; 18 | private busy = false; 19 | public inputByVal: number; 20 | public inputByRef = new NumberHolder(); 21 | public inputObservable = new Subject(); 22 | 23 | @ViewChild('apptick_button', { static: true }) 24 | private _apptickButton: ElementRef; 25 | 26 | @ViewChild('timeout_button', { static: true }) 27 | private _timeoutButton: ElementRef; 28 | 29 | @ViewChild('click_button', { static: true }) 30 | private _clickButton: ElementRef; 31 | 32 | @ViewChild('trigger_change', { static: true }) 33 | private _triggerChangeButton: ElementRef; 34 | 35 | @ViewChild('clear', { static: true }) 36 | private _clearButton: ElementRef; 37 | 38 | @ViewChild('auto_clear', { static: true }) 39 | private _autoClearCheckbox: ElementRef; 40 | 41 | @ViewChild('toggle_content_children', { static: true }) 42 | private _toggleContentChildren: ElementRef; 43 | 44 | @ViewChild('input_value_field', { static: true }) 45 | private _inputValueField: ElementRef; 46 | 47 | @ViewChild('propagate_by_value_checkbox', { static: true }) 48 | private _propagateByValueCheckbox: ElementRef; 49 | 50 | @ViewChild('propagate_by_ref_checkbox', { static: true }) 51 | private _propagateByRefCheckbox: ElementRef; 52 | 53 | @ViewChild('propagate_by_observable_checkbox', { static: true }) 54 | private _propagateByObservableCheckbox: ElementRef; 55 | 56 | @ViewChild('propagate_in_zone_checkbox', { static: true }) 57 | private _propagateInZoneCheckbox: ElementRef; 58 | 59 | constructor(private _zone: NgZone, private _appRef: ApplicationRef, private _dirtyCheckColoringService: DirtyCheckColoringService, private _expandCollapseService: ExpandCollapseService) { 60 | } 61 | 62 | public ngAfterViewInit(): void { 63 | this._dirtyCheckColoringService.setAutoClearColoring(this.isAutoClear()); 64 | 65 | this._zone.runOutsideAngular(() => { 66 | // apptick 67 | fromEvent(this._apptickButton.nativeElement, 'click').pipe( 68 | tap(() => this._dirtyCheckColoringService.clearColoring()), 69 | takeUntil(this._destroy$) 70 | ) 71 | .subscribe(event => this._appRef.tick()); 72 | 73 | // timeout 74 | fromEvent(this._timeoutButton.nativeElement, 'click').pipe( 75 | takeUntil(this._destroy$) 76 | ) 77 | .subscribe(event => { 78 | setTimeout(() => this._zone.run(() => console.log(`setTimeout(...)`)), 3000); 79 | }); 80 | 81 | // clear auto checkbox 82 | fromEvent(this._autoClearCheckbox.nativeElement, 'change').pipe( 83 | takeUntil(this._destroy$), 84 | map((event: Event) => event.target as HTMLInputElement) 85 | ) 86 | .subscribe(element => { 87 | this._dirtyCheckColoringService.setAutoClearColoring(element.checked); 88 | }); 89 | 90 | // clear 91 | fromEvent(this._clearButton.nativeElement, 'click').pipe( 92 | takeUntil(this._destroy$) 93 | ) 94 | .subscribe(_ => { 95 | this._dirtyCheckColoringService.clearColoring(); 96 | }); 97 | 98 | // Change input 99 | fromEvent(this._triggerChangeButton.nativeElement, 'click').pipe( 100 | takeUntil(this._destroy$), 101 | tap(() => this._dirtyCheckColoringService.clearColoring()) 102 | ).subscribe(_ => { 103 | if (this.isPropagateInZone()) { 104 | this._zone.run(this.updateInputValue.bind(this)); 105 | } else { 106 | this.updateInputValue(); 107 | } 108 | }); 109 | 110 | // Toggle content children 111 | fromEvent(this._toggleContentChildren.nativeElement, 'click').pipe( 112 | takeUntil(this._destroy$) 113 | ) 114 | .subscribe(_ => this._expandCollapseService.toggleContentChildren()); 115 | 116 | // Toggle ContentChildren 117 | this._expandCollapseService.contentChildren$.pipe( 118 | takeUntil(this._destroy$) 119 | ) 120 | .subscribe(state => { 121 | const button = this._toggleContentChildren.nativeElement as HTMLElement; 122 | button.innerHTML = (state === State.Expand ? 'Collapse ContentChildren' : 'Expand ContentChildren'); 123 | }); 124 | 125 | // Busy 126 | this._dirtyCheckColoringService.busy$.pipe( 127 | takeUntil(this._destroy$) 128 | ) 129 | .subscribe(busy => { 130 | this.busy = busy; 131 | this._apptickButton.nativeElement.disabled = busy; 132 | this._timeoutButton.nativeElement.disabled = busy; 133 | this._clickButton.nativeElement.disabled = busy; 134 | this._autoClearCheckbox.nativeElement.disabled = busy; 135 | this._triggerChangeButton.nativeElement.disabled = busy; 136 | this._propagateByValueCheckbox.nativeElement.disabled = busy; 137 | this._propagateByRefCheckbox.nativeElement.disabled = busy; 138 | this._propagateByObservableCheckbox.nativeElement.disabled = busy; 139 | this._propagateInZoneCheckbox.nativeElement.disabled = busy; 140 | if (busy && !this._dirtyCheckColoringService.isAutoClearColoring()) { 141 | this._clearButton.nativeElement.classList.add('emphasize'); 142 | } else { 143 | this._clearButton.nativeElement.classList.remove('emphasize'); 144 | } 145 | }); 146 | }); 147 | } 148 | 149 | public clickNoop(): void { 150 | console.log(`click`); 151 | } 152 | 153 | public ngOnDestroy(): void { 154 | this._destroy$.complete(); 155 | } 156 | 157 | private updateInputValue(): void { 158 | this.value++; 159 | if (this.isPropagateByValue()) { 160 | this.inputByVal = this.value; 161 | } 162 | if (this.isPropagateByRef()) { 163 | this.inputByRef.value = this.value; 164 | } 165 | if (this.isPropagateByObservable()) { 166 | this.inputObservable.next(this.value); 167 | } 168 | 169 | // Update DOM directly because outside Angular zone to not trigger change detection 170 | const valueElement = this._inputValueField.nativeElement as HTMLElement; 171 | valueElement.innerHTML = (this.value).toString(10); 172 | } 173 | 174 | private isAutoClear(): boolean { 175 | return (this._autoClearCheckbox.nativeElement as HTMLInputElement).checked; 176 | } 177 | 178 | private isPropagateByValue(): boolean { 179 | return (this._propagateByValueCheckbox.nativeElement as HTMLInputElement).checked; 180 | } 181 | 182 | private isPropagateByRef(): boolean { 183 | return (this._propagateByRefCheckbox.nativeElement as HTMLInputElement).checked; 184 | } 185 | 186 | private isPropagateByObservable(): boolean { 187 | return (this._propagateByObservableCheckbox.nativeElement as HTMLInputElement).checked; 188 | } 189 | 190 | private isPropagateInZone(): boolean { 191 | return (this._propagateInZoneCheckbox.nativeElement as HTMLInputElement).checked; 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { AppComponent } from './app.component'; 5 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 6 | import { Comp_1_Component } from './comp-tree/comp-1.component'; 7 | import { Comp_1_1_Component } from './comp-tree/comp-1-1.component'; 8 | import { Comp_1_2_Component } from './comp-tree/comp-1-2.component'; 9 | import { Comp_1_x_1_Component } from './comp-tree/comp-1-x-1.component'; 10 | import { Comp_1_x_1_1_Component } from './comp-tree/comp-1-x-1-1.component'; 11 | import { Comp_1_x_1_2_Component } from './comp-tree/comp-1-x-1-2.component'; 12 | import { Comp_1_x_1_3_Component } from './comp-tree/comp-1-x-1-3.component'; 13 | import { Comp_1_x_1_4_Component } from './comp-tree/comp-1-x-1-4.component'; 14 | import { Comp_1_x_2_Component } from './comp-tree/comp-1-x-2.component'; 15 | import { Comp_1_x_2_1_Component } from './comp-tree/comp-1-x-2-1.component'; 16 | import { Comp_1_x_2_2_Component } from './comp-tree/comp-1-x-2-2.component'; 17 | import { Comp_1_x_2_3_Component } from './comp-tree/comp-1-x-2-3.component'; 18 | import { Comp_1_x_2_4_Component } from './comp-tree/comp-1-x-2-4.component'; 19 | import { Comp_1_x_3_Component } from './comp-tree/comp-1-x-3.component'; 20 | import { Comp_1_x_3_1_Component } from './comp-tree/comp-1-x-3-1.component'; 21 | import { Comp_1_x_3_2_Component } from './comp-tree/comp-1-x-3-2.component'; 22 | import { Comp_1_x_3_3_Component } from './comp-tree/comp-1-x-3-3.component'; 23 | import { Comp_1_x_3_4_Component } from './comp-tree/comp-1-x-3-4.component'; 24 | import { Comp_1_x_4_Component } from './comp-tree/comp-1-x-4.component'; 25 | import { Comp_1_x_4_1_Component } from './comp-tree/comp-1-x-4-1.component'; 26 | import { Comp_1_x_4_2_Component } from './comp-tree/comp-1-x-4-2.component'; 27 | import { Comp_1_x_4_3_Component } from './comp-tree/comp-1-x-4-3.component'; 28 | import { Comp_1_x_4_4_Component } from './comp-tree/comp-1-x-4-4.component'; 29 | import { DirtyCheckColoringService } from './dirty-check-coloring.service'; 30 | import { ExpandCollapseService } from './expand-collapse.service'; 31 | 32 | @NgModule({ 33 | declarations: [ 34 | AppComponent, 35 | Comp_1_Component, 36 | Comp_1_1_Component, 37 | Comp_1_2_Component, 38 | Comp_1_x_1_Component, 39 | Comp_1_x_1_1_Component, 40 | Comp_1_x_1_2_Component, 41 | Comp_1_x_1_3_Component, 42 | Comp_1_x_1_4_Component, 43 | Comp_1_x_2_Component, 44 | Comp_1_x_2_1_Component, 45 | Comp_1_x_2_2_Component, 46 | Comp_1_x_2_3_Component, 47 | Comp_1_x_2_4_Component, 48 | Comp_1_x_3_Component, 49 | Comp_1_x_3_1_Component, 50 | Comp_1_x_3_2_Component, 51 | Comp_1_x_3_3_Component, 52 | Comp_1_x_3_4_Component, 53 | Comp_1_x_4_Component, 54 | Comp_1_x_4_1_Component, 55 | Comp_1_x_4_2_Component, 56 | Comp_1_x_4_3_Component, 57 | Comp_1_x_4_4_Component 58 | ], 59 | imports: [ 60 | BrowserModule, 61 | ReactiveFormsModule, 62 | FormsModule 63 | ], 64 | providers: [ 65 | DirtyCheckColoringService, 66 | ExpandCollapseService 67 | ], 68 | bootstrap: [AppComponent] 69 | }) 70 | export class AppModule { 71 | } 72 | -------------------------------------------------------------------------------- /src/app/change-detection.component.scss: -------------------------------------------------------------------------------- 1 | $collapse-button-size: 15px; 2 | 3 | :host { 4 | position: relative; // anchor 5 | background-color: white; 6 | display: inline-block; 7 | border: 1px solid black; 8 | margin: 10px; 9 | padding: 5px; 10 | text-align: center; 11 | border-radius: 3px; 12 | min-width: $collapse-button-size; 13 | min-height: $collapse-button-size; 14 | 15 | > button.toggle-visibility { 16 | z-index: 1; 17 | position: absolute; 18 | left: 0; 19 | top: 0; 20 | width: $collapse-button-size; 21 | height: $collapse-button-size; 22 | border: none; 23 | color: black; 24 | background-color: transparent; 25 | outline: none; 26 | margin: 0; 27 | } 28 | 29 | &.dirty-check { 30 | &.level-1 { 31 | background-color: #e6e6ff; 32 | } 33 | &.level-2 { 34 | background-color: #ccccff; 35 | } 36 | &.level-3 { 37 | background-color: #b3b3ff; 38 | } 39 | &.level-4 { 40 | background-color: #9999ff; 41 | } 42 | &.level-5 { 43 | background-color: #8080ff; 44 | } 45 | &.level-6 { 46 | background-color: #6666ff; 47 | } 48 | &.level-7 { 49 | background-color: #4d4dff; 50 | } 51 | &.level-8 { 52 | background-color: #3333ff; 53 | } 54 | &.level-9 { 55 | background-color: #1a1aff; 56 | } 57 | &.level-10 { 58 | background-color: #0000ff; 59 | } 60 | } 61 | 62 | > div.component::before { 63 | position: relative; 64 | top: -10px; 65 | font-family: monospace; 66 | font-size: 10px; 67 | } 68 | 69 | &.view-child { 70 | border-style: solid; 71 | > div.component::before { 72 | content: '<>'; 73 | } 74 | } 75 | 76 | &.content-child { 77 | border-style: dashed; 78 | > div.component::before { 79 | content: '<>'; 80 | } 81 | } 82 | 83 | > div.component { 84 | > div.state { 85 | 86 | > span { 87 | display: inline-block; 88 | margin: 2px 0; 89 | padding: 2px 3px; 90 | border-radius: 3px; 91 | border: 1px solid; 92 | font-size: 10px; 93 | color: black; 94 | background-color: white; 95 | } 96 | 97 | > span.strategy-box { 98 | border-color: black; 99 | color: white; 100 | 101 | &.Default { 102 | border-color: black; 103 | background-color: black; 104 | color: white; 105 | } 106 | 107 | &.OnPush { 108 | border-color: deeppink; 109 | background-color: deeppink; 110 | color: white; 111 | } 112 | } 113 | 114 | > span.cd-state-box { 115 | border-color: #004d1a; 116 | color: #004d1a; 117 | background-color: #b3ffcc; 118 | &::before { 119 | content: 'attached'; 120 | } 121 | 122 | &.cd-detached { 123 | color: #000000; 124 | background-color: #cccccc; 125 | border-color: #000000; 126 | &::before { 127 | content: 'detached'; 128 | } 129 | } 130 | } 131 | 132 | > span.ng-do-check-box { 133 | border-color: darkgray; 134 | color: darkgray; 135 | 136 | &.ng-do-check { 137 | border-color: red; 138 | color: red; 139 | background-color: #ffe6e6; 140 | } 141 | } 142 | 143 | > span.ng-on-changes-box { 144 | border-color: darkgray; 145 | color: darkgray; 146 | 147 | &.ng-on-changes { 148 | border-color: red; 149 | color: red; 150 | background-color: #ffe6e6; 151 | } 152 | } 153 | } 154 | 155 | > div.name { 156 | padding: 5px 0; 157 | font-size: 12px; 158 | font-weight: bold; 159 | } 160 | 161 | > table.input-box { 162 | margin: 5px auto; 163 | font-size: 11px; 164 | border: 1px solid #000000; 165 | border-spacing: 0; 166 | border-collapse: collapse; 167 | 168 | td, th { 169 | padding: 2px 3px; 170 | text-align: left; 171 | } 172 | } 173 | 174 | > div.control > button { 175 | font-size: 10px; 176 | } 177 | 178 | > div.children { 179 | display: flex; 180 | flex-wrap: nowrap; 181 | flex-direction: row; 182 | justify-content: center; 183 | } 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /src/app/change-detection.component.template.ts: -------------------------------------------------------------------------------- 1 | export function template(children: string): string { 2 | return ` 3 | {{touch}} 4 | 5 |
6 |
7 | {{cdStrategyName}} 8 | 9 | ngDoCheck 10 | ngOnChanges 11 |
12 |
13 | {{name}} 14 |
15 | 16 | 17 | 18 | 19 |
input value:{{inputByVal}}
object prop:{{inputByRef?.value}}
observable:{{inputObservableValue}}
20 |
21 | 22 | 23 | 24 | 25 | 26 |
27 |
28 | ${children} 29 | 30 |
31 |
`; 32 | } 33 | -------------------------------------------------------------------------------- /src/app/color.service.ts: -------------------------------------------------------------------------------- 1 | import { ElementRef, Injectable, NgZone } from '@angular/core'; 2 | 3 | import { DirtyCheckColoringService } from './dirty-check-coloring.service'; 4 | 5 | @Injectable() 6 | export class ColorService { 7 | 8 | private ngDoCheckHandle: any; 9 | private ngOnChangesHandle: any; 10 | 11 | constructor(private _zone: NgZone, private _dirtyCheckColoringService: DirtyCheckColoringService) { 12 | } 13 | 14 | public colorNgDoCheck(elementRef: ElementRef): void { 15 | this._zone.runOutsideAngular(() => { 16 | clearTimeout(this.ngDoCheckHandle); 17 | this.ngDoCheckHandle = this.blink(elementRef.nativeElement as HTMLElement, 'ng-do-check'); 18 | }); 19 | } 20 | 21 | public colorNgOnChanges(elementRef: ElementRef): void { 22 | this._zone.runOutsideAngular(() => { 23 | clearTimeout(this.ngOnChangesHandle); 24 | this.ngOnChangesHandle = this.blink(elementRef.nativeElement as HTMLElement, 'ng-on-changes'); 25 | }); 26 | } 27 | 28 | public colorDirtyCheck(elementRef: ElementRef): void { 29 | this._zone.runOutsideAngular(() => { 30 | this._dirtyCheckColoringService.colorDirtyCheck(elementRef); 31 | }); 32 | } 33 | 34 | public colorChangeDetectorDetached(hostRef: ElementRef): void { 35 | this._zone.runOutsideAngular(() => { 36 | const host = hostRef.nativeElement as HTMLElement; 37 | host.classList.add('cd-detached'); 38 | }); 39 | } 40 | 41 | public colorChangeDetectorAttached(hostRef: ElementRef): void { 42 | this._zone.runOutsideAngular(() => { 43 | const host = hostRef.nativeElement as HTMLElement; 44 | host.classList.remove('cd-detached'); 45 | }); 46 | } 47 | 48 | private blink(element: HTMLElement, cssClass: string): any { 49 | element.classList.add(cssClass); 50 | return setTimeout(() => element.classList.remove(cssClass), 1500); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-1.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-1'; 9 | const LEVEL = 2; 10 | const CD_STRATEGY = ChangeDetectionStrategy.Default; 11 | const CHILD_TEMPLATE = ` 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | `; 21 | 22 | @Component({ 23 | selector: `app-${NAME}`, 24 | template: template(CHILD_TEMPLATE), 25 | styleUrls: ['./../change-detection.component.scss'], 26 | providers: [ColorService], 27 | changeDetection: CD_STRATEGY 28 | }) 29 | export class Comp_1_1_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 30 | 31 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 32 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-2.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-2'; 9 | const LEVEL = 2; 10 | const CD_STRATEGY = ChangeDetectionStrategy.OnPush; 11 | const CHILD_TEMPLATE = ` 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | `; 21 | 22 | @Component({ 23 | selector: `app-${NAME}`, 24 | template: template(CHILD_TEMPLATE), 25 | styleUrls: ['./../change-detection.component.scss'], 26 | providers: [ColorService], 27 | changeDetection: CD_STRATEGY 28 | }) 29 | export class Comp_1_2_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 30 | 31 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 32 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-1-1.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-1-1'; 9 | const LEVEL = 4; 10 | const CD_STRATEGY = ChangeDetectionStrategy.Default; 11 | const CHILD_TEMPLATE = ``; 12 | 13 | @Component({ 14 | selector: `app-${NAME}`, 15 | template: template(CHILD_TEMPLATE), 16 | styleUrls: ['./../change-detection.component.scss'], 17 | providers: [ColorService], 18 | changeDetection: CD_STRATEGY 19 | }) 20 | export class Comp_1_x_1_1_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 21 | 22 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 23 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-1-2.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-1-2'; 9 | const LEVEL = 4; 10 | const CD_STRATEGY = ChangeDetectionStrategy.OnPush; 11 | const CHILD_TEMPLATE = ``; 12 | 13 | @Component({ 14 | selector: `app-${NAME}`, 15 | template: template(CHILD_TEMPLATE), 16 | styleUrls: ['./../change-detection.component.scss'], 17 | providers: [ColorService], 18 | changeDetection: CD_STRATEGY 19 | }) 20 | export class Comp_1_x_1_2_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 21 | 22 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 23 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-1-3.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-1-3'; 9 | const LEVEL = 4; 10 | const CD_STRATEGY = ChangeDetectionStrategy.Default; 11 | const CHILD_TEMPLATE = ``; 12 | 13 | @Component({ 14 | selector: `app-${NAME}`, 15 | template: template(CHILD_TEMPLATE), 16 | styleUrls: ['./../change-detection.component.scss'], 17 | providers: [ColorService], 18 | changeDetection: CD_STRATEGY 19 | }) 20 | export class Comp_1_x_1_3_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 21 | 22 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 23 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-1-4.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-1-4'; 9 | const LEVEL = 4; 10 | const CD_STRATEGY = ChangeDetectionStrategy.OnPush; 11 | const CHILD_TEMPLATE = ``; 12 | 13 | @Component({ 14 | selector: `app-${NAME}`, 15 | template: template(CHILD_TEMPLATE), 16 | styleUrls: ['./../change-detection.component.scss'], 17 | providers: [ColorService], 18 | changeDetection: CD_STRATEGY 19 | }) 20 | export class Comp_1_x_1_4_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 21 | 22 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 23 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-1.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-1'; 9 | const LEVEL = 3; 10 | const CD_STRATEGY = ChangeDetectionStrategy.Default; 11 | const CHILD_TEMPLATE = ` 12 | 13 | 14 | `; 15 | 16 | @Component({ 17 | selector: `app-${NAME}`, 18 | template: template(CHILD_TEMPLATE), 19 | styleUrls: ['./../change-detection.component.scss'], 20 | providers: [ColorService], 21 | changeDetection: CD_STRATEGY 22 | }) 23 | export class Comp_1_x_1_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 24 | 25 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 26 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-2-1.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-2-1'; 9 | const LEVEL = 4; 10 | const CD_STRATEGY = ChangeDetectionStrategy.Default; 11 | const CHILD_TEMPLATE = ``; 12 | 13 | @Component({ 14 | selector: `app-${NAME}`, 15 | template: template(CHILD_TEMPLATE), 16 | styleUrls: ['./../change-detection.component.scss'], 17 | providers: [ColorService], 18 | changeDetection: CD_STRATEGY 19 | }) 20 | export class Comp_1_x_2_1_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 21 | 22 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 23 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-2-2.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-2-2'; 9 | const LEVEL = 4; 10 | const CD_STRATEGY = ChangeDetectionStrategy.OnPush; 11 | const CHILD_TEMPLATE = ``; 12 | 13 | @Component({ 14 | selector: `app-${NAME}`, 15 | template: template(CHILD_TEMPLATE), 16 | styleUrls: ['./../change-detection.component.scss'], 17 | providers: [ColorService], 18 | changeDetection: CD_STRATEGY 19 | }) 20 | export class Comp_1_x_2_2_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 21 | 22 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 23 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-2-3.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-2-3'; 9 | const LEVEL = 4; 10 | const CD_STRATEGY = ChangeDetectionStrategy.Default; 11 | const CHILD_TEMPLATE = ``; 12 | 13 | @Component({ 14 | selector: `app-${NAME}`, 15 | template: template(CHILD_TEMPLATE), 16 | styleUrls: ['./../change-detection.component.scss'], 17 | providers: [ColorService], 18 | changeDetection: CD_STRATEGY 19 | }) 20 | export class Comp_1_x_2_3_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 21 | 22 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 23 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-2-4.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-2-4'; 9 | const LEVEL = 4; 10 | const CD_STRATEGY = ChangeDetectionStrategy.OnPush; 11 | const CHILD_TEMPLATE = ``; 12 | 13 | @Component({ 14 | selector: `app-${NAME}`, 15 | template: template(CHILD_TEMPLATE), 16 | styleUrls: ['./../change-detection.component.scss'], 17 | providers: [ColorService], 18 | changeDetection: CD_STRATEGY 19 | }) 20 | export class Comp_1_x_2_4_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 21 | 22 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 23 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-2.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-2'; 9 | const LEVEL = 3; 10 | const CD_STRATEGY = ChangeDetectionStrategy.OnPush; 11 | const CHILD_TEMPLATE = ` 12 | 13 | 14 | `; 15 | 16 | @Component({ 17 | selector: `app-${NAME}`, 18 | template: template(CHILD_TEMPLATE), 19 | styleUrls: ['./../change-detection.component.scss'], 20 | providers: [ColorService], 21 | changeDetection: CD_STRATEGY 22 | }) 23 | export class Comp_1_x_2_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 24 | 25 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 26 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-3-1.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-3-1'; 9 | const LEVEL = 4; 10 | const CD_STRATEGY = ChangeDetectionStrategy.Default; 11 | const CHILD_TEMPLATE = ``; 12 | 13 | @Component({ 14 | selector: `app-${NAME}`, 15 | template: template(CHILD_TEMPLATE), 16 | styleUrls: ['./../change-detection.component.scss'], 17 | providers: [ColorService], 18 | changeDetection: CD_STRATEGY 19 | }) 20 | export class Comp_1_x_3_1_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 21 | 22 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 23 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-3-2.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-3-2'; 9 | const LEVEL = 4; 10 | const CD_STRATEGY = ChangeDetectionStrategy.OnPush; 11 | const CHILD_TEMPLATE = ``; 12 | 13 | @Component({ 14 | selector: `app-${NAME}`, 15 | template: template(CHILD_TEMPLATE), 16 | styleUrls: ['./../change-detection.component.scss'], 17 | providers: [ColorService], 18 | changeDetection: CD_STRATEGY 19 | }) 20 | export class Comp_1_x_3_2_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 21 | 22 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 23 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-3-3.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-3-3'; 9 | const LEVEL = 4; 10 | const CD_STRATEGY = ChangeDetectionStrategy.Default; 11 | const CHILD_TEMPLATE = ``; 12 | 13 | @Component({ 14 | selector: `app-${NAME}`, 15 | template: template(CHILD_TEMPLATE), 16 | styleUrls: ['./../change-detection.component.scss'], 17 | providers: [ColorService], 18 | changeDetection: CD_STRATEGY 19 | }) 20 | export class Comp_1_x_3_3_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 21 | 22 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 23 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-3-4.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-3-4'; 9 | const LEVEL = 4; 10 | const CD_STRATEGY = ChangeDetectionStrategy.OnPush; 11 | const CHILD_TEMPLATE = ``; 12 | 13 | @Component({ 14 | selector: `app-${NAME}`, 15 | template: template(CHILD_TEMPLATE), 16 | styleUrls: ['./../change-detection.component.scss'], 17 | providers: [ColorService], 18 | changeDetection: CD_STRATEGY 19 | }) 20 | export class Comp_1_x_3_4_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 21 | 22 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 23 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-3.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-3'; 9 | const LEVEL = 3; 10 | const CD_STRATEGY = ChangeDetectionStrategy.Default; 11 | const CHILD_TEMPLATE = ` 12 | 13 | 14 | `; 15 | 16 | @Component({ 17 | selector: `app-${NAME}`, 18 | template: template(CHILD_TEMPLATE), 19 | styleUrls: ['./../change-detection.component.scss'], 20 | providers: [ColorService], 21 | changeDetection: CD_STRATEGY 22 | }) 23 | export class Comp_1_x_3_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 24 | 25 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 26 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-4-1.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-4-1'; 9 | const LEVEL = 4; 10 | const CD_STRATEGY = ChangeDetectionStrategy.Default; 11 | const CHILD_TEMPLATE = ``; 12 | 13 | @Component({ 14 | selector: `app-${NAME}`, 15 | template: template(CHILD_TEMPLATE), 16 | styleUrls: ['./../change-detection.component.scss'], 17 | providers: [ColorService], 18 | changeDetection: CD_STRATEGY 19 | }) 20 | export class Comp_1_x_4_1_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 21 | 22 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 23 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-4-2.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-4-2'; 9 | const LEVEL = 4; 10 | const CD_STRATEGY = ChangeDetectionStrategy.OnPush; 11 | const CHILD_TEMPLATE = ``; 12 | 13 | @Component({ 14 | selector: `app-${NAME}`, 15 | template: template(CHILD_TEMPLATE), 16 | styleUrls: ['./../change-detection.component.scss'], 17 | providers: [ColorService], 18 | changeDetection: CD_STRATEGY 19 | }) 20 | export class Comp_1_x_4_2_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 21 | 22 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 23 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-4-3.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-4-3'; 9 | const LEVEL = 4; 10 | const CD_STRATEGY = ChangeDetectionStrategy.Default; 11 | const CHILD_TEMPLATE = ``; 12 | 13 | @Component({ 14 | selector: `app-${NAME}`, 15 | template: template(CHILD_TEMPLATE), 16 | styleUrls: ['./../change-detection.component.scss'], 17 | providers: [ColorService], 18 | changeDetection: CD_STRATEGY 19 | }) 20 | export class Comp_1_x_4_3_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 21 | 22 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 23 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-4-4.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-4-4'; 9 | const LEVEL = 4; 10 | const CD_STRATEGY = ChangeDetectionStrategy.OnPush; 11 | const CHILD_TEMPLATE = ``; 12 | 13 | @Component({ 14 | selector: `app-${NAME}`, 15 | template: template(CHILD_TEMPLATE), 16 | styleUrls: ['./../change-detection.component.scss'], 17 | providers: [ColorService], 18 | changeDetection: CD_STRATEGY 19 | }) 20 | export class Comp_1_x_4_4_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 21 | 22 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 23 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1-x-4.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1-x-4'; 9 | const LEVEL = 3; 10 | const CD_STRATEGY = ChangeDetectionStrategy.OnPush; 11 | const CHILD_TEMPLATE = ` 12 | 13 | 14 | `; 15 | 16 | @Component({ 17 | selector: `app-${NAME}`, 18 | template: template(CHILD_TEMPLATE), 19 | styleUrls: ['./../change-detection.component.scss'], 20 | providers: [ColorService], 21 | changeDetection: CD_STRATEGY 22 | }) 23 | export class Comp_1_x_4_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 24 | 25 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 26 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/app/comp-tree/comp-1.component.ts: -------------------------------------------------------------------------------- 1 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core'; 2 | import { ColorService } from '../color.service'; 3 | import { AbstractChangeDetectionComponent } from '../abstract-change-detection.component'; 4 | import { template } from '../change-detection.component.template'; 5 | import { DirtyCheckColoringService } from '../dirty-check-coloring.service'; 6 | import { ExpandCollapseService } from '../expand-collapse.service'; 7 | 8 | const NAME = 'comp-1'; 9 | const LEVEL = 1; 10 | const CD_STRATEGY = ChangeDetectionStrategy.Default; 11 | const CHILD_TEMPLATE = ` 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | `; 32 | 33 | @Component({ 34 | selector: `app-${NAME}`, 35 | template: template(CHILD_TEMPLATE), 36 | styleUrls: ['./../change-detection.component.scss'], 37 | providers: [ColorService], 38 | changeDetection: CD_STRATEGY 39 | }) 40 | export class Comp_1_Component extends AbstractChangeDetectionComponent { // tslint:disable-line:class-name 41 | 42 | constructor(hostRef: ElementRef, colorService: ColorService, dirtyCheckColoringService: DirtyCheckColoringService, expandCollapseService: ExpandCollapseService, cd: ChangeDetectorRef, zone: NgZone) { 43 | super(NAME, LEVEL, hostRef, colorService, dirtyCheckColoringService, expandCollapseService, cd, zone, CD_STRATEGY); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/app/delayed-scheduler.service.ts: -------------------------------------------------------------------------------- 1 | import { NgZone } from '@angular/core'; 2 | import { Subject, Observable } from 'rxjs'; 3 | 4 | export type Fn = () => void; 5 | 6 | /** 7 | * Executes the scheduled functions in sequence with a specific delay. 8 | */ 9 | export class DelayedScheduler { 10 | 11 | private static readonly DELAY = 75; 12 | 13 | private _queue: Fn[] = []; 14 | private _done$ = new Subject(); 15 | 16 | constructor(private _zone: NgZone) { 17 | } 18 | 19 | public schedule(fn: Fn): void { 20 | this._queue.push(fn); 21 | if (this._queue.length === 1) { 22 | this.scheduleInternal(0); 23 | } 24 | } 25 | 26 | public get done$(): Observable { 27 | return this._done$.asObservable(); 28 | } 29 | 30 | private onTick(): void { 31 | this._queue.shift()(); 32 | if (this._queue.length > 0) { 33 | this.scheduleInternal(DelayedScheduler.DELAY); 34 | } else { 35 | this._done$.next(); 36 | } 37 | } 38 | 39 | private scheduleInternal(millis: number): void { 40 | this._zone.runOutsideAngular(() => { 41 | setTimeout(this.onTick.bind(this), millis); 42 | }); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/app/dirty-check-coloring.service.ts: -------------------------------------------------------------------------------- 1 | import { ElementRef, Injectable, NgZone } from '@angular/core'; 2 | import { Subject, Observable, BehaviorSubject } from 'rxjs'; 3 | import { delay, delayWhen, distinctUntilChanged, take } from 'rxjs/operators'; 4 | import { DelayedScheduler } from './delayed-scheduler.service'; 5 | 6 | /** 7 | * Controls coloring of dirty checked components. 8 | */ 9 | @Injectable() 10 | export class DirtyCheckColoringService { 11 | 12 | private _clearColoring$ = new Subject(); 13 | private _autoClearColoring = true; 14 | private _delayedScheduler: DelayedScheduler; 15 | private _busy$ = new BehaviorSubject(false); 16 | 17 | constructor(private _zone: NgZone) { 18 | this._delayedScheduler = new DelayedScheduler(_zone); 19 | } 20 | 21 | public clearColoring(): void { 22 | this._clearColoring$.next(); 23 | } 24 | 25 | public setAutoClearColoring(autoClear: boolean): void { 26 | this._autoClearColoring = autoClear; 27 | if (autoClear) { 28 | this.clearColoring(); 29 | } 30 | } 31 | 32 | public isAutoClearColoring(): boolean { 33 | return this._autoClearColoring; 34 | } 35 | 36 | public colorDirtyCheck(elementRef: ElementRef): void { 37 | this._busy$.next(true); 38 | this._zone.runOutsideAngular(() => { 39 | const element = elementRef.nativeElement as HTMLElement; 40 | const cssClass = 'dirty-check'; 41 | this._delayedScheduler.schedule(() => { 42 | element.classList.add(cssClass); 43 | }); 44 | 45 | if (this._autoClearColoring) { 46 | this._delayedScheduler.done$.pipe( 47 | take(1), // subscribe once 48 | delay(1000) // clear after 1s 49 | ) 50 | .subscribe(() => { 51 | element.classList.remove(cssClass); 52 | this._busy$.next(false); 53 | }); 54 | } else { 55 | this._delayedScheduler.done$.pipe( 56 | take(1), // subscribe once 57 | delayWhen(() => this._clearColoring$) 58 | ) 59 | .subscribe(() => { 60 | element.classList.remove(cssClass); 61 | this._busy$.next(false); 62 | }); 63 | } 64 | }); 65 | } 66 | 67 | public get busy$(): Observable { 68 | return this._busy$.asObservable().pipe(distinctUntilChanged()); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/app/expand-collapse.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { BehaviorSubject, Observable } from 'rxjs'; 3 | 4 | @Injectable() 5 | export class ExpandCollapseService { 6 | 7 | private _contentChildren$ = new BehaviorSubject(State.Collapse); 8 | 9 | public toggleContentChildren(): void { 10 | this._contentChildren$.next((this._contentChildren$.getValue() === State.Expand) ? State.Collapse : State.Expand); 11 | } 12 | 13 | public get contentChildren$(): Observable { 14 | return this._contentChildren$.asObservable(); 15 | } 16 | } 17 | 18 | export enum State { 19 | Expand, Collapse 20 | } 21 | -------------------------------------------------------------------------------- /src/app/number-holder.ts: -------------------------------------------------------------------------------- 1 | export class NumberHolder { 2 | public value: number; 3 | } 4 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danielwiehl/edu-angular-change-detection/bdea93d95dbd6ac50030c83efe59e60e1b87975c/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danielwiehl/edu-angular-change-detection/bdea93d95dbd6ac50030c83efe59e60e1b87975c/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | EDU - Understand Angular Change Detection (Angular 8.x) 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /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.ts'; 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 | body { 4 | font-family: 'Arial', sans-serif; 5 | box-sizing: border-box; 6 | } 7 | 8 | app-comp-1 { 9 | > div.component > div.children { 10 | flex-direction: column !important; 11 | justify-content: center; 12 | } 13 | width: calc(100% - 40px); 14 | } 15 | 16 | button { 17 | border: 1px solid darkgray; 18 | background-color: white; 19 | box-shadow: none; 20 | border-radius: 0; 21 | } 22 | 23 | button.emphasize { 24 | background-color: #ddffcc; 25 | border-color: #226600; 26 | color: #226600; 27 | } 28 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /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/**/*.ts" 13 | ], 14 | "exclude": [ 15 | "src/test.ts", 16 | "src/**/*.spec.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /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": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | }, 22 | "angularCompilerOptions": { 23 | "fullTemplateTypeCheck": true, 24 | "strictInjectionParameters": true 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "array-type": false, 5 | "arrow-parens": false, 6 | "deprecation": { 7 | "severity": "warning" 8 | }, 9 | "component-class-suffix": true, 10 | "contextual-lifecycle": true, 11 | "directive-class-suffix": true, 12 | "variable-name": false, 13 | "directive-selector": [ 14 | true, 15 | "attribute", 16 | "app", 17 | "camelCase" 18 | ], 19 | "component-selector": [ 20 | true, 21 | "element", 22 | "app", 23 | "kebab-case" 24 | ], 25 | "import-blacklist": [ 26 | true, 27 | "rxjs/Rx" 28 | ], 29 | "interface-name": false, 30 | "max-classes-per-file": false, 31 | "max-line-length": [ 32 | false, 33 | 140 34 | ], 35 | "member-access": false, 36 | "member-ordering": [ 37 | true, 38 | { 39 | "order": [ 40 | "static-field", 41 | "instance-field", 42 | "static-method", 43 | "instance-method" 44 | ] 45 | } 46 | ], 47 | "no-consecutive-blank-lines": false, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-empty": false, 57 | "no-inferrable-types": [ 58 | true, 59 | "ignore-params" 60 | ], 61 | "no-non-null-assertion": true, 62 | "no-redundant-jsdoc": true, 63 | "no-switch-case-fall-through": true, 64 | "no-var-requires": false, 65 | "object-literal-key-quotes": [ 66 | true, 67 | "as-needed" 68 | ], 69 | "object-literal-sort-keys": false, 70 | "ordered-imports": false, 71 | "quotemark": [ 72 | true, 73 | "single" 74 | ], 75 | "trailing-comma": false, 76 | "no-conflicting-lifecycle": false, 77 | "no-host-metadata-property": true, 78 | "no-input-rename": true, 79 | "no-inputs-metadata-property": true, 80 | "no-output-native": true, 81 | "no-output-on-prefix": true, 82 | "no-output-rename": true, 83 | "no-outputs-metadata-property": true, 84 | "template-banana-in-box": true, 85 | "template-no-negated-async": true, 86 | "use-lifecycle-interface": true, 87 | "use-pipe-transform-interface": true 88 | }, 89 | "rulesDirectory": [ 90 | "codelyzer" 91 | ] 92 | } 93 | --------------------------------------------------------------------------------