├── .gitignore ├── LICENSE ├── README.md ├── Rethinking Reactivity.pdf ├── angular.json ├── browserslist ├── package.json ├── src ├── app │ ├── app.component.scss │ ├── app.component.ts │ └── app.module.ts ├── assets │ └── .gitkeep ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts └── styles.scss ├── tsconfig.app.json ├── tsconfig.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Mike Ryan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rethinking Reactivity with Ivy 2 | 3 | ## AngularConnect 2019 4 | 5 | Link to the talk: https://youtu.be/rz-rcaGXhGk 6 | 7 | Follow me on Twitter [@MikeRyanDev](https://twitter.com/mikeryandev) 8 | -------------------------------------------------------------------------------- /Rethinking Reactivity.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MikeRyanDev/rethinking-reactivity-angularconnect2019/7ff2882b9765c6794b143e4d4932dffc9fa68027/Rethinking Reactivity.pdf -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "rethinking-reactivity": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "inlineTemplate": true, 11 | "inlineStyle": true, 12 | "style": "scss" 13 | } 14 | }, 15 | "root": "", 16 | "sourceRoot": "src", 17 | "prefix": "app", 18 | "architect": { 19 | "build": { 20 | "builder": "@angular-devkit/build-angular:browser", 21 | "options": { 22 | "outputPath": "dist/rethinking-reactivity", 23 | "index": "src/index.html", 24 | "main": "src/main.ts", 25 | "polyfills": "src/polyfills.ts", 26 | "tsConfig": "tsconfig.app.json", 27 | "aot": true, 28 | "assets": [ 29 | "src/favicon.ico", 30 | "src/assets" 31 | ], 32 | "styles": [ 33 | "src/styles.scss" 34 | ], 35 | "scripts": [] 36 | }, 37 | "configurations": { 38 | "production": { 39 | "fileReplacements": [ 40 | { 41 | "replace": "src/environments/environment.ts", 42 | "with": "src/environments/environment.prod.ts" 43 | } 44 | ], 45 | "optimization": true, 46 | "outputHashing": "all", 47 | "sourceMap": false, 48 | "extractCss": true, 49 | "namedChunks": false, 50 | "extractLicenses": true, 51 | "vendorChunk": false, 52 | "buildOptimizer": true, 53 | "budgets": [ 54 | { 55 | "type": "initial", 56 | "maximumWarning": "2mb", 57 | "maximumError": "5mb" 58 | }, 59 | { 60 | "type": "anyComponentStyle", 61 | "maximumWarning": "6kb", 62 | "maximumError": "10kb" 63 | } 64 | ] 65 | } 66 | } 67 | }, 68 | "serve": { 69 | "builder": "@angular-devkit/build-angular:dev-server", 70 | "options": { 71 | "browserTarget": "rethinking-reactivity:build" 72 | }, 73 | "configurations": { 74 | "production": { 75 | "browserTarget": "rethinking-reactivity:build:production" 76 | } 77 | } 78 | }, 79 | "extract-i18n": { 80 | "builder": "@angular-devkit/build-angular:extract-i18n", 81 | "options": { 82 | "browserTarget": "rethinking-reactivity:build" 83 | } 84 | } 85 | } 86 | }}, 87 | "defaultProject": "rethinking-reactivity" 88 | } -------------------------------------------------------------------------------- /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'. -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rethinking-reactivity", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~9.0.0-next.7", 15 | "@angular/common": "~9.0.0-next.7", 16 | "@angular/compiler": "~9.0.0-next.7", 17 | "@angular/core": "~9.0.0-next.7", 18 | "@angular/forms": "~9.0.0-next.7", 19 | "@angular/platform-browser": "~9.0.0-next.7", 20 | "@angular/platform-browser-dynamic": "~9.0.0-next.7", 21 | "@angular/router": "~9.0.0-next.7", 22 | "rxjs": "~6.5.3", 23 | "tslib": "^1.10.0", 24 | "zone.js": "~0.10.2" 25 | }, 26 | "devDependencies": { 27 | "@angular-devkit/build-angular": "~0.900.0-next.5", 28 | "@angular/cli": "~9.0.0-next.5", 29 | "@angular/compiler-cli": "~9.0.0-next.7", 30 | "@angular/language-service": "~9.0.0-next.7", 31 | "@types/node": "~8.9.4", 32 | "ts-node": "~7.0.0", 33 | "tslint": "~5.15.0", 34 | "typescript": "~3.5.3" 35 | } 36 | } -------------------------------------------------------------------------------- /src/app/app.component.scss: -------------------------------------------------------------------------------- 1 | :host { 2 | display: grid; 3 | padding: 80px; 4 | 5 | button { 6 | background-color: red; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Component, 3 | OnInit, 4 | OnDestroy, 5 | ɵmarkDirty as markDirty 6 | } from "@angular/core"; 7 | import { Subject, Observable, from, ReplaySubject, concat } from "rxjs"; 8 | import { scan, startWith, mergeMap, tap, takeUntil } from "rxjs/operators"; 9 | 10 | type ObservableDictionary = { 11 | [P in keyof T]: Observable; 12 | }; 13 | 14 | const OnInitSubject = Symbol("OnInitSubject"); 15 | const OnDestroySubject = Symbol("OnDestroySubject"); 16 | export abstract class ReactiveComponent implements OnInit, OnDestroy { 17 | private [OnInitSubject] = new ReplaySubject(1); 18 | private [OnDestroySubject] = new ReplaySubject(1); 19 | 20 | public get onInit$() { 21 | return this[OnInitSubject].asObservable(); 22 | } 23 | 24 | public get onDestroy$() { 25 | return this[OnDestroySubject].asObservable(); 26 | } 27 | 28 | connect(sources: ObservableDictionary): T { 29 | const sink = {} as T; 30 | const sourceKeys = Object.keys(sources) as (keyof T)[]; 31 | const updateSink$ = from(sourceKeys).pipe( 32 | mergeMap(sourceKey => { 33 | const source$ = sources[sourceKey]; 34 | 35 | return source$.pipe( 36 | tap((sinkValue: any) => { 37 | sink[sourceKey] = sinkValue; 38 | }) 39 | ); 40 | }) 41 | ); 42 | 43 | concat(this.onInit$, updateSink$) 44 | .pipe(takeUntil(this.onDestroy$)) 45 | .subscribe(() => markDirty(this)); 46 | 47 | return sink; 48 | } 49 | 50 | ngOnInit() { 51 | this[OnInitSubject].next(true); 52 | this[OnInitSubject].complete(); 53 | } 54 | 55 | ngOnDestroy() { 56 | this[OnDestroySubject].next(true); 57 | this[OnDestroySubject].complete(); 58 | } 59 | } 60 | 61 | @Component({ 62 | selector: "app-root", 63 | template: ` 64 |
{{ state.count }}
65 |
Count
66 | 71 | 76 | ` 77 | }) 78 | export class AppComponent extends ReactiveComponent { 79 | values$ = new Subject(); 80 | state = this.connect({ 81 | count: this.values$.pipe( 82 | startWith(0), 83 | scan((count, next) => count + next, 0) 84 | ) 85 | }); 86 | 87 | pushValue(value: number) { 88 | this.values$.next(value); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from "@angular/core"; 2 | import { BrowserModule } from "@angular/platform-browser"; 3 | import { AppComponent } from "./app.component"; 4 | 5 | @NgModule({ 6 | imports: [BrowserModule], 7 | declarations: [AppComponent], 8 | bootstrap: [AppComponent] 9 | }) 10 | export class AppModule {} 11 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MikeRyanDev/rethinking-reactivity-angularconnect2019/7ff2882b9765c6794b143e4d4932dffc9fa68027/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/MikeRyanDev/rethinking-reactivity-angularconnect2019/7ff2882b9765c6794b143e4d4932dffc9fa68027/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | RethinkingReactivity 6 | 7 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { 2 | enableProdMode, 3 | ɵrenderComponent as renderComponent, 4 | ɵLifecycleHooksFeature as LifecycleHooksFeature 5 | } from "@angular/core"; 6 | import { platformBrowserDynamic } from "@angular/platform-browser-dynamic"; 7 | import { environment } from "./environments/environment"; 8 | import { AppComponent } from "./app/app.component"; 9 | import { AppModule } from "./app/app.module"; 10 | 11 | if (environment.production) { 12 | enableProdMode(); 13 | } 14 | 15 | // renderComponent(AppComponent, { 16 | // hostFeatures: [LifecycleHooksFeature] 17 | // }); 18 | 19 | platformBrowserDynamic() 20 | .bootstrapModule(AppModule, { ngZone: "noop" }) 21 | .catch(console.error); 22 | -------------------------------------------------------------------------------- /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 | * APPLICATION IMPORTS 62 | */ 63 | -------------------------------------------------------------------------------- /src/styles.scss: -------------------------------------------------------------------------------- 1 | app-root { 2 | font-family: "Raleway", sans-serif; 3 | display: grid; 4 | padding: 80px; 5 | max-width: 400px; 6 | margin: 0 auto; 7 | grid-template-areas: 8 | "decrement count increment" 9 | "decrement countLabel increment"; 10 | grid-template-columns: 100px 200px 100px; 11 | justify-content: center; 12 | align-items: center; 13 | 14 | .decrement { 15 | grid-area: decrement; 16 | } 17 | .increment { 18 | grid-area: increment; 19 | } 20 | .count { 21 | grid-area: count; 22 | font-size: 128px; 23 | text-align: center; 24 | } 25 | .countLabel { 26 | grid-area: countLabel; 27 | text-align: center; 28 | } 29 | 30 | button { 31 | background-color: rgba(0, 0, 0, 0.08); 32 | border-radius: 35px; 33 | width: 70px; 34 | height: 70px; 35 | display: flex; 36 | justify-self: center; 37 | align-content: center; 38 | justify-content: center; 39 | border: none; 40 | outline: none; 41 | cursor: pointer; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.d.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": ["node_modules/@types"], 15 | "lib": ["es2018", "dom"] 16 | }, 17 | "angularCompilerOptions": { 18 | "fullTemplateTypeCheck": true, 19 | "strictInjectionParameters": true 20 | } 21 | } 22 | --------------------------------------------------------------------------------