From f560418c20d49bb796673355fe0e4c4ccf998b54 Mon Sep 17 00:00:00 2001 From: pmartin Date: Sun, 19 Nov 2017 10:24:43 +0100 Subject: [PATCH 01/26] refactor(operators): Separate operators in multiple pages --- .../components/operator/operator.component.ts | 44 +++++++++++----- src/app/operators/operators-routing.module.ts | 9 +++- src/app/operators/operators.component.html | 7 +-- src/app/operators/operators.component.ts | 51 ++++++++++++------- src/app/operators/operators.module.ts | 10 +++- 5 files changed, 81 insertions(+), 40 deletions(-) diff --git a/src/app/operators/components/operator/operator.component.ts b/src/app/operators/components/operator/operator.component.ts index 453a59d8..e1789743 100644 --- a/src/app/operators/components/operator/operator.component.ts +++ b/src/app/operators/components/operator/operator.component.ts @@ -2,28 +2,46 @@ import { Component, Input, OnInit, - ChangeDetectionStrategy -} from "@angular/core"; -import { OperatorDoc } from "../../../../operator-docs/operator.model"; + ChangeDetectionStrategy, + Inject, + InjectionToken +} from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { OperatorDoc } from '../../../../operator-docs/operator.model'; +import 'rxjs/add/operator/pluck'; + +export const OPERATOR_TOKEN = new InjectionToken('operators'); @Component({ - selector: "app-operator", - templateUrl: "./operator.component.html", - styleUrls: ["./operator.component.scss"], - changeDetection: ChangeDetectionStrategy.OnPush + selector: 'app-operator', + templateUrl: './operator.component.html', + styleUrls: ['./operator.component.scss'] }) -export class OperatorComponent { - @Input() operator: OperatorDoc; - - private readonly baseSourceUrl = "https://github.com/ReactiveX/rxjs/blob/master/src/operators/"; - private readonly baseSpecUrl = "http://reactivex.io/rxjs/test-file/spec-js/operators"; +export class OperatorComponent implements OnInit { + public operator: OperatorDoc; + + private readonly baseSourceUrl = 'https://github.com/ReactiveX/rxjs/blob/master/src/operators/'; + private readonly baseSpecUrl = 'http://reactivex.io/rxjs/test-file/spec-js/operators'; + + constructor( + private _activatedRoute: ActivatedRoute, + @Inject(OPERATOR_TOKEN) public operators: OperatorDoc[] + ) {} + + ngOnInit() { + this._activatedRoute.params.pluck('operator').subscribe((name: string) => { + this.operator = this.operators.filter( + (operator: OperatorDoc) => operator.name === name + )[0]; + }); + } get operatorName() { return this.operator.name; } get signature() { - return this.operator.signature || "Signature Placeholder"; + return this.operator.signature || 'Signature Placeholder'; } get marbleUrl() { diff --git a/src/app/operators/operators-routing.module.ts b/src/app/operators/operators-routing.module.ts index 83354d0e..ea38e80e 100644 --- a/src/app/operators/operators-routing.module.ts +++ b/src/app/operators/operators-routing.module.ts @@ -2,8 +2,15 @@ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { OperatorsComponent } from './operators.component'; +import { OperatorComponent } from './components/operator/operator.component'; -const routes: Routes = [{ path: '', component: OperatorsComponent }]; +const routes: Routes = [ + { + path: '', + component: OperatorsComponent, + children: [{ path: ':operator', component: OperatorComponent }] + } +]; @NgModule({ imports: [RouterModule.forChild(routes)], diff --git a/src/app/operators/operators.component.html b/src/app/operators/operators.component.html index ef256efa..cc9f4f87 100644 --- a/src/app/operators/operators.component.html +++ b/src/app/operators/operators.component.html @@ -11,15 +11,12 @@

{{ category }}

+ [routerLink]="['/operators', operator.name]"> {{ operator.name }} - - +