Created
December 20, 2014 22:24
-
-
Save huang47/2897534a92ba47751e69 to your computer and use it in GitHub Desktop.
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
var Rx = require('rx'); | |
var profileSwitchSuccess = new Rx.Subject(); | |
var cacheExpiryInHomeOnForeground = new Rx.Subject(); | |
var loginCheckDone = new Rx.Subject(); | |
profileSwitchSuccess.asObservable(). | |
do(function () { | |
console.log('profile switch success'); | |
}). | |
startWith(true). | |
flatMapLatest(function () { | |
return cacheExpiryInHomeOnForeground.asObservable(). | |
do(function () { | |
console.log('cache expiry in home on forground'); | |
}). | |
flatMapLatest(function () { | |
return loginCheckDone.asObservable(). | |
do(function (isLogin) { | |
console.log('login check done: is login %s', isLogin); | |
}). | |
take(1). | |
filter(function (isLogin) { | |
return true === isLogin; | |
}); | |
}); | |
}). | |
subscribe(function () { | |
console.log('!!!!!!!!!!!!!!!!!!!!!!!!! subscribe happen'); | |
}); | |
cacheExpiryInHomeOnForeground.onNext(true); | |
setTimeout(function () { | |
loginCheckDone.onNext(true); | |
}, 1000); | |
setTimeout(function () { | |
profileSwitchSuccess.onNext(true); | |
}, 2000); | |
setTimeout(function () { | |
cacheExpiryInHomeOnForeground.onNext(true); | |
}, 3000); | |
setTimeout(function () { | |
loginCheckDone.onNext(true); | |
}, 4000); | |
setTimeout(function () { | |
profileSwitchSuccess.onNext(true); | |
}, 5000); | |
setTimeout(function () { | |
cacheExpiryInHomeOnForeground.onNext(true); | |
}, 6000); | |
setTimeout(function () { | |
loginCheckDone.onNext(false); | |
}, 7000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment