Last active
June 8, 2017 21:41
-
-
Save brabadu/8b3596559099d4cb5d101d1ecdcc4f02 to your computer and use it in GitHub Desktop.
Experiments with effect cancelation in tanok
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Rx from 'rx'; | |
Rx.config.longStackSupport = true; | |
function firstFx(n){ | |
const a = function (stream, bus) { | |
return Rx.Observable | |
.fromPromise( | |
new Promise((resolve) => setTimeout(() => resolve(n + a.label), 1000)) | |
) | |
.takeUntil(bus.filter((i) => i.label === 'first')) | |
.do((i) => console.log('First', i)); | |
} | |
a.label = 'first'; | |
return a; | |
} | |
function secondFx(n){ | |
const a = function (stream, bus) { | |
return Rx.Observable | |
.fromPromise( | |
new Promise((resolve) => setTimeout(() => resolve(n + a.label), 1000)) | |
) | |
.takeUntil(bus.filter((i) => i.label === 'second')) | |
.do((i) => console.log('Second', i)); | |
} | |
a.label = 'second'; | |
return a; | |
} | |
function thirdFx(n) { | |
return (stream, bus) => console.log('Third, immidiately', n); | |
} | |
const s = new Rx.Subject(); | |
s | |
.flatMap((obj) => obj(null, s) || []) | |
.subscribe() | |
let count = 0 | |
document.querySelector('#one').addEventListener( | |
'click', () => s.onNext(firstFx(count++))); | |
document.querySelector('#two').addEventListener( | |
'click', () => s.onNext(secondFx(count++))); | |
document.querySelector('#three').addEventListener( | |
'click', () => s.onNext(thirdFx(count++))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment