Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operation on messages in rx-js-chat #58

Open
asker2410 opened this issue May 4, 2018 · 1 comment
Open

Operation on messages in rx-js-chat #58

asker2410 opened this issue May 4, 2018 · 1 comment

Comments

@asker2410
Copy link

this.messages = this.updates
      // watch the updates and accumulate operations on the messages
      .scan((messages: Message[],
             operation: IMessagesOperation) => {
               return operation(messages);
             },

In above code snippet, what operation exactly is ? - "return operation(messages);". I don't see "operation" defined anywhere except there is an interface. I am looking for concrete method.

Thanks!

@vp93
Copy link

vp93 commented Feb 16, 2019

Operations is way to perform changes to all the messages in the stream , at the same time.
In the above snippet operation is an inner function used for concatenation.

.scan((messages: Message[],
operation: IMessagesOperation) => {
return operation(messages); },

Here the incoming message stream is being scanned and then an " operation " is applied to it to add the new messages to the list of existing messages. The "operation" here being a concat operation, as it is updating the message stream with all the new messages.

You can do this manually yourself, without using the operation function, by adding the concatenation procedure in a later function call ( such as the addMessage() ) to update the message stream directly. However, although this leads to more semantic code, the message stream is no longer composable after this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants