View sample
// classic component
class HelloMessage extends React.Component {
render() {
return <div>Hello {this.props.name}</div>;
}
}
// stateless component
const HelloMessage = (props) => {
return <div>Hello {props.name}</div>;
}
View test.js
var Rx = require('rx');
var Observable = Rx.Observable;
var Subject = Rx.Subject;
var hover = new Subject();
var blur = new Subject();
var hovers = hover.asObservable();
var blurs = blur.asObservable();
var HOVER_TIMER = 300;
View rx
var Rx = require('rx');
var pauses = new Rx.Subject();
var ends = new Rx.Subject();
pauses.
flatMap(function () {
return Rx.Observable.amb(
Rx.Observable.timer(1000).
map(function () { return true }),
ends.map(function () { return false })
View -
var Rx = require('rx');
var s1 = new Rx.Subject();
var s2 = new Rx.Subject();
var s3 = new Rx.Subject();
Rx.Observable.merge(s1, s2, s3).
forEach(
console.log.bind(console, 'next'),
console.log.bind(console, 'error'),
View -
var Rx = require('rx');
var throwErrors = Rx.Observable.throw(new Error('tiny url exploded'));
throwErrors.
do(
function () {},
function () {
console.log('handle error');
}
View -
var Rx = require('rx');
var subjects = {};
function create(sn) {
var s = new Rx.Subject();
subjects[sn] = s;
View foo.javascript
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;
}).
View foo.javascript
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');
}).
View foo.javascript
profileSwitchSuccesses.
startWith(true).
flatMapLatest(function () {
return cacheExpiryInHomeOnForegrounds.
flatMapLatest(function() {
return EventManager.observe(EventManager.APP.EVENT_LOGIN_CHECK_DONE).
take(1).
filter(isLoggedIn);
});
}).
View foo.javascript
var Rx = require('rx');
var e1 = new Rx.Subject();
var e2 = new Rx.Subject();
var e3 = new Rx.Subject();
var e1s = e1.asObservable();
var e2s = e2.asObservable();
var e3s = e3.asObservable();