Created
December 5, 2015 02:33
-
-
Save anonymous/14c372e822927b9b5056 to your computer and use it in GitHub Desktop.
rxjs behaviour subject rxjs behaviour subject // source https://jsbin.com/hovada
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="rxjs behaviour subject"> | |
<meta charset="utf-8"> | |
<title>rxjs behaviour subject</title> | |
</script> | |
<script src="https://npmcdn.com/@reactivex/[email protected]/dist/global/Rx.js"></script> | |
</head> | |
<body> | |
<ui-view></ui-view> | |
<script id="jsbin-javascript"> | |
'use strict'; | |
console.clear(); | |
var start = Date.now(); | |
var observable = Rx.Observable.interval(250).take(4).map(function (x) { | |
console.log(x + ' ~ ' + (Date.now() - start) / 1000); | |
return x; | |
}).publish().refCount(); | |
setTimeout(add.bind(null, 'a', 0), 500); | |
setTimeout(add.bind(null, 'b', 260), 750); | |
function add(label, delay) { | |
var derrived = new Rx.BehaviorSubject(); | |
observable.subscribe(derrived); | |
setTimeout(function () { | |
return derrived.subscribe(log(label)); | |
}, delay); | |
} | |
function log(label) { | |
console.log('subscribe: ' + label); | |
return function (value) { | |
return console.log(' ' + label + ':' + value); | |
}; | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">console.clear(); | |
var start = Date.now(); | |
var observable = Rx.Observable.interval(250).take(4) | |
.map((x) => { | |
console.log(x + ' ~ ' + (Date.now() - start) / 1000); | |
return x; | |
}) | |
.publish() | |
.refCount(); | |
setTimeout(add.bind(null, 'a', 0), 500); | |
setTimeout(add.bind(null, 'b', 260), 750); | |
function add(label, delay) { | |
var derrived = new Rx.BehaviorSubject(); | |
observable.subscribe(derrived); | |
setTimeout(() => derrived.subscribe(log(label)), delay); | |
} | |
function log(label) { | |
console.log('subscribe: ' + label); | |
return (value) => console.log(' ' + label + ':' + value); | |
}</script></body> | |
</html> |
This file contains hidden or 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
'use strict'; | |
console.clear(); | |
var start = Date.now(); | |
var observable = Rx.Observable.interval(250).take(4).map(function (x) { | |
console.log(x + ' ~ ' + (Date.now() - start) / 1000); | |
return x; | |
}).publish().refCount(); | |
setTimeout(add.bind(null, 'a', 0), 500); | |
setTimeout(add.bind(null, 'b', 260), 750); | |
function add(label, delay) { | |
var derrived = new Rx.BehaviorSubject(); | |
observable.subscribe(derrived); | |
setTimeout(function () { | |
return derrived.subscribe(log(label)); | |
}, delay); | |
} | |
function log(label) { | |
console.log('subscribe: ' + label); | |
return function (value) { | |
return console.log(' ' + label + ':' + value); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment