Comparing version 0.2.0 to 0.3.0
@@ -26,3 +26,3 @@ 'use strict'; | ||
Client.prototype.close = function () { | ||
Client.prototype.disconnect = function () { | ||
this.res.end(); | ||
@@ -29,0 +29,0 @@ this.res.removeAllListeners(); |
@@ -24,3 +24,3 @@ 'use strict'; | ||
heartbeatTimer.removeListener('tick', sendHeartbeat); | ||
client.emit('close'); | ||
client.emit('disconnect'); | ||
client.removeAllListeners(); | ||
@@ -35,3 +35,3 @@ }); | ||
callback(client); | ||
client.emit('open'); | ||
client.emit('connect'); | ||
}; | ||
@@ -38,0 +38,0 @@ }; |
{ | ||
"name": "json-lines", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "json-lines streams JSON Lines.", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
@@ -17,11 +17,11 @@ # json-lines | ||
To send JSON you need an Express application and a route that you want to use. Then subscribe to the `open` and `close` events to initialize or end data transfer. | ||
To send JSON you need an Express application and a route that you want to use. Then subscribe to the `connect` and `disconnect` events to initialize or end data transfer. | ||
```javascript | ||
app.get('/events', jsonLines(function (client) { | ||
client.once('open', function () { | ||
client.once('connect', function () { | ||
// ... | ||
}); | ||
client.once('close', function () { | ||
client.once('disconnect', function () { | ||
// ... | ||
@@ -32,3 +32,3 @@ }); | ||
Within the `open` event handler, you can use the `send` function to actually stream data to the client. | ||
Within the `connect` event handler, you can use the `send` function to actually stream data to the client. | ||
@@ -41,6 +41,6 @@ ```javascript | ||
If you want to close the connection, call the `close` function. This will emit the `close` event and clean up any event listeners. | ||
If you want to close the connection to the client, call the `disconnect` function. This will emit the `disconnect` event and clean up any event listeners. | ||
```javascript | ||
client.close(); | ||
client.disconnect(); | ||
``` | ||
@@ -47,0 +47,0 @@ |
@@ -29,5 +29,5 @@ 'use strict'; | ||
test('emits an open event when the client connects.', function (done) { | ||
test('emits a connect event when the client connects.', function (done) { | ||
app.get('/', route(function (client) { | ||
client.once('open', function () { | ||
client.once('connect', function () { | ||
done(); | ||
@@ -45,5 +45,5 @@ }); | ||
test('emits a close event when the client disconnects.', function (done) { | ||
test('emits a disconnect event when the client disconnects.', function (done) { | ||
app.get('/', route(function (client) { | ||
client.once('close', function () { | ||
client.once('disconnect', function () { | ||
done(); | ||
@@ -61,7 +61,7 @@ }); | ||
test('is able to close a client.', function (done) { | ||
test('is able to disconnect a client.', function (done) { | ||
app.get('/', route(function (client) { | ||
client.once('open', function () { | ||
client.once('connect', function () { | ||
client.send({ foo: 'bar' }); | ||
client.close(); | ||
client.disconnect(); | ||
}); | ||
@@ -81,9 +81,9 @@ })); | ||
test('emits a close event when the client is closed from the server.', function (done) { | ||
test('emits a disconnect event when the client is disconnected from the server.', function (done) { | ||
app.get('/', route(function (client) { | ||
client.once('open', function () { | ||
client.close(); | ||
client.once('connect', function () { | ||
client.disconnect(); | ||
}); | ||
client.once('close', function () { | ||
client.once('disconnect', function () { | ||
done(); | ||
@@ -103,10 +103,10 @@ }); | ||
app.get('/', route(function (client) { | ||
client.on('open', function () { | ||
client.on('connect', function () { | ||
// Intentionally left blank... | ||
}); | ||
client.on('close', function () { | ||
client.on('disconnect', function () { | ||
process.nextTick(function () { | ||
assert.that(client.listeners('open').length).is.equalTo(0); | ||
assert.that(client.listeners('close').length).is.equalTo(0); | ||
assert.that(client.listeners('connect').length).is.equalTo(0); | ||
assert.that(client.listeners('disconnect').length).is.equalTo(0); | ||
done(); | ||
@@ -154,3 +154,3 @@ }); | ||
client.once('open', function () { | ||
client.once('connect', function () { | ||
timer.on('tick', function () { | ||
@@ -161,3 +161,3 @@ client.send({ counter: counter++ }); | ||
client.once('close', function () { | ||
client.once('disconnect', function () { | ||
timer.destroy(); | ||
@@ -187,3 +187,3 @@ }); | ||
app.get('/', route(function (client) { | ||
client.once('open', function () { | ||
client.once('connect', function () { | ||
client.send({ text: 'foo\nbar' }); | ||
@@ -213,3 +213,3 @@ }); | ||
app.get('/', route(function (client) { | ||
client.once('open', function () { | ||
client.once('connect', function () { | ||
assert.that(function () { | ||
@@ -232,3 +232,3 @@ client.send(undefined); | ||
app.get('/', route(function (client) { | ||
client.once('open', function () { | ||
client.once('connect', function () { | ||
assert.that(function () { | ||
@@ -235,0 +235,0 @@ client.send(null); |
11056