├── .editorconfig ├── .firebaserc ├── .gitignore ├── README.md ├── angular.json ├── e2e ├── app.e2e-spec.ts ├── app.po.ts └── tsconfig.json ├── firebase.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── protractor.conf.js ├── src ├── app │ ├── app.component.css │ ├── app.component.html │ ├── app.component.ts │ ├── app.module.ts │ ├── app.routing.ts │ ├── circle │ │ └── circle.component.ts │ ├── examples │ │ ├── 00-basic-sequence │ │ │ └── basic-sequence.component.ts │ │ ├── 01-maintaining-state │ │ │ └── maintaining-state.component.ts │ │ ├── 02-merging-streams │ │ │ └── merging-streams.component.ts │ │ ├── 03-map-to-functions │ │ │ └── map-to-functions.component.ts │ │ ├── 04-triggers │ │ │ └── triggers.component.ts │ │ ├── 05-stream-origin │ │ │ └── stream-origin.component.ts │ │ ├── 06-simple-animation │ │ │ └── simple-animation.component.ts │ │ ├── 07-animation │ │ │ └── animation.component.ts │ │ ├── 08-counter │ │ │ ├── counter-client.component.ts │ │ │ ├── counter-master.component.ts │ │ │ └── counter.component.ts │ │ ├── 09-slideshow │ │ │ ├── images.ts │ │ │ ├── slideshow-client.component.ts │ │ │ ├── slideshow-master.component.ts │ │ │ └── slideshow.component.ts │ │ ├── 10-location │ │ │ ├── location-client.component.ts │ │ │ ├── location-master.component.ts │ │ │ └── location.component.ts │ │ ├── 11-map │ │ │ ├── map-client.component.ts │ │ │ ├── map-master.component.ts │ │ │ └── map.component.ts │ │ ├── 12-annotate │ │ │ ├── annotate-client.component.ts │ │ │ ├── annotate-master.component.ts │ │ │ ├── annotate.component.ts │ │ │ └── doc.component.ts │ │ ├── 13-game │ │ │ ├── game-client.component.ts │ │ │ ├── game-master.component.ts │ │ │ └── game.component.ts │ │ ├── 14-slider │ │ │ ├── slider-client.component.ts │ │ │ ├── slider-master.component.ts │ │ │ └── slider.component.ts │ │ └── index.ts │ ├── firebase.conf.example.ts │ ├── index.ts │ ├── line │ │ └── line.component.ts │ └── shot │ │ └── shot.component.ts ├── assets │ ├── .gitkeep │ ├── .npmignore │ ├── lion-roar.jpg │ ├── london-map.jpg │ ├── maxres.jpg │ ├── maxresdefault.jpg │ ├── pin.png │ ├── spaceship.png │ └── stars.jpg ├── environments │ ├── environment.dev.ts │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── styles.css ├── test.ts ├── tsconfig.json └── typings.d.ts ├── tslint.json └── yarn.lock /.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 | end_of_line = lf 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | [*.md] 13 | max_line_length = 0 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /.firebaserc: -------------------------------------------------------------------------------- 1 | { 2 | "projects": { 3 | "default": "rxjsbeastmode" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | 7 | # dependencies 8 | /node_modules 9 | /bower_components 10 | 11 | # firebase config 12 | /src/app/firebase.conf.ts 13 | 14 | # IDEs and editors 15 | /.idea 16 | .project 17 | .classpath 18 | *.launch 19 | .settings/ 20 | 21 | # misc 22 | /.sass-cache 23 | /connect.lock 24 | /coverage/* 25 | /libpeerconnection.log 26 | npm-debug.log 27 | testem.log 28 | /typings 29 | 30 | # e2e 31 | /e2e/*.js 32 | /e2e/*.map 33 | 34 | #System Files 35 | .DS_Store 36 | Thumbs.db 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![image](https://cloud.githubusercontent.com/assets/1544557/19167633/6cf42cc4-8bc1-11e6-98b9-8645f01bd5ce.png) 2 | 3 | # RxJS Examples in Angular 2 4 | 5 | This project contains several mini-apps, showcasing RxJS observables and operators and how they can be combined to perform tasks of varying difficulty and awesomeness. Also included are several, more complex "real-world" examples that combine the power of observables with a realtime database from Firebase. Below is a link to a blog post with the AngularConnect talk and slides that facilitated the creation of this project. Oh and there are also some great resources for reactive programming. You're welcome. 6 | 7 | [#GoBeastModeOrGoHome](http://onehungrymind.com/realtime-reactive-interfaces-angular-firebase/) 8 | 9 | ## Prerequisites 10 | * You will need to have NodeJS and NPM installed from [nodejs.org](https://nodejs.org) 11 | * You will need a Google account (generally associated with Gmail) 12 | 13 | ## Getting the code 14 | Run the following in the terminal or command prompt to download and enter the project: 15 | ```bash 16 | git clone https://github.com/onehungrymind/angular2-rxjs-examples.git 17 | cd angular2-rxjs-examples 18 | ``` 19 | ## Setting up a Firebase account 20 | Simply navigate to https://firebase.google.com/ and click the "GET STARTED FOR FREE" button. Once you have signed in via Google, you will have access to your Firebase console. 21 | 22 | ## Setting up Firebase in the Angular app 23 | From your [Firebase console](https://console.firebase.google.com/), click "CREATE NEW PROJECT". Then fill in the necessary details and go to that project's dashboard. Then click the "Add Firebase To Your Web App" button toward the top-right of the screen. 24 | 25 | Open the project in a code editor and copy `src > app > firebase.conf.example.ts` to `src > app > firebase.conf.ts`. Then fill in `firebase.conf.ts` with the information showing in your project's dashboard (note that "storageBucket" is optional and that "messagingSenderId" is not used at all). Last but not least, save the file. 26 | 27 | ## Running the app 28 | Run the following commands in the project directory to install dependencies and start the app: 29 | ```bash 30 | npm i 31 | npm start # or ng serve 32 | ``` 33 | Then navigate to http://localhost:4200 and the app will be running. 34 | 35 | ## Code scaffolding 36 | 37 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive/pipe/service/class`. 38 | 39 | ## Build 40 | 41 | 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. 42 | 43 | ## Running unit tests 44 | 45 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 46 | 47 | ## Running end-to-end tests 48 | 49 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 50 | Before running the tests make sure you are serving the app via `ng serve`. 51 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "angular2-rxjs-examples": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "architect": { 11 | "build": { 12 | "builder": "@angular-devkit/build-angular:browser", 13 | "options": { 14 | "outputPath": "dist", 15 | "index": "src/index.html", 16 | "main": "src/main.ts", 17 | "tsConfig": "src/tsconfig.json", 18 | "assets": [ 19 | "src/assets" 20 | ], 21 | "styles": [ 22 | "src/styles.css" 23 | ], 24 | "scripts": [ 25 | "node_modules/jquery/dist/jquery.js", 26 | "node_modules/gsap/src/minified/TweenMax.min.js" 27 | ] 28 | }, 29 | "configurations": { 30 | "source": { 31 | "fileReplacements": [ 32 | { 33 | "replace": "src/undefined", 34 | "with": "src/environments/environment.ts" 35 | } 36 | ] 37 | }, 38 | "production": { 39 | "optimization": true, 40 | "outputHashing": "all", 41 | "sourceMap": false, 42 | "extractCss": true, 43 | "namedChunks": false, 44 | "aot": true, 45 | "extractLicenses": true, 46 | "vendorChunk": false, 47 | "buildOptimizer": true, 48 | "fileReplacements": [ 49 | { 50 | "replace": "src/undefined", 51 | "with": "src/environments/environment.prod.ts" 52 | } 53 | ] 54 | }, 55 | "dev": { 56 | "fileReplacements": [ 57 | { 58 | "replace": "src/undefined", 59 | "with": "src/environments/environment.dev.ts" 60 | } 61 | ] 62 | } 63 | } 64 | }, 65 | "serve": { 66 | "builder": "@angular-devkit/build-angular:dev-server", 67 | "options": { 68 | "browserTarget": "angular2-rxjs-examples:build" 69 | }, 70 | "configurations": { 71 | "source": { 72 | "browserTarget": "angular2-rxjs-examples:build:source" 73 | }, 74 | "production": { 75 | "browserTarget": "angular2-rxjs-examples:build:production" 76 | }, 77 | "dev": { 78 | "browserTarget": "angular2-rxjs-examples:build:dev" 79 | } 80 | } 81 | }, 82 | "extract-i18n": { 83 | "builder": "@angular-devkit/build-angular:extract-i18n", 84 | "options": { 85 | "browserTarget": "angular2-rxjs-examples:build" 86 | } 87 | }, 88 | "test": { 89 | "builder": "@angular-devkit/build-angular:karma", 90 | "options": { 91 | "main": "src/test.ts", 92 | "karmaConfig": "./karma.conf.js", 93 | "scripts": [ 94 | "node_modules/jquery/dist/jquery.js", 95 | "node_modules/gsap/src/minified/TweenMax.min.js" 96 | ], 97 | "styles": [ 98 | "src/styles.css" 99 | ], 100 | "assets": [ 101 | "src/assets" 102 | ] 103 | } 104 | }, 105 | "lint": { 106 | "builder": "@angular-devkit/build-angular:tslint", 107 | "options": { 108 | "tsConfig": [], 109 | "exclude": [] 110 | } 111 | } 112 | } 113 | }, 114 | "angular2-rxjs-examples-e2e": { 115 | "root": "", 116 | "sourceRoot": "e2e", 117 | "projectType": "application", 118 | "architect": { 119 | "e2e": { 120 | "builder": "@angular-devkit/build-angular:protractor", 121 | "options": { 122 | "protractorConfig": "./protractor.conf.js", 123 | "devServerTarget": "angular2-rxjs-examples:serve" 124 | } 125 | }, 126 | "lint": { 127 | "builder": "@angular-devkit/build-angular:tslint", 128 | "options": { 129 | "tsConfig": [], 130 | "exclude": [] 131 | } 132 | } 133 | } 134 | } 135 | }, 136 | "defaultProject": "angular2-rxjs-examples", 137 | "schematics": { 138 | "@schematics/angular:component": { 139 | "prefix": "app", 140 | "styleext": "css" 141 | }, 142 | "@schematics/angular:directive": { 143 | "prefix": "app" 144 | } 145 | } 146 | } -------------------------------------------------------------------------------- /e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Angular2RxjsExamplesPage } from './app.po'; 2 | 3 | describe('angular2-rxjs-examples App', function() { 4 | let page: Angular2RxjsExamplesPage; 5 | 6 | beforeEach(() => { 7 | page = new Angular2RxjsExamplesPage(); 8 | }); 9 | 10 | it('should display message saying app works', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('app works!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, element, by } from 'protractor/globals'; 2 | 3 | export class Angular2RxjsExamplesPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "declaration": false, 5 | "emitDecoratorMetadata": true, 6 | "experimentalDecorators": true, 7 | "module": "commonjs", 8 | "moduleResolution": "node", 9 | "outDir": "../dist/out-tsc-e2e", 10 | "sourceMap": true, 11 | "target": "es5", 12 | "typeRoots": [ 13 | "../node_modules/@types" 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /firebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "public": "dist", 3 | "rewrites": [ { 4 | "source": "**", 5 | "destination": "/index.html" 6 | } ] 7 | } 8 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/0.13/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: './', 7 | frameworks: ['jasmine', 'angular-cli'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-remap-istanbul'), 12 | require('angular-cli/plugins/karma') 13 | ], 14 | files: [ 15 | 16 | ], 17 | preprocessors: { 18 | './src/test.ts': ['angular-cli'] 19 | }, 20 | remapIstanbulReporter: { 21 | dir: require('path').join(__dirname, 'coverage'), reports: { 22 | html: 'coverage', 23 | lcovonly: './coverage/coverage.lcov' 24 | } 25 | }, 26 | ); 27 | }; 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular2-rxjs-examples", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "angular-cli": {}, 6 | "scripts": { 7 | "start": "ng serve", 8 | "lint": "tslint \"src/**/*.ts\"", 9 | "test": "ng test", 10 | "pree2e": "webdriver-manager update", 11 | "e2e": "protractor" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/animations": "^6.0.6", 16 | "@angular/cdk": "^6.3.0", 17 | "@angular/common": "6.0.6", 18 | "@angular/compiler": "6.0.6", 19 | "@angular/core": "6.0.6", 20 | "@angular/forms": "6.0.6", 21 | "@angular/http": "6.0.6", 22 | "@angular/material": "^6.3.0", 23 | "@angular/platform-browser": "6.0.6", 24 | "@angular/platform-browser-dynamic": "6.0.6", 25 | "@angular/router": "6.0.6", 26 | "@types/firebase": "^3.2.1", 27 | "@types/jquery": "^3.3.4", 28 | "angularfire2": "^5.0.0-rc.11", 29 | "core-js": "^2.5.7", 30 | "firebase": "^5.0.4", 31 | "gsap": "^2.0.1", 32 | "hammerjs": "^2.0.8", 33 | "jquery": "^3.3.1", 34 | "rxjs": "6.2.1", 35 | "ts-helpers": "^1.1.2", 36 | "zone.js": "0.8.26" 37 | }, 38 | "devDependencies": { 39 | "@angular-devkit/build-angular": "~0.6.8", 40 | "@angular/cli": "^6.0.8", 41 | "@angular/compiler-cli": "^6.0.6", 42 | "@types/core-js": "^2.5.0", 43 | "@types/hammerjs": "^2.0.35", 44 | "@types/jasmine": "^2.8.8", 45 | "codelyzer": "~4.3.0", 46 | "jasmine-core": "3.1.0", 47 | "jasmine-spec-reporter": "4.2.1", 48 | "karma": "2.0.4", 49 | "karma-chrome-launcher": "2.2.0", 50 | "karma-jasmine": "1.1.2", 51 | "karma-remap-istanbul": "^0.6.0", 52 | "protractor": "5.3.2", 53 | "ts-node": "6.1.2", 54 | "tslint": "5.10.0", 55 | "typescript": "2.7.2" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/docs/referenceConf.js 3 | 4 | /*global jasmine */ 5 | var SpecReporter = require('jasmine-spec-reporter'); 6 | 7 | exports.config = { 8 | allScriptsTimeout: 11000, 9 | specs: [ 10 | './e2e/**/*.e2e-spec.ts' 11 | ], 12 | capabilities: { 13 | 'browserName': 'chrome' 14 | }, 15 | directConnect: true, 16 | baseUrl: 'http://localhost:4200/', 17 | framework: 'jasmine', 18 | jasmineNodeOpts: { 19 | showColors: true, 20 | defaultTimeoutInterval: 30000, 21 | print: function() {} 22 | }, 23 | useAllAngular2AppRoots: true, 24 | beforeLaunch: function() { 25 | require('ts-node').register({ 26 | project: 'e2e' 27 | }); 28 | }, 29 | onPrepare: function() { 30 | jasmine.getEnv().addReporter(new SpecReporter()); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- 1 | mat-toolbar { 2 | position: relative; 3 | z-index:1; 4 | } 5 | 6 | .app-content { 7 | padding: 20px; 8 | 9 | /* 100% - header height - element padding */ 10 | height: calc(100% - 64px - 40px); 11 | overflow: hidden; 12 | } 13 | 14 | .app-sidenav { 15 | padding: 10px; 16 | min-width: 200px; 17 | } 18 | 19 | .app-toolbar-menu { 20 | padding: 0 14px 0 14px; 21 | color: white; 22 | } 23 | 24 | .app-icon-button { 25 | box-shadow: none; 26 | user-select: none; 27 | background: none; 28 | border: none; 29 | cursor: pointer; 30 | filter: none; 31 | font-weight: normal; 32 | height: auto; 33 | line-height: inherit; 34 | margin: 0; 35 | min-width: 0; 36 | padding: 0; 37 | text-align: left; 38 | text-decoration: none; 39 | display: flex; 40 | } 41 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | {{example.name}} 9 | 10 | 11 | 12 | 13 | 14 | 17 | RxJS Examples 18 | 19 | 20 |
21 | 22 |
23 |
24 | 25 | 34 | 35 | 40 | 41 | 48 | 49 | 50 | 58 | 59 | 60 | 70 | 71 | 77 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import 'gsap'; 3 | 4 | @Component({ 5 | selector: 'app-root', 6 | templateUrl: './app.component.html', 7 | styleUrls: ['./app.component.css'] 8 | }) 9 | export class AppComponent { 10 | examples = [ 11 | { path: '/examples/00-basic-sequence', name: 'Basic Sequence'}, 12 | { path: '/examples/01-maintaining-state', name: 'Maintaining State'}, 13 | { path: '/examples/02-merging-streams', name: 'Merging Streams'}, 14 | { path: '/examples/03-map-to-functions', name: 'Mapping to Functions'}, 15 | { path: '/examples/04-triggers', name: 'Triggers'}, 16 | { path: '/examples/05-stream-origin', name: 'Stream Origins'}, 17 | { path: '/examples/06-simple-animation', name: 'Simple Animation'}, 18 | { path: '/examples/07-animation', name: 'Animation'}, 19 | { path: '/examples/08-counter', name: 'Counter'}, 20 | { path: '/examples/09-slideshow', name: 'Slideshow'}, 21 | { path: '/examples/10-location', name: 'Location'}, 22 | { path: '/examples/11-map', name: 'Map'}, 23 | { path: '/examples/12-annotate', name: 'Annotate'}, 24 | { path: '/examples/13-game', name: 'Game'}, 25 | { path: '/examples/14-slider', name: 'Slider'} 26 | ]; 27 | } 28 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { ReactiveFormsModule } from '@angular/forms'; 4 | import { HttpModule } from '@angular/http'; 5 | 6 | import { AngularFireModule } from 'angularfire2'; 7 | import * as firebase from 'firebase'; 8 | import { firebaseConfig } from './firebase.conf'; 9 | 10 | // import { MdButtonModule } from '@angular2-material/button'; 11 | // import { MdCardModule } from '@angular2-material/card'; 12 | // import { MdIconModule } from '@angular2-material/icon'; 13 | // import { MdListModule } from '@angular2-material/list'; 14 | // import { MdSidenavModule } from '@angular2-material/sidenav'; 15 | // import { MdToolbarModule } from '@angular2-material/toolbar'; 16 | 17 | import { AppComponent } from './app.component'; 18 | import { routing, appRoutingProviders } from './app.routing'; 19 | import { CircleComponent } from './circle/circle.component'; 20 | import { LineComponent } from './line/line.component'; 21 | import { ShotComponent } from './shot/shot.component'; 22 | 23 | 24 | import { 25 | BasicSequenceComponent, 26 | MaintainingStateComponent, 27 | MergingStreamsComponent, 28 | MapToFunctionsComponent, 29 | TriggersComponent, 30 | StreamOriginComponent, 31 | SimpleAnimationComponent, 32 | AnimationComponent, 33 | CounterComponent, 34 | CounterClientComponent, 35 | CounterMasterComponent, 36 | SlideshowComponent, 37 | SlideshowClientComponent, 38 | SlideshowMasterComponent, 39 | LocationComponent, 40 | LocationClientComponent, 41 | LocationMasterComponent, 42 | MapComponent, 43 | MapClientComponent, 44 | MapMasterComponent, 45 | AnnotateComponent, 46 | AnnotateClientComponent, 47 | AnnotateMasterComponent, 48 | DocComponent, 49 | GameComponent, 50 | GameClientComponent, 51 | GameMasterComponent, 52 | SliderComponent, 53 | SliderClientComponent, 54 | SliderMasterComponent 55 | } from './examples'; 56 | import { AngularFirestoreModule } from 'angularfire2/firestore'; 57 | import { AngularFireDatabase, AngularFireDatabaseModule } from 'angularfire2/database'; 58 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 59 | import { MatButtonModule, MatCardModule, MatIconModule, MatListModule, MatSidenavModule, MatToolbarModule } from '@angular/material'; 60 | 61 | @NgModule({ 62 | declarations: [ 63 | AppComponent, 64 | CircleComponent, 65 | LineComponent, 66 | ShotComponent, 67 | BasicSequenceComponent, 68 | BasicSequenceComponent, 69 | MaintainingStateComponent, 70 | MergingStreamsComponent, 71 | MapToFunctionsComponent, 72 | TriggersComponent, 73 | StreamOriginComponent, 74 | SimpleAnimationComponent, 75 | AnimationComponent, 76 | CounterComponent, 77 | CounterClientComponent, 78 | CounterMasterComponent, 79 | SlideshowComponent, 80 | SlideshowClientComponent, 81 | SlideshowMasterComponent, 82 | LocationComponent, 83 | LocationClientComponent, 84 | LocationMasterComponent, 85 | MapComponent, 86 | MapClientComponent, 87 | MapMasterComponent, 88 | AnnotateComponent, 89 | AnnotateClientComponent, 90 | AnnotateMasterComponent, 91 | DocComponent, 92 | GameComponent, 93 | GameClientComponent, 94 | GameMasterComponent, 95 | SliderComponent, 96 | SliderClientComponent, 97 | SliderMasterComponent 98 | ], 99 | imports: [ 100 | BrowserModule, 101 | BrowserAnimationsModule, 102 | AngularFireModule.initializeApp(firebaseConfig), 103 | AngularFireDatabaseModule, 104 | ReactiveFormsModule, 105 | HttpModule, 106 | MatButtonModule, 107 | MatCardModule, 108 | MatIconModule, 109 | MatListModule, 110 | MatSidenavModule, 111 | MatToolbarModule, 112 | routing 113 | ], 114 | providers: [ 115 | appRoutingProviders 116 | ], 117 | bootstrap: [AppComponent] 118 | }) 119 | export class AppModule { 120 | } 121 | -------------------------------------------------------------------------------- /src/app/app.routing.ts: -------------------------------------------------------------------------------- 1 | import { Routes, RouterModule } from '@angular/router'; 2 | import { ModuleWithProviders } from "@angular/core"; 3 | import { 4 | BasicSequenceComponent, 5 | MaintainingStateComponent, 6 | MergingStreamsComponent, 7 | MapToFunctionsComponent, 8 | TriggersComponent, 9 | StreamOriginComponent, 10 | SimpleAnimationComponent, 11 | AnimationComponent, 12 | CounterComponent, 13 | SlideshowComponent, 14 | LocationComponent, 15 | MapComponent, 16 | AnnotateComponent, 17 | GameComponent, 18 | SliderComponent 19 | } from './examples'; 20 | 21 | const appRoutes: Routes = [ 22 | { 23 | path: '', 24 | redirectTo: '/examples/00-basic-sequence', 25 | pathMatch: 'full' 26 | }, 27 | { path: 'examples/00-basic-sequence', component: BasicSequenceComponent }, 28 | { path: 'examples/01-maintaining-state', component: MaintainingStateComponent }, 29 | { path: 'examples/02-merging-streams', component: MergingStreamsComponent }, 30 | { path: 'examples/03-map-to-functions', component: MapToFunctionsComponent }, 31 | { path: 'examples/04-triggers', component: TriggersComponent }, 32 | { path: 'examples/05-stream-origin', component: StreamOriginComponent }, 33 | { path: 'examples/06-simple-animation', component: SimpleAnimationComponent }, 34 | { path: 'examples/07-animation', component: AnimationComponent }, 35 | { path: 'examples/08-counter', component: CounterComponent }, 36 | { path: 'examples/09-slideshow', component: SlideshowComponent }, 37 | { path: 'examples/10-location', component: LocationComponent }, 38 | { path: 'examples/11-map', component: MapComponent }, 39 | { path: 'examples/12-annotate', component: AnnotateComponent }, 40 | { path: 'examples/13-game', component: GameComponent }, 41 | { path: 'examples/14-slider', component: SliderComponent } 42 | ]; 43 | 44 | export const appRoutingProviders: any[] = []; 45 | 46 | export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes); -------------------------------------------------------------------------------- /src/app/circle/circle.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, OnInit, ViewChild} from '@angular/core'; 2 | import 'gsap'; 3 | 4 | @Component({ 5 | selector: 'app-circle', 6 | template: `
` 7 | }) 8 | export class CircleComponent implements OnInit { 9 | @ViewChild('circle') circle; 10 | 11 | ngOnInit() { 12 | TweenMax.to(this.circle.nativeElement, 2, 13 | {alpha: 0, width: 0, height: 0}); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/app/examples/00-basic-sequence/basic-sequence.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, ViewChild } from '@angular/core'; 2 | import { fromEvent } from 'rxjs'; 3 | import { filter } from 'rxjs/operators'; 4 | import { map } from 'rxjs/internal/operators'; 5 | 6 | @Component({ 7 | selector: 'app-basic-sequence', 8 | template: ` 9 | 10 |
11 |

{{message}}

12 |
13 | ` 14 | }) 15 | export class BasicSequenceComponent implements OnInit { 16 | @ViewChild('btn') btn; 17 | message: string; 18 | 19 | ngOnInit() { 20 | fromEvent(this.getNativeElement(this.btn), 'click') 21 | .pipe( 22 | // filter((event: KeyboardEvent) => event.shiftKey), // Operator stacking 23 | map(event => 'Beast Mode Activated!') 24 | ) 25 | .subscribe(result => this.message = result); 26 | } 27 | 28 | getNativeElement(element) { 29 | return element._elementRef.nativeElement; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/app/examples/01-maintaining-state/maintaining-state.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, ViewChild } from '@angular/core'; 2 | import { fromEvent } from 'rxjs'; 3 | import { map, scan, startWith } from 'rxjs/internal/operators'; 4 | 5 | interface Coordinate { 6 | x: number, 7 | y: number 8 | } 9 | 10 | @Component({ 11 | selector: 'app-maintaining-state', 12 | template: ` 13 | 14 |
15 |
18 |
19 |
20 | ` 21 | }) 22 | export class MaintainingStateComponent implements OnInit { 23 | @ViewChild('right') right; 24 | position: any; 25 | 26 | ngOnInit() { 27 | fromEvent(this.getNativeElement(this.right), 'click') 28 | .pipe( 29 | map(event => 10), 30 | startWith({x: 100, y: 150}), 31 | scan((acc: Coordinate, curr: number) => Object.assign({}, acc, {x: acc.x + curr})) 32 | ) 33 | .subscribe(position => this.position = position); 34 | } 35 | 36 | getNativeElement(element) { 37 | return element._elementRef.nativeElement; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/app/examples/02-merging-streams/merging-streams.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, ViewChild } from '@angular/core'; 2 | import { fromEvent, merge } from 'rxjs'; 3 | import { map, scan, startWith } from 'rxjs/internal/operators'; 4 | 5 | interface Coordinate { 6 | x: number, 7 | y: number 8 | } 9 | 10 | @Component({ 11 | selector: 'app-merging-streams', 12 | template: ` 13 | 14 | 15 |
16 |
19 |
20 |
21 | ` 22 | }) 23 | export class MergingStreamsComponent implements OnInit { 24 | @ViewChild('left') left; 25 | @ViewChild('right') right; 26 | position: any; 27 | 28 | ngOnInit() { 29 | const left$ = fromEvent(this.getNativeElement(this.left), 'click') 30 | .pipe(map(event => -10)); 31 | 32 | const right$ = fromEvent(this.getNativeElement(this.right), 'click') 33 | .pipe(map(event => 10)); 34 | 35 | merge(left$, right$) 36 | .pipe( 37 | startWith({x: 200, y: 200}), 38 | scan((acc: Coordinate, curr: number) => Object.assign({}, acc, {x: acc.x + curr})) 39 | ) 40 | .subscribe(position => this.position = position); 41 | } 42 | 43 | getNativeElement(element) { 44 | return element._elementRef.nativeElement; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/app/examples/03-map-to-functions/map-to-functions.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { fromEvent, merge, Observable } from 'rxjs'; 3 | import { filter, mapTo, scan, startWith } from 'rxjs/internal/operators'; 4 | 5 | @Component({ 6 | selector: 'app-map-to-functions', 7 | template: ` 8 |
9 |
12 |
13 |
14 | ` 15 | }) 16 | export class MapToFunctionsComponent implements OnInit { 17 | position: any; 18 | 19 | ngOnInit() { 20 | const leftArrow$ = fromEvent(document, 'keydown') 21 | .pipe( 22 | filter((event: KeyboardEvent) => event.key === 'ArrowLeft'), 23 | mapTo(position => this.decrement(position, 'x', 10)) 24 | ) 25 | 26 | const rightArrow$ = fromEvent(document, 'keydown') 27 | .pipe( 28 | filter((event: KeyboardEvent) => event.key === 'ArrowRight'), 29 | mapTo(position => this.increment(position, 'x', 10)) 30 | ) 31 | 32 | const upArrow$ = fromEvent(document, 'keydown') 33 | .pipe( 34 | filter((event: KeyboardEvent) => event.key === 'ArrowUp'), 35 | mapTo(position => this.decrement(position, 'y', 10)) 36 | ) 37 | 38 | const downArrow$ = fromEvent(document, 'keydown') 39 | .pipe( 40 | filter((event: KeyboardEvent) => event.key === 'ArrowDown'), 41 | mapTo(position => this.increment(position, 'y', 10)) 42 | ) 43 | 44 | merge(leftArrow$, rightArrow$, upArrow$, downArrow$) 45 | .pipe( 46 | startWith({x: 100, y: 100}), 47 | scan((acc, curr: Function) => curr(acc)) 48 | ) 49 | .subscribe(position => this.position = position); 50 | } 51 | 52 | increment(obj, prop, value) { 53 | return Object.assign({}, obj, {[prop]: obj[prop] + value}) 54 | } 55 | 56 | decrement(obj, prop, value) { 57 | return Object.assign({}, obj, {[prop]: obj[prop] - value}) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/app/examples/04-triggers/triggers.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, ViewChild } from '@angular/core'; 2 | import { fromEvent } from 'rxjs'; 3 | import { map, startWith, switchMap, takeUntil, tap } from 'rxjs/internal/operators'; 4 | 5 | @Component({ 6 | selector: 'app-triggers', 7 | template: ` 8 |
11 |
12 | ` 13 | }) 14 | export class TriggersComponent implements OnInit { 15 | @ViewChild('ball') ball; 16 | position: any; 17 | 18 | ngOnInit() { 19 | const BALL_OFFSET = 50; 20 | 21 | const move$ = fromEvent(document, 'mousemove') 22 | .pipe( 23 | map((event: MouseEvent) => { 24 | const offset = $(event.target).offset(); 25 | return { 26 | x: event.clientX - offset.left - BALL_OFFSET, 27 | y: event.pageY - BALL_OFFSET 28 | }; 29 | }) 30 | ); 31 | 32 | const down$ = fromEvent(this.ball.nativeElement, 'mousedown') 33 | .pipe(tap(event => this.ball.nativeElement.style.pointerEvents = 'none')); 34 | 35 | const up$ = fromEvent(document, 'mouseup') 36 | .pipe(tap(event => this.ball.nativeElement.style.pointerEvents = 'all')); 37 | 38 | down$.pipe( 39 | switchMap(event => move$.pipe(takeUntil(up$))), 40 | startWith({ x: 100, y: 100}) 41 | ) 42 | .subscribe(position => this.position = position); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/app/examples/05-stream-origin/stream-origin.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { fromEvent } from 'rxjs'; 3 | import { map, pairwise, startWith } from 'rxjs/internal/operators'; 4 | 5 | @Component({ 6 | selector: 'app-stream-origin', 7 | template: ` 8 | 10 | 11 | ` 12 | }) 13 | export class StreamOriginComponent implements OnInit { 14 | lines: any[] = []; 15 | ngOnInit() { 16 | const emptyLine: any = { x1: 0, y1: 0, x2: 0, y2: 0 }; 17 | 18 | // Observable.fromEvent(document, 'mousemove') 19 | fromEvent(document, 'click') 20 | .pipe( 21 | map((event: MouseEvent) => { 22 | const offset = $(event.target).offset(); 23 | return { 24 | x: event.clientX - offset.left, 25 | y: event.pageY - offset.top 26 | }; 27 | }), 28 | pairwise(), 29 | map(positions => { 30 | const p1 = positions[0]; 31 | const p2 = positions[1]; 32 | return { x1: p1.x, y1: p1.y, x2: p2.x, y2: p2.y }; 33 | }), 34 | startWith(emptyLine) 35 | ) 36 | .subscribe(line => this.lines = [...this.lines, line]); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/app/examples/06-simple-animation/simple-animation.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, ViewChild } from '@angular/core'; 2 | import { fromEvent } from 'rxjs'; 3 | 4 | import 'gsap'; 5 | import { map } from 'rxjs/internal/operators'; 6 | 7 | @Component({ 8 | selector: 'app-simple-animation', 9 | template: `
` 10 | }) 11 | export class SimpleAnimationComponent implements OnInit { 12 | 13 | @ViewChild('ball') ball; 14 | 15 | ngOnInit() { 16 | const BALL_OFFSET = 50; 17 | const CURSOR_OFFSET = 20; 18 | 19 | fromEvent(document, 'click') 20 | .pipe( 21 | map((event: any) => { 22 | const offset = $(event.target).offset(); 23 | return { 24 | x: event.clientX - offset.left - BALL_OFFSET - CURSOR_OFFSET, 25 | y: event.pageY - offset.top - BALL_OFFSET - CURSOR_OFFSET 26 | }; 27 | }) 28 | ) 29 | .subscribe(props => TweenMax.to(this.ball.nativeElement, 1, props)) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/app/examples/07-animation/animation.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { fromEvent } from 'rxjs'; 3 | import { map } from 'rxjs/internal/operators'; 4 | 5 | @Component({ 6 | selector: 'app-animation', 7 | template: ` 8 |
9 | 13 | 14 |
15 | ` 16 | }) 17 | export class AnimationComponent implements OnInit { 18 | circles: any[] = []; 19 | 20 | ngOnInit() { 21 | const BALL_OFFSET = 25; 22 | 23 | fromEvent(document, 'mousemove') 24 | .pipe( 25 | map((event: MouseEvent) => { 26 | const offset = $(event.target).offset(); 27 | return { 28 | x: event.clientX - offset.left - BALL_OFFSET, 29 | y: event.pageY - BALL_OFFSET 30 | }; 31 | }) 32 | ) 33 | .subscribe(circle => this.circles = [...this.circles, circle]) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/app/examples/08-counter/counter-client.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, ViewChild } from '@angular/core'; 2 | import { AngularFireDatabase } from 'angularfire2/database'; 3 | 4 | @Component({ 5 | selector: 'app-counter-client', 6 | template: ` 7 |
8 |

Beast Mode Activated

9 | {{count}} times! 10 |
11 | ` 12 | }) 13 | export class CounterClientComponent implements OnInit { 14 | count: number; 15 | 16 | constructor(private db: AngularFireDatabase) {} 17 | 18 | ngOnInit() { 19 | const remote$ = this.db.object('clicker/').valueChanges(); 20 | 21 | remote$ 22 | .subscribe((result: any) => this.count = result.ticker) 23 | ; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/examples/08-counter/counter-master.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, ViewChild } from '@angular/core'; 2 | import { fromEvent } from 'rxjs'; 3 | import { scan, startWith } from 'rxjs/internal/operators'; 4 | import { AngularFireDatabase } from 'angularfire2/database'; 5 | 6 | interface Ticker { 7 | ticker: number 8 | } 9 | 10 | @Component({ 11 | selector: 'app-counter-master', 12 | template: ` 13 | 14 | ` 15 | }) 16 | export class CounterMasterComponent implements OnInit { 17 | @ViewChild('btn') btn; 18 | 19 | constructor(private db: AngularFireDatabase) {} 20 | 21 | ngOnInit() { 22 | const remoteRef = this.db.object('clicker/'); 23 | 24 | fromEvent(this.getNativeElement(this.btn), 'click') 25 | .pipe( 26 | startWith({ticker: 0}), 27 | scan((acc: Ticker, curr) => { return { ticker: acc.ticker + 1 }; }) 28 | ) 29 | .subscribe(event => remoteRef.update(event)); 30 | } 31 | 32 | getNativeElement(element) { 33 | return element._elementRef.nativeElement; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/app/examples/08-counter/counter.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-counter', 5 | styles: [` 6 | mat-card { 7 | width: 400px; 8 | box-sizing: border-box; 9 | margin: 16px; 10 | } 11 | .card-container { 12 | display: flex; 13 | flex-flow: row wrap; 14 | } 15 | `], 16 | template: ` 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | ` 26 | }) 27 | export class CounterComponent {} 28 | -------------------------------------------------------------------------------- /src/app/examples/09-slideshow/images.ts: -------------------------------------------------------------------------------- 1 | export const images: string[] = [ 2 | 'assets/lion-roar.jpg', 3 | 'assets/maxres.jpg', 4 | 'assets/maxresdefault.jpg' 5 | ]; 6 | -------------------------------------------------------------------------------- /src/app/examples/09-slideshow/slideshow-client.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { images } from './images'; 3 | import { AngularFireDatabase } from 'angularfire2/database'; 4 | import { startWith } from 'rxjs/internal/operators'; 5 | import { animate, style, transition, trigger } from '@angular/animations'; 6 | 7 | @Component({ 8 | selector: 'app-slideshow-client', 9 | template: ` 10 |
11 |
12 |
18 |
19 |
20 | `, 21 | styles: [` 22 | .slide-wrapper { 23 | height: 50vw; 24 | max-height: 500px; 25 | } 26 | 27 | .slide { 28 | background-size: cover; 29 | background-position: 50%; 30 | background-repeat: no-repeat; 31 | position: absolute; 32 | top: 24px; 33 | bottom: 24px; 34 | right: 24px; 35 | left: 24px; 36 | } 37 | `], 38 | animations: [ 39 | trigger('imageChange', [ 40 | transition('void => left', [ 41 | style({transform: 'translateX(100vw)'}), 42 | animate('300ms ease-in-out') 43 | ]), 44 | transition('left => void', [ 45 | animate('300ms ease-in-out', style({transform: 'translateX(-100vw)'})) 46 | ]), 47 | transition('void => right', [ 48 | style({transform: 'translateX(-100vw)'}), 49 | animate('300ms ease-in-out') 50 | ]), 51 | transition('right => void', [ 52 | animate('300ms ease-in-out', style({transform: 'translateX(100vw)'})) 53 | ]) 54 | ]) 55 | ] 56 | }) 57 | export class SlideshowClientComponent implements OnInit { 58 | position: any; 59 | images: any[] = images; 60 | currentIndex: number = 0; 61 | currentDirection: string = 'left'; 62 | 63 | constructor(private db: AngularFireDatabase) {} 64 | 65 | ngOnInit() { 66 | const remote$ = this.db.object('slideshow/').valueChanges(); 67 | 68 | remote$ 69 | .pipe(startWith({index: 0, direction: 'left'})) 70 | .subscribe(event => { 71 | this.currentIndex = event.index; 72 | this.currentDirection = event.direction; 73 | }); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/app/examples/09-slideshow/slideshow-master.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, ViewChild } from '@angular/core'; 2 | import { images } from './images'; 3 | import { fromEvent, merge } from 'rxjs'; 4 | import { map, scan, startWith } from 'rxjs/internal/operators'; 5 | import { AngularFireDatabase } from 'angularfire2/database'; 6 | 7 | @Component({ 8 | selector: 'app-slideshow-master', 9 | template: ` 10 | 11 | 12 | `, 13 | styles: [` 14 | :host { 15 | display: flex; 16 | justify-content: space-between; 17 | } 18 | `] 19 | }) 20 | export class SlideshowMasterComponent implements OnInit { 21 | @ViewChild('previous') previous; 22 | @ViewChild('next') next; 23 | images: any[] = images; 24 | position: any; 25 | 26 | constructor(private db: AngularFireDatabase) {} 27 | 28 | ngOnInit() { 29 | const remoteRef = this.db.object('slideshow/'); 30 | 31 | const previous$ = fromEvent(this.getNativeElement(this.previous), 'click') 32 | .pipe(map(event => {return {shift: -1, direction: 'right'}})); 33 | 34 | const next$ = fromEvent(this.getNativeElement(this.next), 'click') 35 | .pipe(map(event => {return {shift: +1, direction: 'left'}})); 36 | 37 | merge(previous$, next$) 38 | .pipe( 39 | startWith({index: 0} as any), 40 | scan((acc, curr) => { 41 | const projectedIndex = acc.index + curr.shift; 42 | 43 | let adjustedIndex = projectedIndex < 0 ? this.images.length - 1 44 | : projectedIndex >= this.images.length ? 0 45 | : projectedIndex; 46 | 47 | return {index: adjustedIndex, direction: curr.direction}; 48 | }) 49 | ) 50 | .subscribe(event => remoteRef.update(event)); 51 | } 52 | 53 | getNativeElement(element) { 54 | return element._elementRef.nativeElement; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/app/examples/09-slideshow/slideshow.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-slideshow', 5 | styles: [` 6 | mat-card { 7 | width: 100%; 8 | max-width: 900px; 9 | box-sizing: border-box; 10 | margin: 16px; 11 | overflow: hidden; 12 | } 13 | .card-container { 14 | display: flex; 15 | flex-flow: row wrap; 16 | } 17 | `], 18 | template: ` 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | ` 28 | }) 29 | export class SlideshowComponent {} 30 | -------------------------------------------------------------------------------- /src/app/examples/10-location/location-client.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, ViewChild } from '@angular/core'; 2 | import { AngularFireDatabase } from 'angularfire2/database'; 3 | import { startWith } from 'rxjs/internal/operators'; 4 | 5 | @Component({ 6 | selector: 'app-location-client', 7 | template: ` 8 |
11 |
12 | ` 13 | }) 14 | export class LocationClientComponent implements OnInit { 15 | position: any; 16 | 17 | constructor(private db: AngularFireDatabase) {} 18 | 19 | ngOnInit() { 20 | const remoteRef = this.db.object('location/'); 21 | const remote$ = remoteRef.valueChanges(); 22 | 23 | remote$ 24 | .pipe(startWith({x: 100, y: 100})) 25 | .subscribe(result => this.position = result); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/app/examples/10-location/location-master.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, ViewChild } from '@angular/core'; 2 | import { fromEvent } from 'rxjs'; 3 | import { map, startWith, switchMap, takeUntil, tap } from 'rxjs/internal/operators'; 4 | import { AngularFireDatabase } from 'angularfire2/database'; 5 | 6 | @Component({ 7 | selector: 'app-location-master', 8 | template: ` 9 |
12 |
13 | ` 14 | }) 15 | export class LocationMasterComponent implements OnInit { 16 | @ViewChild('pin') pin; 17 | position: any; 18 | 19 | constructor(private db: AngularFireDatabase) {} 20 | 21 | ngOnInit() { 22 | const remoteRef = this.db.object('location/'), 23 | remote$ = remoteRef.valueChanges(), 24 | PIN_OFFSET_X = 26, 25 | PIN_OFFSET_Y = 16; 26 | 27 | const move$ = fromEvent(document, 'mousemove') 28 | .pipe( 29 | map((event: MouseEvent) => { 30 | const offset = $(event.target).offset(); 31 | return { 32 | x: event.clientX - offset.left - PIN_OFFSET_X, 33 | y: event.clientY - offset.top - PIN_OFFSET_Y 34 | }; 35 | }) 36 | ); 37 | 38 | const down$ = fromEvent(this.pin.nativeElement, 'mousedown') 39 | .pipe(tap(event => this.pin.nativeElement.style.pointerEvents = 'none')); 40 | 41 | const up$ = fromEvent(document, 'mouseup') 42 | .pipe(tap(event => this.pin.nativeElement.style.pointerEvents = 'all')); 43 | 44 | down$ 45 | .pipe( 46 | switchMap(event => move$.pipe(takeUntil(up$))), 47 | startWith({ x: window.innerWidth / 2, y: 100}) 48 | ) 49 | .subscribe(event => remoteRef.update(event)); 50 | 51 | remote$ 52 | .pipe(startWith({x: window.innerWidth / 2, y: 100})) 53 | .subscribe(result => this.position = result); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/app/examples/10-location/location.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-location', 5 | styles: [` 6 | .card-container { 7 | position:fixed; 8 | top: 70px; 9 | bottom: 0; 10 | left: 0; 11 | right: 0; 12 | } 13 | mat-card { 14 | width: 100%; 15 | box-sizing: border-box; 16 | margin: 16px; 17 | background: #fff url(assets/london-map.jpg) no-repeat center center; 18 | } 19 | .card-container { 20 | display: flex; 21 | flex-flow: row wrap; 22 | } 23 | `], 24 | template: ` 25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 |
33 | ` 34 | }) 35 | export class LocationComponent {} 36 | -------------------------------------------------------------------------------- /src/app/examples/11-map/map-client.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { AngularFireDatabase } from 'angularfire2/database'; 3 | 4 | @Component({ 5 | selector: 'app-map-client', 6 | template: ` 7 |
8 | 10 | 11 |
12 | ` 13 | }) 14 | export class MapClientComponent implements OnInit { 15 | lines: any[] = []; 16 | 17 | constructor(private db: AngularFireDatabase) {} 18 | 19 | ngOnInit() { 20 | const remote$ = this.db.object('map/').valueChanges(); 21 | 22 | remote$ 23 | .subscribe(line => this.lines = [...this.lines, line]); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/examples/11-map/map-master.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, ElementRef } from '@angular/core'; 2 | import { fromEvent } from 'rxjs'; 3 | import { map, pairwise, startWith } from 'rxjs/internal/operators'; 4 | import { AngularFireDatabase } from 'angularfire2/database'; 5 | 6 | declare var jQuery:any; 7 | 8 | @Component({ 9 | selector: 'app-map-master', 10 | template: ` 11 | 13 | 14 | ` 15 | }) 16 | export class MapMasterComponent implements OnInit { 17 | lines: any[] = []; 18 | 19 | constructor(private db: AngularFireDatabase) {} 20 | 21 | ngOnInit() { 22 | const remoteRef = this.db.object('map/'); 23 | const remote$ = remoteRef.valueChanges(); 24 | const emptyLine: any = { x1: 0, y1: 0, x2: 0, y2: 0 }; 25 | 26 | fromEvent(document, 'click') 27 | .pipe( 28 | map((event: MouseEvent) => { 29 | const offset = $(event.target).offset(); 30 | return { 31 | x: event.clientX - offset.left, 32 | y: event.clientY - offset.top 33 | }; 34 | }), 35 | pairwise(), 36 | map(positions => { 37 | const p1 = positions[0]; 38 | const p2 = positions[1]; 39 | return { x1: p1.x, y1: p1.y, x2: p2.x, y2: p2.y }; 40 | }), 41 | startWith(emptyLine) 42 | ) 43 | .subscribe(line => remoteRef.update(line)); 44 | 45 | remote$ 46 | .subscribe(line => this.lines = [...this.lines, line]); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/app/examples/11-map/map.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-map', 5 | styles: [` 6 | mat-card { 7 | width: 100%; 8 | box-sizing: border-box; 9 | margin: 16px; 10 | background: #fff url(assets/london-map.jpg) no-repeat center center; 11 | padding: 0; 12 | } 13 | .card-container { 14 | display: flex; 15 | flex-flow: row wrap; 16 | position: fixed; 17 | top: 70px; 18 | bottom: 0; 19 | left: 0; 20 | right: 0; 21 | } 22 | `], 23 | template: ` 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
32 | ` 33 | }) 34 | export class MapComponent { } 35 | -------------------------------------------------------------------------------- /src/app/examples/12-annotate/annotate-client.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { AngularFireDatabase } from 'angularfire2/database'; 3 | 4 | @Component({ 5 | selector: 'app-annotate-client', 6 | template: ` 7 | 9 | 10 | 11 | ` 12 | }) 13 | export class AnnotateClientComponent implements OnInit { 14 | lines: any[] = []; 15 | 16 | constructor(private db: AngularFireDatabase) {} 17 | 18 | ngOnInit() { 19 | const remote$ = this.db.object('annotate/').valueChanges(); 20 | 21 | remote$ 22 | .subscribe(line => this.lines = [...this.lines, line]); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/app/examples/12-annotate/annotate-master.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { fromEvent } from 'rxjs'; 3 | import { map, pairwise, startWith } from 'rxjs/internal/operators'; 4 | import { AngularFireDatabase } from 'angularfire2/database'; 5 | 6 | @Component({ 7 | selector: 'app-annotate-master', 8 | template: ` 9 | 11 | 12 | 13 | ` 14 | }) 15 | export class AnnotateMasterComponent implements OnInit { 16 | lines: any[] = []; 17 | 18 | constructor(private db: AngularFireDatabase) {} 19 | 20 | ngOnInit() { 21 | const remoteRef = this.db.object('annotate/'); 22 | const remote$ = remoteRef.valueChanges(); 23 | const emptyLine: any = { x1: 0, y1: 0, x2: 0, y2: 0 }; 24 | 25 | fromEvent(document, 'mousemove') 26 | .pipe( 27 | map((event: MouseEvent) => { 28 | const offset = $(event.target).offset(); 29 | 30 | return { 31 | x: event.clientX - offset.left, 32 | y: event.clientY - offset.top 33 | }; 34 | }), 35 | pairwise(), 36 | map(positions => { 37 | const p1 = positions[0]; 38 | const p2 = positions[1]; 39 | return { x1: p1.x, y1: p1.y, x2: p2.x, y2: p2.y }; 40 | }), 41 | startWith(emptyLine) 42 | ) 43 | .subscribe(event => remoteRef.update(event)); 44 | 45 | remote$ 46 | .subscribe(line => this.lines = [...this.lines, line]); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/app/examples/12-annotate/annotate.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-annotate', 5 | styles: [` 6 | mat-card { 7 | width: 400px; 8 | box-sizing: border-box; 9 | margin: 16px; 10 | } 11 | .card-container { 12 | position:fixed; 13 | top: 70px; 14 | bottom: 0; 15 | display: flex; 16 | flex-flow: row wrap; 17 | } 18 | `], 19 | template: ` 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | ` 29 | }) 30 | export class AnnotateComponent { } 31 | -------------------------------------------------------------------------------- /src/app/examples/12-annotate/doc.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-doc', 5 | styles: [` 6 | h1 { 7 | text-align: center; 8 | } 9 | `], 10 | template: ` 11 |

RXJS + Firebase FTW!

12 |

Aenean vitae pharetra magna. Curabitur lacinia dignissim fringilla. Donec vel ligula ac orci congue lobortis eget et lectus. Donec elit quam, vestibulum et elit in, iaculis tempus nulla.

13 |
14 |
    15 |
  1. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  2. 16 |
  3. Curabitur lobortis nisi at interdum efficitur.
  4. 17 |
  5. Integer non mauris diam. Morbi viverra nisi auctor neque condimentum viverra. Phasellus sed accumsan dui. Morbi eget efficitur diam, eget vehicula justo.
  6. 18 |
19 |
20 |
Sed ut felis turpis. Sed cursus luctus lacus eget elementum. Fusce congue semper nisi, in dignissim magna blandit id.
21 | ` 22 | }) 23 | export class DocComponent { } 24 | -------------------------------------------------------------------------------- /src/app/examples/13-game/game-client.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { AngularFireDatabase } from 'angularfire2/database'; 3 | 4 | @Component({ 5 | selector: 'app-game-client', 6 | template: ` 7 |
10 |
11 | 15 | ` 16 | }) 17 | export class GameClientComponent implements OnInit { 18 | spaceshipPosition: Object = {}; 19 | shots: any[] = []; 20 | 21 | constructor(private db: AngularFireDatabase) {} 22 | 23 | ngOnInit() { 24 | const spaceship$ = this.db.object('spaceship/').valueChanges(), 25 | shots$ = this.db.list('shots/').valueChanges(); 26 | 27 | shots$ 28 | .subscribe(shots => { 29 | if (shots.length && this.shots.length < shots.length) { 30 | this.shots.push(shots[shots.length - 1]) 31 | } else { 32 | this.shots.shift(); 33 | } 34 | }); 35 | 36 | spaceship$ 37 | .subscribe(position => this.spaceshipPosition = position); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/app/examples/13-game/game-master.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { fromEvent } from 'rxjs'; 3 | import { map } from 'rxjs/internal/operators'; 4 | import { AngularFireDatabase } from 'angularfire2/database'; 5 | 6 | const SPACESHIP_OFFSET = 40, 7 | SHOT_OFFSET = 2; 8 | 9 | @Component({ 10 | selector: 'app-game-master', 11 | template: ` 12 |
15 |
16 | 21 | ` 22 | }) 23 | export class GameMasterComponent implements OnInit { 24 | spaceshipPosition: Object = {}; 25 | shots: any[] = []; 26 | shotsRef: any; 27 | 28 | constructor(private db: AngularFireDatabase) {} 29 | 30 | ngOnInit() { 31 | const spaceShipRef = this.db.object('spaceship/'), 32 | spaceship$ = spaceShipRef.valueChanges(), 33 | shotsRef = this.db.list('shots/'), 34 | shots$ = shotsRef.valueChanges(); 35 | 36 | this.shotsRef = shotsRef; 37 | 38 | fromEvent(document, 'click') 39 | .pipe(map(this.parseEvent)) 40 | .subscribe(shot => shotsRef.push(shot)); 41 | 42 | fromEvent(document, 'mousemove') 43 | .pipe(map(this.parseEvent)) 44 | .subscribe(event => spaceShipRef.update(event)); 45 | 46 | shots$ 47 | .subscribe(shots => { 48 | if (shots.length && this.shots.length < shots.length) { 49 | this.shots.push(shots[shots.length - 1]) 50 | } else { 51 | this.shots.shift(); 52 | } 53 | }); 54 | 55 | spaceship$ 56 | .subscribe(event => this.spaceshipPosition = event); 57 | } 58 | 59 | parseEvent(event) { 60 | const offset = $(event.target).offset(), 61 | typeOfOffsetLeft = event.type === 'click' ? SHOT_OFFSET : SPACESHIP_OFFSET; 62 | 63 | return { 64 | x: event.clientX - offset.left - typeOfOffsetLeft, 65 | y: event.clientY - offset.top - SPACESHIP_OFFSET 66 | }; 67 | } 68 | 69 | removeShot(shot) { 70 | if (shot) { 71 | this.shotsRef.remove(shot.$key); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/app/examples/13-game/game.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { interval } from 'rxjs'; 3 | import { repeat, startWith, take } from 'rxjs/internal/operators'; 4 | 5 | @Component({ 6 | selector: 'app-game', 7 | styles: [` 8 | mat-card { 9 | width: 400px; 10 | box-sizing: border-box; 11 | margin: 16px; 12 | background: white url('assets/stars.jpg') repeat-y 0 0; 13 | background-size: cover; 14 | overflow: hidden; 15 | } 16 | .card-container { 17 | display: flex; 18 | flex-flow: row wrap; 19 | position: fixed; 20 | top: 70px; 21 | bottom: 0; 22 | } 23 | `], 24 | template: ` 25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 |
33 | ` 34 | }) 35 | export class GameComponent implements OnInit{ 36 | backgroundPosition: number = 0; 37 | ngOnInit() { 38 | interval(10) 39 | .pipe( 40 | startWith(1100), 41 | take(1178), 42 | repeat() 43 | ) 44 | .subscribe(count => this.backgroundPosition = count); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/app/examples/14-slider/slider-client.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, OnDestroy } from '@angular/core'; 2 | import { FormBuilder, FormGroup, FormControl } from '@angular/forms'; 3 | import { Observable } from 'rxjs'; 4 | import { AngularFireDatabase } from 'angularfire2/database'; 5 | import { map, startWith, tap } from 'rxjs/internal/operators'; 6 | 7 | @Component({ 8 | selector: 'app-slider-client', 9 | styles: [ 10 | 'input { width: 50%; }' 11 | ], 12 | template: ` 13 |

Min/Max Selector

14 |
15 | 16 |

min - {{minValue | async}}

17 | 18 |

max - {{maxValue | async}}

19 |
20 | ` 21 | }) 22 | export class SliderClientComponent implements OnInit { 23 | myForm: FormGroup; 24 | minValue: Observable; 25 | maxValue: Observable; 26 | min = 0; 27 | max = 100; 28 | startMin = 45; 29 | startMax = 55; 30 | step = 1; 31 | 32 | constructor (private builder: FormBuilder, private db: AngularFireDatabase) {} 33 | 34 | ngOnInit() { 35 | const remote$ = this.db.object('slider/').valueChanges(); 36 | 37 | this.myForm = this.builder.group({ 38 | min: this.startMin, 39 | max: this.startMax 40 | }); 41 | 42 | this.minValue = remote$ 43 | .pipe( 44 | map((vals: any) => vals.min), 45 | tap(val => (this.myForm.controls['min']).setValue(val)), 46 | startWith(this.startMin), 47 | ); 48 | 49 | this.maxValue = remote$ 50 | .pipe( 51 | map((vals: any) => vals.max), 52 | tap(val => (this.myForm.controls['max']).setValue(val)), 53 | startWith(this.startMax), 54 | ); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/app/examples/14-slider/slider-master.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { FormBuilder, FormGroup, FormControl } from '@angular/forms'; 3 | import { Observable } from 'rxjs'; 4 | import { filter, map, pairwise, startWith, tap } from 'rxjs/internal/operators'; 5 | import { AngularFireDatabase } from 'angularfire2/database'; 6 | 7 | @Component({ 8 | selector: 'app-slider-master', 9 | styles: [ 10 | 'input { width: 50%; }' 11 | ], 12 | template: ` 13 |

Min/Max Selector

14 |
15 | 16 |

min - {{minValue | async}}

17 | 18 |

max - {{maxValue | async}}

19 |
20 | ` 21 | }) 22 | export class SliderMasterComponent implements OnInit { 23 | myForm: FormGroup; 24 | minValue: Observable; 25 | maxValue: Observable; 26 | min = 0; 27 | max = 100; 28 | startMin = 45; 29 | startMax = 55; 30 | step = 1; 31 | 32 | constructor (private builder: FormBuilder, private db: AngularFireDatabase) {} 33 | 34 | ngOnInit() { 35 | this.myForm = this.builder.group({ 36 | min: this.startMin, 37 | max: this.startMax 38 | }); 39 | 40 | const remoteRef = this.db.object('slider/'); 41 | 42 | let valueStream = this.myForm.valueChanges 43 | .pipe( 44 | map(val => { 45 | return { 46 | min: parseFloat(val.min), 47 | max: parseFloat(val.max) 48 | }; 49 | }), 50 | pairwise(), 51 | filter(([oldVal, newVal]) => { 52 | let isValid = true; 53 | if (oldVal.min !== newVal.min && newVal.min > newVal.max) { 54 | isValid = false; 55 | (this.myForm.controls['max']).setValue(newVal.min); 56 | } 57 | else if (oldVal.max !== newVal.max && newVal.max < newVal.min) { 58 | isValid = false; 59 | (this.myForm.controls['min']).setValue(newVal.max); 60 | } 61 | return isValid; 62 | }), 63 | map(([oldVal, newVal]) => newVal), 64 | tap(vals => remoteRef.update(vals)) 65 | ) 66 | 67 | this.minValue = valueStream 68 | .pipe( 69 | map(vals => vals.min), 70 | startWith(this.startMin) 71 | ); 72 | 73 | this.maxValue = valueStream 74 | .pipe( 75 | map(vals => vals.max), 76 | startWith(this.startMax) 77 | ); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/app/examples/14-slider/slider.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-slider', 5 | styles: [` 6 | mat-card { 7 | width: 400px; 8 | box-sizing: border-box; 9 | margin: 16px; 10 | } 11 | .card-container { 12 | display: flex; 13 | flex-flow: row wrap; 14 | } 15 | `], 16 | template: ` 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | ` 26 | }) 27 | export class SliderComponent{} 28 | -------------------------------------------------------------------------------- /src/app/examples/index.ts: -------------------------------------------------------------------------------- 1 | export { BasicSequenceComponent } from "./00-basic-sequence/basic-sequence.component"; 2 | export { MaintainingStateComponent } from "./01-maintaining-state/maintaining-state.component"; 3 | export { MergingStreamsComponent } from "./02-merging-streams/merging-streams.component"; 4 | export { MapToFunctionsComponent } from "./03-map-to-functions/map-to-functions.component"; 5 | export { TriggersComponent } from "./04-triggers/triggers.component"; 6 | export { StreamOriginComponent } from "./05-stream-origin/stream-origin.component"; 7 | export { SimpleAnimationComponent } from "./06-simple-animation/simple-animation.component"; 8 | export { AnimationComponent } from "./07-animation/animation.component"; 9 | 10 | export { CounterComponent } from "./08-counter/counter.component"; 11 | export { CounterClientComponent } from "./08-counter/counter-client.component"; 12 | export { CounterMasterComponent } from "./08-counter/counter-master.component"; 13 | 14 | export { SlideshowComponent } from "./09-slideshow/slideshow.component"; 15 | export { SlideshowClientComponent } from "./09-slideshow/slideshow-client.component"; 16 | export { SlideshowMasterComponent } from "./09-slideshow/slideshow-master.component"; 17 | 18 | export { LocationComponent } from "./10-location/location.component"; 19 | export { LocationClientComponent } from "./10-location/location-client.component"; 20 | export { LocationMasterComponent } from "./10-location/location-master.component"; 21 | 22 | export { MapComponent } from "./11-map/map.component"; 23 | export { MapClientComponent } from "./11-map/map-client.component"; 24 | export { MapMasterComponent } from "./11-map/map-master.component"; 25 | 26 | export { AnnotateComponent } from "./12-annotate/annotate.component"; 27 | export { AnnotateClientComponent } from "./12-annotate/annotate-client.component"; 28 | export { AnnotateMasterComponent } from "./12-annotate/annotate-master.component"; 29 | export { DocComponent } from "./12-annotate/doc.component"; 30 | 31 | export { GameComponent } from "./13-game/game.component"; 32 | export { GameClientComponent } from "./13-game/game-client.component"; 33 | export { GameMasterComponent } from "./13-game/game-master.component"; 34 | 35 | export { SliderComponent } from "./14-slider/slider.component"; 36 | export { SliderClientComponent } from "./14-slider/slider-client.component"; 37 | export { SliderMasterComponent } from "./14-slider/slider-master.component"; 38 | -------------------------------------------------------------------------------- /src/app/firebase.conf.example.ts: -------------------------------------------------------------------------------- 1 | export const firebaseConfig = { 2 | apiKey: '', 3 | authDomain: '', 4 | databaseURL: '', 5 | storageBucket: '' 6 | }; 7 | -------------------------------------------------------------------------------- /src/app/index.ts: -------------------------------------------------------------------------------- 1 | export * from './app.component'; 2 | export * from './app.module'; 3 | -------------------------------------------------------------------------------- /src/app/line/line.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, OnInit, Input} from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-line', 5 | template: ` 6 | 7 | 10 | 11 | `, 12 | styles: [` 13 | line { 14 | pointer-events: none; 15 | } 16 | `] 17 | }) 18 | export class LineComponent implements OnInit { 19 | @Input() line: any; 20 | 21 | ngOnInit() { 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/app/shot/shot.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, ViewChild, OnInit, Output, EventEmitter } from '@angular/core'; 2 | import 'gsap'; 3 | 4 | @Component({ 5 | selector: 'app-shot', 6 | template: `
`, 7 | styles: [` 8 | .shot { 9 | pointer-events: none; 10 | position: absolute; 11 | width: 5px; 12 | height: 10px; 13 | background: cyan; 14 | border-radius: 2px; 15 | } 16 | `] 17 | }) 18 | 19 | export class ShotComponent implements OnInit{ 20 | @ViewChild('shot') shot; 21 | @Output() remove: EventEmitter = new EventEmitter(); 22 | 23 | ngOnInit() { 24 | TweenMax.to(this.shot.nativeElement, 2, {top: -1000, onComplete: () => { 25 | this.remove.emit(); 26 | }}); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onehungrymind/angular2-rxjs-examples/6bec84b4ab0dd5454027f4975add49f194283316/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/assets/.npmignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onehungrymind/angular2-rxjs-examples/6bec84b4ab0dd5454027f4975add49f194283316/src/assets/.npmignore -------------------------------------------------------------------------------- /src/assets/lion-roar.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onehungrymind/angular2-rxjs-examples/6bec84b4ab0dd5454027f4975add49f194283316/src/assets/lion-roar.jpg -------------------------------------------------------------------------------- /src/assets/london-map.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onehungrymind/angular2-rxjs-examples/6bec84b4ab0dd5454027f4975add49f194283316/src/assets/london-map.jpg -------------------------------------------------------------------------------- /src/assets/maxres.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onehungrymind/angular2-rxjs-examples/6bec84b4ab0dd5454027f4975add49f194283316/src/assets/maxres.jpg -------------------------------------------------------------------------------- /src/assets/maxresdefault.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onehungrymind/angular2-rxjs-examples/6bec84b4ab0dd5454027f4975add49f194283316/src/assets/maxresdefault.jpg -------------------------------------------------------------------------------- /src/assets/pin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onehungrymind/angular2-rxjs-examples/6bec84b4ab0dd5454027f4975add49f194283316/src/assets/pin.png -------------------------------------------------------------------------------- /src/assets/spaceship.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onehungrymind/angular2-rxjs-examples/6bec84b4ab0dd5454027f4975add49f194283316/src/assets/spaceship.png -------------------------------------------------------------------------------- /src/assets/stars.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onehungrymind/angular2-rxjs-examples/6bec84b4ab0dd5454027f4975add49f194283316/src/assets/stars.jpg -------------------------------------------------------------------------------- /src/environments/environment.dev.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: false 3 | }; 4 | -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file for the current environment will overwrite this one during build. 2 | // Different environments can be found in ./environment.{dev|prod}.ts, and 3 | // you can create your own and use it with the --env flag. 4 | // The build system defaults to the dev environment. 5 | 6 | export const environment = { 7 | production: false 8 | }; 9 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onehungrymind/angular2-rxjs-examples/6bec84b4ab0dd5454027f4975add49f194283316/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Angular2 RxJS Examples 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Loading... 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import "./polyfills.ts"; 2 | 3 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 4 | import { enableProdMode } from '@angular/core'; 5 | import { environment } from './environments/environment'; 6 | import { AppModule } from './app/'; 7 | 8 | if (environment.production) { 9 | enableProdMode(); 10 | } 11 | 12 | platformBrowserDynamic().bootstrapModule(AppModule); 13 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | // This file includes polyfills needed by Angular 2 and is loaded before 2 | // the app. You can add your own extra polyfills to this file. 3 | import 'core-js/es6/symbol'; 4 | import 'core-js/es6/object'; 5 | import 'core-js/es6/function'; 6 | import 'core-js/es6/parse-int'; 7 | import 'core-js/es6/parse-float'; 8 | import 'core-js/es6/number'; 9 | import 'core-js/es6/math'; 10 | import 'core-js/es6/string'; 11 | import 'core-js/es6/date'; 12 | import 'core-js/es6/array'; 13 | import 'core-js/es6/regexp'; 14 | import 'core-js/es6/map'; 15 | import 'core-js/es6/set'; 16 | import 'core-js/es6/reflect'; 17 | 18 | import 'core-js/es7/reflect'; 19 | import 'zone.js/dist/zone'; 20 | -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | @import '~@angular/material/prebuilt-themes/purple-green.css'; 2 | 3 | body { 4 | font-family: Roboto, "Helvetica Neue", sans-serif; 5 | } 6 | .ball { 7 | cursor: pointer; 8 | border-radius: 50%; 9 | width: 100px; 10 | height: 100px; 11 | position: absolute; 12 | background-image: radial-gradient(orange, red); 13 | } 14 | .pin { 15 | cursor: pointer; 16 | width: 50px; 17 | height: 50px; 18 | position: absolute; 19 | background: transparent url('assets/pin.png') no-repeat; 20 | background-size: contain; 21 | } 22 | .spaceship { 23 | pointer-events: none; 24 | width: 100px; 25 | height: 100px; 26 | position: absolute; 27 | background: transparent url('assets/spaceship.png') no-repeat; 28 | background-size: contain; 29 | } 30 | .circle { 31 | border-radius: 50%; 32 | width: 50px; 33 | height: 50px; 34 | position: absolute; 35 | background-image: radial-gradient(#DDD, white); 36 | pointer-events: none; 37 | } 38 | app-circle { 39 | position: absolute; 40 | } 41 | app-shot { 42 | position: absolute; 43 | } 44 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | import './polyfills.ts'; 2 | 3 | import 'zone.js/dist/long-stack-trace-zone'; 4 | import 'zone.js/dist/jasmine-patch'; 5 | import 'zone.js/dist/async-test'; 6 | import 'zone.js/dist/fake-async-test'; 7 | import 'zone.js/dist/sync-test'; 8 | 9 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 10 | declare var __karma__: any; 11 | 12 | // Prevent Karma from running prematurely. 13 | __karma__.loaded = function () {}; 14 | 15 | 16 | Promise.all([ 17 | System.import('@angular/core/testing'), 18 | System.import('@angular/platform-browser-dynamic/testing') 19 | ]) 20 | // First, initialize the Angular testing environment. 21 | .then(([testing, testingBrowser]) => { 22 | testing.getTestBed().initTestEnvironment( 23 | testingBrowser.BrowserDynamicTestingModule, 24 | testingBrowser.platformBrowserDynamicTesting() 25 | ); 26 | }) 27 | // Then we find all the tests. 28 | .then(() => require.context('./', true, /\.spec\.ts/)) 29 | // And load the modules. 30 | .then(context => context.keys().map(context)) 31 | // Finally, start Karma to run the tests. 32 | .then(__karma__.start, __karma__.error); 33 | -------------------------------------------------------------------------------- /src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": false, 4 | "emitDecoratorMetadata": true, 5 | "experimentalDecorators": true, 6 | "lib": ["es6", "dom"], 7 | "mapRoot": "./", 8 | "module": "es6", 9 | "moduleResolution": "node", 10 | "outDir": "../dist/out-tsc", 11 | "sourceMap": true, 12 | "skipLibCheck": true, 13 | "target": "es6", 14 | "typeRoots": [ 15 | "../node_modules/@types" 16 | ], 17 | "types": [ 18 | "hammerjs" 19 | ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/typings.d.ts: -------------------------------------------------------------------------------- 1 | // Typings reference file, see links for more information 2 | // https://github.com/typings/typings 3 | // https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html 4 | 5 | declare var System: any; 6 | declare var module: { id: string }; 7 | declare var require: any; 8 | declare var $: any; 9 | declare var TweenMax: any; 10 | declare var {}: any; -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "class-name": true, 7 | "comment-format": [ 8 | true, 9 | "check-space" 10 | ], 11 | "curly": true, 12 | "eofline": true, 13 | "forin": true, 14 | "indent": [ 15 | true, 16 | "spaces" 17 | ], 18 | "label-position": true, 19 | "label-undefined": true, 20 | "max-line-length": [ 21 | true, 22 | 140 23 | ], 24 | "member-access": false, 25 | "member-ordering": [ 26 | true, 27 | "static-before-instance", 28 | "variables-before-functions" 29 | ], 30 | "no-arg": true, 31 | "no-bitwise": true, 32 | "no-console": [ 33 | true, 34 | "debug", 35 | "info", 36 | "time", 37 | "timeEnd", 38 | "trace" 39 | ], 40 | "no-construct": true, 41 | "no-debugger": true, 42 | "no-duplicate-key": true, 43 | "no-duplicate-variable": true, 44 | "no-empty": false, 45 | "no-eval": true, 46 | "no-inferrable-types": true, 47 | "no-shadowed-variable": true, 48 | "no-string-literal": false, 49 | "no-switch-case-fall-through": true, 50 | "no-trailing-whitespace": true, 51 | "no-unused-expression": true, 52 | "no-unused-variable": true, 53 | "no-unreachable": true, 54 | "no-use-before-declare": true, 55 | "no-var-keyword": true, 56 | "object-literal-sort-keys": false, 57 | "one-line": [ 58 | true, 59 | "check-open-brace", 60 | "check-catch", 61 | "check-else", 62 | "check-whitespace" 63 | ], 64 | "quotemark": [ 65 | true, 66 | "single" 67 | ], 68 | "radix": true, 69 | "semicolon": [ 70 | "always" 71 | ], 72 | "triple-equals": [ 73 | true, 74 | "allow-null-check" 75 | ], 76 | "typedef-whitespace": [ 77 | true, 78 | { 79 | "call-signature": "nospace", 80 | "index-signature": "nospace", 81 | "parameter": "nospace", 82 | "property-declaration": "nospace", 83 | "variable-declaration": "nospace" 84 | } 85 | ], 86 | "variable-name": false, 87 | "whitespace": [ 88 | true, 89 | "check-branch", 90 | "check-decl", 91 | "check-operator", 92 | "check-separator", 93 | "check-type" 94 | ], 95 | 96 | "directive-selector-prefix": [true, "app"], 97 | "component-selector-prefix": [true, "app"], 98 | "directive-selector-name": [true, "camelCase"], 99 | "component-selector-name": [true, "kebab-case"], 100 | "directive-selector-type": [true, "attribute"], 101 | "component-selector-type": [true, "element"], 102 | "use-input-property-decorator": true, 103 | "use-output-property-decorator": true, 104 | "use-host-property-decorator": true, 105 | "no-input-rename": true, 106 | "no-output-rename": true, 107 | "use-life-cycle-interface": true, 108 | "use-pipe-transform-interface": true, 109 | "component-class-suffix": true, 110 | "directive-class-suffix": true 111 | } 112 | } 113 | --------------------------------------------------------------------------------