Permalink
Browse files

fix hub

  • Loading branch information...
1 parent eec61fd commit 9367f4bf113ccfb10d330abc3fb8774ec3dc02fc Adriano Raiano committed Jul 31, 2012
Showing with 13 additions and 17 deletions.
  1. +12 −16 lib/hub.js
  2. +1 −1 package.json
View
@@ -32,28 +32,22 @@ var EventEmitter2 = require('eventemitter2').EventEmitter2
, Hub
, hubInstance;
-// ## Hub
-Hub = function() {
- this.observer = new Observer();
-
-};
-
-// Inherit prototyp and extend it.
-(function(S) {
-
- var P = S.prototype = new EventEmitter2({
+function getNewHub() {
+ var hub = new EventEmitter2({
wildcard: true, // should the event emitter use wildcards.
delimiter: ':', // the delimiter used to segment namespaces, defaults to `.`.
maxListeners: 1000 // the max number of listeners that can be assigned to an event, defaults to 10.
});
+ hub.observer = new Observer();
+
// __init:__ initializes the hub.
//
// `this.init(getCommandIdFunction)`
//
// - __getCommandIdFunction:__ `function(event){}`
- P.init = function(getCommandIdFunction) {
+ hub.init = function(getCommandIdFunction) {
var self = this;
@@ -89,7 +83,7 @@ Hub = function() {
//
// - __cmd:__ the command
// - __callback:__ `function(event){}` [optional]
- P.sendCommand = function(cmd, callback) {
+ hub.sendCommand = function(cmd, callback) {
if (!cmd.id) {
// get id...
@@ -107,15 +101,17 @@ Hub = function() {
this.emit('commands', cmd);
};
-
-})(Hub);
+
+ return hub;
+}
+
if (!hubInstance) { // just to be shure...
- hubInstance = new Hub();
+ hubInstance = getNewHub();
}
hubInstance.create = function() {
- return new Hub();
+ return getNewHub();
};
module.exports = hubInstance;
View
@@ -1,7 +1,7 @@
{
"author": "adrai"
, "name": "nodeEventedCommand"
- , "version": "0.1.1"
+ , "version": "0.1.2"
, "private": false
, "repository": {
"type": "git"

0 comments on commit 9367f4b

Please sign in to comment.