Created
April 19, 2017 19:10
-
-
Save gmarcos87/563718572ab36542f29bdc63a4e8e692 to your computer and use it in GitHub Desktop.
Websocket messages by ID
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script src="https://unpkg.com/@reactivex/rxjs@5.0.3/dist/global/Rx.js"></script> | |
<script id="jsbin-javascript"> | |
'use strict'; | |
var create = function create() { | |
var subject = new Rx.Subject(); | |
var ws = { | |
onmessage: function onmessage(data) { | |
return subject.next(data); | |
} | |
}; | |
return { | |
ws: ws, | |
obsv: subject.asObservable() | |
}; | |
}; | |
var stream = create(); | |
Rx.Observable.timer(500, 500).take(10).subscribe(function (i) { | |
stream.ws.onmessage(i); | |
}); | |
var a = stream.obsv.filter(function (x) { | |
return x === 1; | |
}).subscribe(function (x) { | |
return console.log('a ', x); | |
}); | |
var b = stream.obsv.filter(function (x) { | |
return x === 2; | |
}).subscribe(function (x) { | |
return console.log('b ', x); | |
}); | |
var c = stream.obsv.filter(function (x) { | |
return x === 3; | |
}).subscribe(function (x) { | |
return console.log('c ', x); | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const create = ()=> { | |
const subject = new Rx.Subject(); | |
let ws = { | |
onmessage: data => subject.next(data) | |
}; | |
return { | |
ws, | |
obsv: subject.asObservable() | |
}; | |
} | |
let stream = create(); | |
Rx.Observable.timer(500, 500) | |
.take(10) | |
.subscribe( i => { | |
stream.ws.onmessage(i); | |
}) | |
let a = stream.obsv.filter(x => x === 1).subscribe(x => console.log('a ', x)) | |
let b = stream.obsv.filter(x => x === 2).subscribe(x => console.log('b ',x)) | |
let c = stream.obsv.filter(x => x === 3).subscribe(x => console.log('c ',x)) | |
</script></body> | |
</html> |
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
'use strict'; | |
var create = function create() { | |
var subject = new Rx.Subject(); | |
var ws = { | |
onmessage: function onmessage(data) { | |
return subject.next(data); | |
} | |
}; | |
return { | |
ws: ws, | |
obsv: subject.asObservable() | |
}; | |
}; | |
var stream = create(); | |
Rx.Observable.timer(500, 500).take(10).subscribe(function (i) { | |
stream.ws.onmessage(i); | |
}); | |
var a = stream.obsv.filter(function (x) { | |
return x === 1; | |
}).subscribe(function (x) { | |
return console.log('a ', x); | |
}); | |
var b = stream.obsv.filter(function (x) { | |
return x === 2; | |
}).subscribe(function (x) { | |
return console.log('b ', x); | |
}); | |
var c = stream.obsv.filter(function (x) { | |
return x === 3; | |
}).subscribe(function (x) { | |
return console.log('c ', x); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment