Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.

Commit a7f4182

Browse files
committed
fix(operator): Compute a map of operators
1 parent 2d369a9 commit a7f4182

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/app/operators/components/operator/operator.component.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const OPERATOR_TOKEN = new InjectionToken<string>('operators');
2020
})
2121
export class OperatorComponent implements OnInit {
2222
public operator: OperatorDoc;
23+
public operatorsMap: { string?: OperatorDoc };
2324

2425
private readonly baseSourceUrl = 'https://github.com/ReactiveX/rxjs/blob/master/src/operators/';
2526
private readonly baseSpecUrl = 'http://reactivex.io/rxjs/test-file/spec-js/operators';
@@ -32,13 +33,23 @@ export class OperatorComponent implements OnInit {
3233
) {}
3334

3435
ngOnInit() {
36+
this.operatorsMap = this.operators.reduce(
37+
(acc: { string?: OperatorDoc }, value: OperatorDoc) => {
38+
acc[value.name] = value;
39+
return acc;
40+
},
41+
{}
42+
);
43+
3544
this._activatedRoute.params
3645
.pipe(pluck('operator'))
3746
.subscribe((name: string) => {
38-
this.operator =
39-
this.operators.filter(
40-
(operator: OperatorDoc) => operator.name === name
41-
)[0] || this.notfound();
47+
if (name in this.operatorsMap) {
48+
this.operator = this.operatorsMap[name];
49+
} else {
50+
this.notfound();
51+
return;
52+
}
4253
this._seo.setHeaders({
4354
title: [this.operator.name, this.operator.operatorType],
4455
description: this.operator.shortDescription

0 commit comments

Comments
 (0)