Created
December 20, 2014 22:49
-
-
Save huang47/3ef91c4ab37ad41f3113 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(). | |
map(function () { | |
return true; | |
}). | |
do(function () { | |
console.log('profile switch success'); | |
}). | |
startWith(false). | |
subscribe(function (isProfileSwitching) { | |
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; | |
}); | |
}). | |
takeUntil(profileSwitchSuccess.asObservable()). | |
subscribe(function () { | |
isProfileSwitching = undefined; | |
console.log('!!!!!!!!!!!!!!!!!!!!!!!!! subscribe happen'); | |
}, function () {}, function () { | |
isProfileSwitching = false; | |
}); | |
}); | |
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