RxJS: firstOrDefault Sample

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.0.7/rx.all.js"></script>
<div id="output" />

Babel + JSX

function print(msg) {
  document.getElementById('output').innerHTML += msg + "<br/>";
}

function showError(o) {
  return o.first((x) => x.length !== 0, null, "")
    .subscribe((x) => {
      if (x === "") {
        print("no error!");
      } else {
        print("error: " + x);
      }
    });
}

print("[Error]");
showError(Rx.Observable.from(["", "", "error 1 1", "", "error 1"]));
print("[No errors]");
showError(Rx.Observable.from(["", "", "", "", ""]));