raptor-pubsub
Advanced tools
Comparing version 0.2.1-beta to 0.2.2-beta
@@ -100,65 +100,21 @@ /* | ||
'use strict'; | ||
var listeners = require('raptor-listeners'); | ||
var EventEmitter = require('events').EventEmitter; | ||
function Message(topic, props) { | ||
listeners.Message.call(this, topic, props); | ||
this.topic = topic; | ||
} | ||
Message.prototype = { | ||
getTopic: function () { | ||
return this.topic; | ||
} | ||
}; | ||
require('raptor-util').inherit(Message, listeners.Message); | ||
var channels = {}; | ||
function Channel(name) { | ||
this.name = name; | ||
this.observable = listeners.createObservable(); | ||
} | ||
Channel.prototype = { | ||
publish: function (topic, data) { | ||
var message; | ||
//Convert the arguments into a Message object if necessary so that we can associate extra information with the message being published | ||
if (listeners.isMessage(topic)) { | ||
message = topic; | ||
} else { | ||
message = require('raptor-pubsub').createMessage(topic, data); | ||
var globalChannel = new EventEmitter(); | ||
globalChannel.channel = function() { | ||
var channel; | ||
if (name) { | ||
channel = channels[name]; | ||
if (!channel) { | ||
channel = new EventEmitter(); | ||
channels[name] = channel; | ||
} | ||
this.observable.publish(message); | ||
return message; | ||
}, | ||
subscribe: function (topic, callback, thisObj) { | ||
return this.observable.subscribe(topic, callback, thisObj); | ||
} else { | ||
channel = new EventEmitter(); | ||
} | ||
return channel; | ||
}; | ||
var channels = {}; | ||
module.exports = { | ||
channel: function (name) { | ||
var channel; | ||
if (name) { | ||
channel = channels[name]; | ||
if (!channel) { | ||
channel = new Channel(name); | ||
channels[name] = channel; | ||
} | ||
} else { | ||
channel = new Channel(); | ||
} | ||
return channel; | ||
}, | ||
global: function () { | ||
return this.channel('global'); | ||
}, | ||
publish: function (topic, props) { | ||
var global = this.global(); | ||
global.publish.apply(global, arguments); | ||
}, | ||
subscribe: function (topic, callback, thisObj) { | ||
var global = this.global(); | ||
return global.subscribe.apply(global, arguments); | ||
}, | ||
createMessage: function (topic, data) { | ||
return new Message(topic, data); | ||
} | ||
}; | ||
module.exports = globalChannel; |
@@ -15,3 +15,3 @@ { | ||
"raptor-util": "^0.2.0-beta", | ||
"raptor-listeners": "^0.2.0-beta" | ||
"events": "^1.0.0" | ||
}, | ||
@@ -28,3 +28,3 @@ "devDependencies": { | ||
}, | ||
"version": "0.2.1-beta" | ||
"version": "0.2.2-beta" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5968
117
+ Addedevents@^1.0.0
+ Addedevents@1.1.1(transitive)
- Removedraptor-listeners@^0.2.0-beta
- Removedraptor-listeners@0.2.0-beta(transitive)