Skip to content

Commit bd91bed

Browse files
committed
feat: add async pipe
1 parent fbb5e82 commit bd91bed

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

apps/rxjs/14-race-condition/cypress/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "../../../dist/out-tsc",
5-
"module": "commonjs",
5+
"module": "es2015",
66
"types": ["cypress", "node"],
77
"sourceMap": false
88
},

apps/rxjs/14-race-condition/src/app/app.component.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
1-
import {
2-
ChangeDetectionStrategy,
3-
Component,
4-
inject,
5-
OnInit,
6-
} from '@angular/core';
1+
import { AsyncPipe } from '@angular/common';
2+
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
73
import { MatDialog } from '@angular/material/dialog';
8-
import { take } from 'rxjs';
94
import { TopicModalComponent } from './topic-dialog.component';
105
import { TopicService, TopicType } from './topic.service';
116

127
@Component({
138
selector: 'app-root',
149
template: `
15-
<button (click)="openTopicModal()">Open Topic</button>
10+
@if (topics$ | async; as topics) {
11+
<button (click)="openTopicModal(topics)">Open Topic</button>
12+
}
1613
`,
14+
imports: [AsyncPipe],
1715
changeDetection: ChangeDetectionStrategy.OnPush,
1816
})
19-
export class AppComponent implements OnInit {
17+
export class AppComponent {
2018
title = 'rxjs-race-condition';
2119
dialog = inject(MatDialog);
2220
topicService = inject(TopicService);
23-
topics: TopicType[] = [];
21+
topics$ = this.topicService.fakeGetHttpTopic();
2422

25-
ngOnInit(): void {
26-
this.topicService
27-
.fakeGetHttpTopic()
28-
.pipe(take(1))
29-
.subscribe((topics) => (this.topics = topics));
30-
}
31-
32-
openTopicModal() {
23+
openTopicModal(topics: TopicType[]) {
3324
this.dialog.open(TopicModalComponent, {
3425
data: {
35-
topics: this.topics,
26+
topics,
3627
},
3728
});
3829
}

0 commit comments

Comments
 (0)