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 · $._remember startWith
Status Interface level Implementation level Library
Stable as of March 29, 2017 L2: Interaction creator L3: Stream creator material-motion
UpdatesCurrent StatusInitiation dateCompletion date
First introduced Stable March 29, 2017
platformsrctests
Android View
iOS (Swift) View View
startWith
upstream (T)
initialValue (T)
(T) downstream

startWith specification

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

Overview

startWith emits the provided value and then subscribes upstream and emits all subsequent values with no modification.

Example usage

stream.startWith(0)

upstream  |  downstream
          |  0
20        |  20
80        |  80

MVP

Expose a startWith operator API

class MotionObservable<T> {
  public func startWith(initialValue: T) -> MotionObservable<T> 
}

Create a MotionObservable that emits the initialValue on subscription

The stream should be _remember‘d so that the last value emitted is cached for subsequent subscriptions.

class MotionObservable<T> {
  public func startWith(initialValue: T) -> MotionObservable<T> {
    return MotionObservable { observer in
      observer.next(initialValue)
      let subscription = self.subscribeAndForward(to: observer)
      return {
        subscription.unsubscribe()
      }
    }._remember()
  }
}