Material Motion Exploring solutions that will empower creators with the tools needed to describe and implement rich, interactive motion on any platform. Edit this page · History
MotionObservable merge
Status Interface level Implementation level Library
Stable as of February 21, 2016 L2: Interaction creator L3: Stream creator material-motion
platformsrctests
Android View
iOS (Swift) View View
JavaScript View View
merge
upstream (T)
stream (MotionObservable)
(T) downstream

merge specification

This is the engineering specification for the MotionObservable operator: merge.

Overview

merge emits values as it receives them, both from upstream and from the provided stream.

Example usage

stream.merge(with: otherStream)

upstream  otherStream  |  downstream
10                     |  10
          20           |  20
50                     |  50
70                     |  70
          15           |  15

MVP

Expose a merge operator API

Use MotionObservable to implement the operator. Accept a MotionObservable of type T.

class MotionObservable<T> {
  public func merge(with stream: MotionObservable<T>) -> MotionObservable<T>

Subscribe to both streams and emit their values

Use MotionObservable to implement the operator. Accept a MotionObservable of type T.

class MotionObservable<T> {
  public func merge(with stream: MotionObservable<T>) -> MotionObservable<T> {
    return MotionObservable<T> { observer in
      let upstreamSubscription = self.subscribe(observer: observer)
      let subscription = stream.subscribe(observer: observer)
      return {
        subscription.unsubscribe()
        upstreamSubscription.unsubscribe()
      }
    }
  }