Skip to content

Commit b218ca6

Browse files
author
Your Name
committed
RxJs Course
1 parent a7724e4 commit b218ca6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/app/common/store.service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ export class Store {
4040
return this.filterByCategory('ADVANCED');
4141
}
4242

43+
selectCourseById(courseId:number) {
44+
return this.courses$
45+
.pipe(
46+
map(courses => courses.find(course => course.id == courseId))
47+
);
48+
}
49+
4350
filterByCategory(category: string) {
4451
return this.courses$
4552
.pipe(

src/app/course/course.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import {merge, fromEvent, Observable, concat} from 'rxjs';
1717
import {Lesson} from '../model/lesson';
1818
import {createHttpObservable} from '../common/util';
19+
import {Store} from '../common/store.service';
1920

2021

2122
@Component({
@@ -25,7 +26,7 @@ import {createHttpObservable} from '../common/util';
2526
})
2627
export class CourseComponent implements OnInit, AfterViewInit {
2728

28-
courseId:string;
29+
courseId:number;
2930

3031
course$ : Observable<Course>;
3132

@@ -34,7 +35,7 @@ export class CourseComponent implements OnInit, AfterViewInit {
3435

3536
@ViewChild('searchInput') input: ElementRef;
3637

37-
constructor(private route: ActivatedRoute) {
38+
constructor(private route: ActivatedRoute, private store: Store) {
3839

3940

4041
}
@@ -43,7 +44,7 @@ export class CourseComponent implements OnInit, AfterViewInit {
4344

4445
this.courseId = this.route.snapshot.params['id'];
4546

46-
this.course$ = createHttpObservable(`/api/courses/${this.courseId}`);
47+
this.course$ = this.store.selectCourseById(this.courseId);
4748

4849
}
4950

0 commit comments

Comments
 (0)