made with esnextbin
Created
January 11, 2017 14:22
-
-
Save theadam/eade1426d6ab4ae79abd3d2d2cf991f7 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> | |
<div id="app"><div id="test"></div></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 'zen-observable'; | |
let i = 1; | |
let observable = new Observable(observer => { | |
// Emit a single value after 1 second | |
let x = i++; | |
console.log('subscribed ' + x); | |
let timer = setTimeout(_=> { | |
observer.next("hello " + x); | |
observer.complete(); | |
}, 1000); | |
// On unsubscription, cancel the timer | |
return _=> clearTimeout(timer); | |
}); | |
observable.subscribe(v => console.log(v)); | |
observable.subscribe(v => console.log(v)); | |
observable.subscribe(v => console.log(v)); | |
observable.subscribe(v => console.log(v)); | |
observable.subscribe(v => console.log(v)); |
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": { | |
"zen-observable": "0.4.0" | |
} | |
} |
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 _zenObservable = require('zen-observable'); | |
var _zenObservable2 = _interopRequireDefault(_zenObservable); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
var i = 1; | |
var observable = new _zenObservable2.default(function (observer) { | |
// Emit a single value after 1 second | |
var x = i++; | |
console.log('subscribed ' + x); | |
var timer = setTimeout(function (_) { | |
observer.next("hello " + x); | |
observer.complete(); | |
}, 1000); | |
// On unsubscription, cancel the timer | |
return function (_) { | |
return clearTimeout(timer); | |
}; | |
}); | |
observable.subscribe(function (v) { | |
return console.log(v); | |
}); | |
observable.subscribe(function (v) { | |
return console.log(v); | |
}); | |
observable.subscribe(function (v) { | |
return console.log(v); | |
}); | |
observable.subscribe(function (v) { | |
return console.log(v); | |
}); | |
observable.subscribe(function (v) { | |
return console.log(v); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment