Skip to content

Instantly share code, notes, and snippets.

@aliyome
Last active July 22, 2018 07:57
Show Gist options
  • Save aliyome/8ad147fec0baf567e2d605fba65e2bae to your computer and use it in GitHub Desktop.
Save aliyome/8ad147fec0baf567e2d605fba65e2bae to your computer and use it in GitHub Desktop.
rxjs playground
// https://rxviz.com/v/7J2laXyo
var a = Rx.Observable
.interval(500)
.take(6)
.groupBy(x => x %2 === 0)
var b = a.flatMap(x => x)
var bb = a.mergeAll()
var sw = a.switchMap(x => x)
var exh = a.exhaustMap(x => x)
var con = a.concatMap(x => x)
var c = a.flatMap(x => x.toArray())
var d = b.scan( (x,y) => x + y)
var e = b.reduce( (x,y) => x + y)
var f = b.buffer(Rx.Observable.interval(1000))
var g = b.take(1)
var h = b.last()
var i = b.elementAt(3)
var j = b.skip(1).take(1)
var k = b.skipWhile(x => x < 3)
var l = b.takeWhile(x => x < 3)
var m = b.map(x => 1).distinct()
var n = b.map(x => 1).distinctUntilChanged()
var o = sw.merge(exh)
var p = b.startWith(3) // initial value
var q = a.combineLatest() // つらい
var r = sw.zip(exh) // 待つ
var s = a.switch()
var t = sw.concat(exh)
/// var u = b.throw(new Error('err'))
// var u = b.tap(x => throw new Error('hoge'))
var u = b.catch(console.log)
var v = b.delay(500)
var w = b.timestamp().map(x => x.timestamp) // {value, timestamp}
var x = b.timeout(600) // 600msの感覚が空かないのでエラーにならない。400ならエラー
var y = b.every(x => x > 3) // 即 false
var z = b.every(x => x > -1) // onComplete時に true
var g1 = b.defaultIfEmpty(999)
var g2 = Rx.Observable.empty().defaultIfEmpty(999)
var g3 = b.count() // onComplete時
var g4 = b.max() // onComplete時
var g5 = b.min() // onComplete時
var h1 = b.publish() // connectable observable
h1.connect() // subscribeした後、connectするまでデータが流れない。復数subscribeしてもpublishまでは共通
var h2 = b.publish().refCount() // connectable なのに connect不要。subscribeで自動connect
//var h3 = b.replay().refCount()
h3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment