Stream<ValueUpdate> onValueChange(String path, { int cacheLevel: 1 })

Retrieves a Broadcast Stream which subscribes to path with the specified cacheLevel. The node is only subscribed if there is at least one stream subscription. When the stream subscription count goes to 0, the node is unsubscribed from.

Source

Stream<ValueUpdate> onValueChange(String path, {int cacheLevel: 1}) {
  RespSubscribeListener listener;
  StreamController<ValueUpdate> controller;
  int subs = 0;
  controller = new StreamController<ValueUpdate>.broadcast(onListen: () {
    subs++;
    if (listener == null) {
      listener = this[path].subscribe((ValueUpdate update) {
        controller.add(update);
      }, cacheLevel);
    }
  }, onCancel: () {
    subs--;
    if (subs == 0) {
      listener.cancel();
      listener = null;
    }
  });
  return controller.stream;
}