Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/rxjs/14-race-condition/cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"module": "commonjs",
"module": "es2015",
"types": ["cypress", "node"],
"sourceMap": false
},
Expand Down
29 changes: 10 additions & 19 deletions apps/rxjs/14-race-condition/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,29 @@
import {
ChangeDetectionStrategy,
Component,
inject,
OnInit,
} from '@angular/core';
import { AsyncPipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { take } from 'rxjs';
import { TopicModalComponent } from './topic-dialog.component';
import { TopicService, TopicType } from './topic.service';

@Component({
selector: 'app-root',
template: `
<button (click)="openTopicModal()">Open Topic</button>
@if (topics$ | async; as topics) {
<button (click)="openTopicModal(topics)">Open Topic</button>
}
`,
imports: [AsyncPipe],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent implements OnInit {
export class AppComponent {
title = 'rxjs-race-condition';
dialog = inject(MatDialog);
topicService = inject(TopicService);
topics: TopicType[] = [];
topics$ = this.topicService.fakeGetHttpTopic();

ngOnInit(): void {
this.topicService
.fakeGetHttpTopic()
.pipe(take(1))
.subscribe((topics) => (this.topics = topics));
}

openTopicModal() {
openTopicModal(topics: TopicType[]) {
this.dialog.open(TopicModalComponent, {
data: {
topics: this.topics,
topics,
},
});
}
Expand Down