Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

published a new version 0.1.1

  • Loading branch information...
commit eec61fd23aa8096885e90b279147fd1e6ab982d7 1 parent 8328645
@adrai authored
View
2  index.js
@@ -6,7 +6,7 @@ if (typeof module.exports !== 'undefined') {
index = root.index = {};
}
-index.VERSION = '0.0.1';
+index.VERSION = '0.1.1';
index.hub = require('./lib/hub');
index.Command = require('./lib/command');
View
2  lib/command.js
@@ -1,4 +1,4 @@
-// lib/command.js v0.0.1
+// lib/command.js v0.1.1
// (c) 2012 Adriano Raiano (adrai); under MIT License
// This is the wrapper object for the commands.
View
108 lib/hub.js
@@ -1,4 +1,4 @@
-// lib/hub.js v0.0.1
+// lib/hub.js v0.1.1
// (c) 2012 Adriano Raiano (adrai); under MIT License
// The hub is the module that have to wire up the commands and events.
@@ -7,24 +7,24 @@
//
// var hub = require('nodeEventedCommand').hub;
//
-// // initialize the hub by passing the function that gets the command id from the event
-// hub.init(
-// function(evt) {
-// var idEndIndex = evt.id.indexOf('_event');
-// var id = evt.id.substring(0, idEndIndex);
-// return id;
-// }
-// );
+// // initialize the hub by passing the function that gets the command id from the event
+// hub.init(
+// function(evt) {
+// var idEndIndex = evt.id.indexOf('_event');
+// var id = evt.id.substring(0, idEndIndex);
+// return id;
+// }
+// );
//
// // pass in events from your bus
-// bus.on('events', function(data){
-// hub.emit('events', data);
-// });
+// bus.on('events', function(data){
+// hub.emit('events', data);
+// });
//
-// // pass commands to bus
-// hub.on('commands', function(data) {
-// bus.emit('commands', data);
-// });
+// // pass commands to bus
+// hub.on('commands', function(data) {
+// bus.emit('commands', data);
+// });
var EventEmitter2 = require('eventemitter2').EventEmitter2
, uuid = require('./uuid')
@@ -35,7 +35,7 @@ var EventEmitter2 = require('eventemitter2').EventEmitter2
// ## Hub
Hub = function() {
- this.observer = new Observer();
+ this.observer = new Observer();
};
@@ -43,10 +43,10 @@ Hub = function() {
(function(S) {
var P = S.prototype = 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.
- });
+ 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.
+ });
// __init:__ initializes the hub.
//
@@ -54,32 +54,32 @@ Hub = function() {
//
// - __getCommandIdFunction:__ `function(event){}`
P.init = function(getCommandIdFunction) {
-
- var self = this;
+
+ var self = this;
- // listen on events...
- this.on('event:*', function(evt) {
+ // listen on events...
+ this.on('event:*', function(evt) {
- var eventName = this.event.substr(6);
-
- var commandCallback = self.observer.getPendingCommand(getCommandIdFunction(evt), eventName);
+ var eventName = this.event.substr(6);
+
+ var commandCallback = self.observer.getPendingCommand(getCommandIdFunction(evt), eventName);
- if (commandCallback) {
- commandCallback(evt);
- }
+ if (commandCallback) {
+ commandCallback(evt);
+ }
- });
+ });
- // listen on events...
- this.on('events', function(evt) {
-
- var commandCallback = self.observer.getPendingCommand(getCommandIdFunction(evt));
+ // listen on events...
+ this.on('events', function(evt) {
+
+ var commandCallback = self.observer.getPendingCommand(getCommandIdFunction(evt));
- if (commandCallback) {
- commandCallback(evt);
- }
+ if (commandCallback) {
+ commandCallback(evt);
+ }
- });
+ });
};
@@ -91,31 +91,31 @@ Hub = function() {
// - __callback:__ `function(event){}` [optional]
P.sendCommand = function(cmd, callback) {
- if (!cmd.id) {
- // get id...
- cmd.id = uuid().toString();
- }
+ if (!cmd.id) {
+ // get id...
+ cmd.id = uuid().toString();
+ }
- if (typeof callback === 'function') {
- this.observer.observe(cmd.id, callback);
- } else {
- for(var m in callback) {
- this.observer.observe(cmd.id, m, callback[m]);
- }
- }
+ if (typeof callback === 'function') {
+ this.observer.observe(cmd.id, callback);
+ } else {
+ for(var m in callback) {
+ this.observer.observe(cmd.id, m, callback[m]);
+ }
+ }
- this.emit('commands', cmd);
+ this.emit('commands', cmd);
};
})(Hub);
if (!hubInstance) { // just to be shure...
- hubInstance = new Hub();
+ hubInstance = new Hub();
}
hubInstance.create = function() {
- return new Hub();
+ return new Hub();
};
module.exports = hubInstance;
View
2  lib/observer.js
@@ -1,4 +1,4 @@
-// lib/observer.js v0.0.1
+// lib/observer.js v0.1.1
// (c) 2012 Adriano Raiano (adrai); under MIT License
// The command observer... observes a command until an event is coming...
View
5 npmlink.js
@@ -1,5 +0,0 @@
-module.exports = {
- global: true,
- dependencies: []
-};
-
View
2  package.json
@@ -1,7 +1,7 @@
{
"author": "adrai"
, "name": "nodeEventedCommand"
- , "version": "0.1.0"
+ , "version": "0.1.1"
, "private": false
, "repository": {
"type": "git"
Please sign in to comment.
Something went wrong with that request. Please try again.