     }))
   }
 
+  /**
+   Creates a child runtime instance.
+
+   Streams registered to a child runtime will affect the state on that runtime and all of its
+   ancestors.
+   */
+  public func createChild() -> MotionRuntime {
+    return MotionRuntime(parent: self)
+  }
+
+  /** Creates a child motion runtime instance. */
+  private init(parent: MotionRuntime) {
+    self.parent = parent
+    parent.children.append(self)
+  }
+
   private func stateDidChange(_ state: MotionState, for token: String) {
     if state == .active {
       activeSubscriptions.insert(token)


  /** Creates a motion runtime instance. */
  public init() {
  }

  /** Subscribes to the stream, writes its output to the given property, and observes its state. */

    if oldState != newState {
      self.state.write(newState)
    }

    if let parent = parent {
      parent.stateDidChange(state, for: token)
    }
  }

  private weak var parent: MotionRuntime?
  private var children: [MotionRuntime] = []
  private var subscriptions: [Subscription] = []

  private typealias Token = String
