Created
June 4, 2021 18:39
-
-
Save michael-mckenna/cae21c80099a9da7212036fe42b0d061 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// maintains messages across channels | |
private messageDB = {1: [], 2: [], 3: []}; | |
// Tracks messages for the currently selected channel | |
private messageSubject$ = new BehaviorSubject<string[]>([]); | |
public readonly messages$ = this.messageSubject$.asObservable(); | |
private selectedChannelId: number; | |
constructor() { | |
} | |
// the getter will return the last value emitted in message subject | |
private get messages(): string[] { | |
return this.messageSubject$.getValue(); | |
} | |
private set messages(val: string[]) { | |
this.messageSubject$.next(val); | |
this.messageDB[this.selectedChannelId] = val; | |
} | |
getInitialMessagesForChannel(channelId: number) { | |
this.selectedChannelId = channelId; | |
this.messages = this.messageDB[channelId]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment