made with esnextbin
Created
September 16, 2016 00:27
-
-
Save trxcllnt/a2adab473947863ee48b01c26b8fae83 to your computer and use it in GitHub Desktop.
esnextbin sketch
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 charset="utf-8"> | |
<title>ESNextbin Sketch</title> | |
<!-- put additional styles and scripts here --> | |
</head> | |
<body> | |
<!-- put markup and other contents here --> | |
<div id="app"></div> | |
</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
import { Observable } from 'rxjs'; | |
const someObservableThatMightBeSyncOrAsync = Observable.create((subscriber) => { | |
let id, isSync = false && Math.random() < 0.5; | |
if (isSync) { | |
subscriber.next(`oops I'm synchronous`); | |
} else { | |
id = setTimeout(() => { | |
subscriber.next(`nice I'm async`); | |
}, 100); | |
} | |
return () => { | |
if (id) { | |
clearTimeout(id); | |
id = null; | |
} | |
} | |
}); | |
try { | |
someObservableThatMightBeSyncOrAsync.subscribe( | |
(x) => { | |
throw "something really bad happened"; | |
}, | |
(e) => { | |
console.log(`handled the error '${e}' nice`); | |
} | |
); | |
} catch(e) { | |
console.error(`sync emission so catch won't work :(`); | |
} |
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
{ | |
"name": "esnextbin-sketch", | |
"version": "0.0.0", | |
"dependencies": { | |
"rxjs": "5.0.0-beta.11" | |
} | |
} |
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"; | |
var _rxjs = require("rxjs"); | |
var someObservableThatMightBeSyncOrAsync = _rxjs.Observable.create(function (subscriber) { | |
var id = void 0, | |
isSync = false && Math.random() < 0.5; | |
if (isSync) { | |
subscriber.next("oops I'm synchronous"); | |
} else { | |
id = setTimeout(function () { | |
subscriber.next("nice I'm async"); | |
}, 100); | |
} | |
return function () { | |
if (id) { | |
clearTimeout(id); | |
id = null; | |
} | |
}; | |
}); | |
try { | |
someObservableThatMightBeSyncOrAsync.subscribe(function (x) { | |
throw "something really bad happened"; | |
}, function (e) { | |
console.log("handled the error '" + e + "' nice"); | |
}); | |
} catch (e) { | |
console.error("sync emission so catch won't work :("); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment