-
Notifications
You must be signed in to change notification settings - Fork 33
/
notes.service.ts
42 lines (31 loc) · 1.09 KB
/
notes.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Injectable } from '@angular/core';
import {SocketService} from '../../../core/services/socket.service';
import {Observable} from 'rxjs/Observable';
@Injectable()
export class NotesService {
notesListed$: Observable<any>;
noteAdded$: Observable<any>;
noteUpdated$: Observable<any>;
noteDeleted$: Observable<any>;
constructor(private socket: SocketService) {
this.socket.join('notes');
// Every socket NOTES event has it's own observable, will be used by ngrx effects
this.notesListed$ = this.socket.listen('[Notes] Listed');
this.noteAdded$ = this.socket.listen('[Notes] Added');
this.noteUpdated$ = this.socket.listen('[Notes] Updated');
this.noteDeleted$ = this.socket.listen('[Notes] Deleted');
}
// These methods will be called by ngrx effects (do not use directly in the components)
listNotes() {
this.socket.emit('[Notes] List');
}
addNote(note) {
this.socket.emit('[Notes] Add', note);
}
updateNote(note) {
this.socket.emit('[Notes] Update', note);
}
deleteNote(note) {
this.socket.emit('[Notes] Delete', note);
}
}