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 _nextOperator $._filter · $._map · delayBy · log · rewrite · threshold · thresholdRange · translationAddedTo
Status Interface level Implementation level Library
Stable as of December 13, 2016 L3: Stream creator L4: Runtime engineering material-motion
platformsrctests
Android View View
iOS (Swift) View View
JavaScript View View
_nextOperator
upstream (T)
(U) downstream

_nextOperator specification

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

Overview

_nextOperator is a means by which new operators can be created. An operator can change, add, or remove values in the stream. An operator can also change the type of emitted values.

MVP

Expose _nextOperator API

operation should be a function that receives two arguments: the value T from upstream and a callback that dispatches a value on the next channel. It will be called every time a new T is received from upstream.

class MotionObservable<T> {
  public func _nextOperator<U>(operation: (T, (U) -> Void) -> Void) -> MotionObservable<U>

Pass next to the operation function

The operation should only be allowed to invoke next. Pass the observer’s next function to the operation.

class MotionObservable<T> {
  public func _nextOperator<U>(operation: (T, (U) -> Void) -> Void) -> MotionObservable<U>
    return MotionObservable<U> { observer in
      let subscription = self.subscribe(next: { value in
        operation(value, observer.next)
      }
      return {
        subscription.unsubscribe()
      }
    }
  }
}