Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
einaros committed Feb 10, 2012
2 parents 09111a0 + 7313b90 commit 2c2f0d2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
VERSION := $(shell node -e "console.log(JSON.parse(require('fs').readFileSync('package.json', 'utf8')).version)")

run-tests:
run-tests: node_modules
@NODE_PATH=lib ./node_modules/.bin/nodeunit test
.PHONY: run-tests

clobber:
git clean -dfx
.PHONY: clobber

parser:
./node_modules/.bin/jison -o lib/parser.js lib/grammar.jison

publish:
npm publish && git tag v$(VERSION) -m "Release v$(VERSION)" && git push && git push --tags
.PHONY: publish

doc/eventsource.json:
@mkdir -p doc
NODE_PATH=lib ./node_modules/.bin/dox < lib/eventsource.js > doc/eventsource.json

node_modules: package.json
npm install
touch $@

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ es = new EventSource('someurl');

See the [spec](http://dev.w3.org/html5/eventsource/) for API docs.

## Example

See https://github.com/einaros/sse-example
1 change: 1 addition & 0 deletions doc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.json
13 changes: 8 additions & 5 deletions lib/eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ function EventSource(url) {
req.end();
}

module.exports = EventSource;

util.inherits(EventSource, events.EventEmitter);
EventSource.prototype.constructor = EventSource; // make stacktraces readable

['open', 'error', 'message'].forEach(function(method) {
Object.defineProperty(EventSource.prototype, 'on' + method, {
/**
* Returns the current listener
*
* @returns {Mixed} the set function or undefined
* @return {Mixed} the set function or undefined
* @api private
*/
get: function get() {
Expand All @@ -52,7 +55,7 @@ util.inherits(EventSource, events.EventEmitter);
* Start listening for events
*
* @param {Function} listener the listener
* @returns {Mixed} the set function or undefined
* @return {Mixed} the set function or undefined
* @api private
*/
set: function set(listener) {
Expand All @@ -65,20 +68,20 @@ util.inherits(EventSource, events.EventEmitter);
/**
* Emulates the W3C Browser based WebSocket interface using addEventListener.
*
* @param {String} method Listen for an event
* @param {Function} event callback
* @see https://developer.mozilla.org/en/DOM/element.addEventListener
* @see http://dev.w3.org/html5/websockets/#the-websocket-interface
* @api public
*/
EventSource.prototype.addEventListener = function(method, listener) {
EventSource.prototype.addEventListener = function addEventListener(method, listener) {
if (typeof listener === 'function') {
// store a reference so we can return the original function again
listener._listener = listener;
this.on(method, listener);
}
};

module.exports = EventSource;

/**
* W3C MessageEvent
*
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
}
],
"devDependencies": {
"nodeunit" : "0.6.4",
"jison": "0.3.6"
"nodeunit" : "0.6.x",
"dox" : "0.1.x",
"jison": "0.3.x"
}
}

0 comments on commit 2c2f0d2

Please sign in to comment.