Skip to content

Commit b034577

Browse files
committed
feat: race-condition
1 parent 0d15a0b commit b034577

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

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

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,32 @@
1-
import {
2-
ChangeDetectionStrategy,
3-
Component,
4-
inject,
5-
OnInit,
6-
} from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
2+
import { toSignal } from '@angular/core/rxjs-interop';
73
import { MatDialog } from '@angular/material/dialog';
4+
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
85
import { take } from 'rxjs';
96
import { TopicModalComponent } from './topic-dialog.component';
10-
import { TopicService, TopicType } from './topic.service';
7+
import { TopicService } from './topic.service';
118

129
@Component({
1310
standalone: true,
1411
selector: 'app-root',
12+
imports: [MatProgressSpinnerModule],
1513
template: `
16-
<button (click)="openTopicModal()">Open Topic</button>
14+
@if (topics()) {
15+
<button (click)="openModal()">Open Topic</button>
16+
}
1717
`,
1818
changeDetection: ChangeDetectionStrategy.OnPush,
1919
})
20-
export class AppComponent implements OnInit {
20+
export class AppComponent {
2121
title = 'rxjs-race-condition';
22-
dialog = inject(MatDialog);
2322
topicService = inject(TopicService);
24-
topics: TopicType[] = [];
23+
matDialog = inject(MatDialog);
24+
topics = toSignal(this.topicService.fakeGetHttpTopic().pipe(take(1)));
2525

26-
ngOnInit(): void {
27-
this.topicService
28-
.fakeGetHttpTopic()
29-
.pipe(take(1))
30-
.subscribe((topics) => (this.topics = topics));
31-
}
32-
33-
openTopicModal() {
34-
this.dialog.open(TopicModalComponent, {
26+
openModal(): void {
27+
this.matDialog.open(TopicModalComponent, {
3528
data: {
36-
topics: this.topics,
29+
topics: this.topics(),
3730
},
3831
});
3932
}

0 commit comments

Comments
 (0)