Skip to content

Commit c6aaca4

Browse files
committed
use class syntax in stream-view
- Add 'use strict' to view.js - Remove the harmony flag from README - Remove iojs and add node 4 and 6 to .travis.yml
1 parent be18b58 commit c6aaca4

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
node_js:
2-
- "0.12"
3-
- "iojs"
2+
- "4"
3+
- "6"
44
language: node_js

stream-view/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# stream-view
22

3-
This is a "Hello World" application, using a view that inherits from a Readable stream.
3+
This is a "Hello World" application, using a view that inherits from a Readable stream.
44

55
To invoke, the following command begins listening on localhost:3000.
66

7-
node --harmony app.js
7+
node app.js
88

99
To see results:
1010

stream-view/view.js

+29-29
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
var Readable = require('stream').Readable;
2-
var inherits = require('util').inherits;
3-
var co = require('co');
1+
'use strict';
42

5-
module.exports = View
3+
const Readable = require('stream').Readable;
4+
const co = require('co');
65

7-
inherits(View, Readable);
86

9-
function View(context) {
10-
Readable.call(this, {});
7+
module.exports = class View extends Readable {
118

12-
// render the view on a different loop
13-
co.call(this, this.render).catch(context.onerror);
14-
}
9+
constructor(context) {
10+
super();
11+
12+
// render the view on a different loop
13+
co.call(this, this.render).catch(context.onerror);
14+
}
15+
16+
_read() {}
17+
18+
*render() {
19+
// push the <head> immediately
20+
this.push('<!DOCTYPE html><html><head><title>Hello World</title></head>');
1521

16-
View.prototype._read = function () {};
17-
18-
View.prototype.render = function* () {
19-
// push the <head> immediately
20-
this.push('<!DOCTYPE html><html><head><title>Hello World</title></head>');
21-
22-
// render the <body> on the next tick
23-
var body = yield function (done) {
24-
setImmediate(function () {
25-
done(null, '<p>Hello World</p>');
26-
});
27-
};
28-
this.push('<body>' + body + '</body>');
29-
30-
// close the document
31-
this.push('</html>');
32-
// end the stream
33-
this.push(null);
34-
};
22+
// render the <body> on the next tick
23+
const body = yield done => {
24+
setImmediate(() => done(null, '<p>Hello World</p>'));
25+
};
26+
this.push('<body>' + body + '</body>');
27+
28+
// close the document
29+
this.push('</html>');
30+
31+
// end the stream
32+
this.push(null);
33+
};
34+
}

0 commit comments

Comments
 (0)