Skip to content

Instantly share code, notes, and snippets.

@hekike
Last active August 29, 2015 14:11
Show Gist options
  • Save hekike/2af764c859e18464557e to your computer and use it in GitHub Desktop.
Save hekike/2af764c859e18464557e to your computer and use it in GitHub Desktop.
Mixed highlandjs and node streams
var stream = require('stream');
var _ = require('highland');
var $ = require('jquery');
var toConsoleStream = new stream.Writable({ objectMode: true });
toConsoleStream._write = function (data, encoding, done) {
console.log(data);
done();
};
_('click', $('#button'))
.throttle(200)
.map(1)
.scan(0, _.add)
.pipe(toConsoleStream);
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-type' content='text/html; charset=utf-8'>
<title>FRP</title>
</head>
<body>
<button id="button">BUTTON</button>
<script src="bundle.js"></script>
</body>
</html>
{
"name": "frp-node-stream",
"version": "0.0.1",
"main": "app.js",
"scripts": {
"bundle": "webpack-dev-server",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"webpack": "^1.4.13",
"webpack-dev-server": "^1.6.6"
},
"dependencies": {
"highland": "^2.2.0",
"jquery": "^2.1.1"
}
}
module.exports = {
entry: {
app: ['./app.js']
},
output: {
path: './',
filename: 'bundle.js'
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment