Created
May 6, 2017 10:16
-
-
Save Ibro/b1b01d686fdfecdbc0ec62ef23724887 to your computer and use it in GitHub Desktop.
RxJS Socket.IO Angular Chat - Angular Component - Coding Blast - www.codingblast.com
This file contains 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
ngOnInit() { | |
this.chatService | |
.getMessages() | |
.distinctUntilChanged() | |
.filter((message) => message.trim().length > 0) | |
.throttleTime(1000) | |
.scan((acc: string, message: string, index: number) => | |
`${message}(${index + 1})` | |
, 1) | |
.subscribe((message: string) => { | |
const currentTime = moment().format('hh:mm:ss a'); | |
const messageWithTimestamp = `${currentTime}: ${message}`; | |
this.messages.push(messageWithTimestamp); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment