made with esnextbin
Last active
March 24, 2017 18:42
-
-
Save TylorS/04a3f25c77a586994289d7ec9499a763 to your computer and use it in GitHub Desktop.
esnextbin sketch
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"> | |
<title>ESNextbin Sketch</title> | |
<!-- put additional styles and scripts here --> | |
</head> | |
<body> | |
<!-- put markup and other contents here --> | |
</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
import { Stream, multicast, just } from 'most' | |
const syncJust = a => new Stream(new Just(a)) | |
class Just { | |
constructor (a) { | |
this.a = a | |
} | |
run (sink, scheduler) { | |
sink.event(scheduler.now(), this.a) | |
sink.end(scheduler.now(), this.a) | |
return { dispose: Function.prototype } | |
} | |
} | |
const running = stream => new Stream(new Running(stream.source)) | |
class Running { | |
constructor(source) { | |
this.source = source | |
} | |
run(sink, scheduler) { | |
console.log('running') | |
return this.source.run(sink, scheduler) | |
} | |
} | |
const foo$ = multicast(running(syncJust('foo'))) | |
foo$.observe(x => console.log('1', x)) | |
foo$.observe(x => console.log('2', x)) | |
const bar$ = multicast(running(just('bar'))) | |
bar$.observe(x => console.log('1', x)) | |
bar$.observe(x => console.log('2', x)) |
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
{ | |
"name": "esnextbin-sketch", | |
"version": "0.0.0", | |
"dependencies": { | |
"most": "1.2.2", | |
"babel-runtime": "6.22.0" | |
} | |
} |
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 _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | |
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | |
var _createClass2 = require('babel-runtime/helpers/createClass'); | |
var _createClass3 = _interopRequireDefault(_createClass2); | |
var _most = require('most'); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
var syncJust = function syncJust(a) { | |
return new _most.Stream(new Just(a)); | |
}; | |
var Just = function () { | |
function Just(a) { | |
(0, _classCallCheck3.default)(this, Just); | |
this.a = a; | |
} | |
(0, _createClass3.default)(Just, [{ | |
key: 'run', | |
value: function run(sink, scheduler) { | |
sink.event(scheduler.now(), this.a); | |
sink.end(scheduler.now(), this.a); | |
return { dispose: Function.prototype }; | |
} | |
}]); | |
return Just; | |
}(); | |
var running = function running(stream) { | |
return new _most.Stream(new Running(stream.source)); | |
}; | |
var Running = function () { | |
function Running(source) { | |
(0, _classCallCheck3.default)(this, Running); | |
this.source = source; | |
} | |
(0, _createClass3.default)(Running, [{ | |
key: 'run', | |
value: function run(sink, scheduler) { | |
console.log('running'); | |
return this.source.run(sink, scheduler); | |
} | |
}]); | |
return Running; | |
}(); | |
var foo$ = (0, _most.multicast)(running(syncJust('foo'))); | |
foo$.observe(function (x) { | |
return console.log('1', x); | |
}); | |
foo$.observe(function (x) { | |
return console.log('2', x); | |
}); | |
var bar$ = (0, _most.multicast)(running((0, _most.just)('bar'))); | |
bar$.observe(function (x) { | |
return console.log('1', x); | |
}); | |
bar$.observe(function (x) { | |
return console.log('2', x); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment