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 _read
$._remember
Status Interface level Implementation level Library
Stable as of December 13, 2016 L3: Stream creator L4: Runtime engineering material-motion
platformsrctests
iOS (Swift) View
JavaScript View View

_read specification

This is the engineering specification for the MotionObservable convenience method: _read.

Overview

_read subscribes to a stream and synchronously returns the first emitted value, if any.

Note: this API is provided as a stop-gap solution for building connected streams. In general it’s preferred that streams be subscribed to and their last values cached in some manner. The _remember operator can be a helpful tool for making this easier:

let memoryStream = stream._remember()
let subscription = memoryStream.subscribe { value in
  // No need to do anything.
}

// Later, when we need the value:
let latestValue = memoryStream._read()

MVP

Expose _read API

class MotionObservable<T> {

  public func _read() -> T? {
    var value: T?
    self.subscribe { value = $0 }
    return value
  }