mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-13 14:23:02 -05:00
feat(challenge 7): begin ngrx notification work
This commit is contained in:
27
apps/ngrx-notification/src/app/backend/push.service.ts
Normal file
27
apps/ngrx-notification/src/app/backend/push.service.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, tap, timer } from 'rxjs';
|
||||
import { randStudent } from '../model/student.model';
|
||||
import { randTeacher } from '../model/teacher.model';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PushService {
|
||||
private notificationSubject = new BehaviorSubject<any>(undefined);
|
||||
notification$ = this.notificationSubject.asObservable();
|
||||
|
||||
init() {
|
||||
this.startTeacherNotification();
|
||||
this.startStudentNotification();
|
||||
}
|
||||
|
||||
private startTeacherNotification() {
|
||||
timer(0, 4000)
|
||||
.pipe(tap(() => this.notificationSubject.next(randTeacher())))
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
private startStudentNotification() {
|
||||
timer(1000, 3000)
|
||||
.pipe(tap(() => this.notificationSubject.next(randStudent())))
|
||||
.subscribe();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user