Created
January 6, 2017 22:14
-
-
Save argyleink/ad950658d173ca37064fecc6b1d43a68 to your computer and use it in GitHub Desktop.
There an easier way? RXJS subject to increment likes on an array object
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
// this really what it takes to increment a counter on an item in my observable | |
// likes is a subject, broadcasting the updated array eventually to the source observable being rendered | |
this.likes | |
.map( | |
(message: Message): IMessagesOperation => | |
(messages: Message[]) => { | |
return messages.map((m: Message) => { | |
// todo: check if user has already liked | |
if (m.id == message.id) | |
++m.likes | |
return m | |
}) | |
} | |
) | |
.subscribe(this.updates) | |
// help me find a better way please =) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you think about using .reduce() operator?