Permalink
Browse files

[cleanup] this cleanup the inherent flow

Fix #1 there was a lot of .parent, the unnessarry .parent has been removed and the rest has been renamed
  • Loading branch information...
1 parent 7219f45 commit 6ca5df62eb0c6592a6c12d0c710238c91294694c @AndreasMadsen committed Mar 1, 2012
Showing with 29 additions and 38 deletions.
  1. +3 −6 lib/core/abstract.js
  2. +4 −4 lib/core/lisenter.js
  3. +13 −14 lib/core/message.js
  4. +9 −12 lib/core/requester.js
  5. +0 −2 lib/layers/IPC.js
View
@@ -46,14 +46,13 @@
/**
* Listener abstract layer
*/
- function ListenerAbstract(parent, object, layerID) {
+ function ListenerAbstract(object, layerID) {
var self = this;
this.layerID = layerID;
this.connections = {};
this.online = false;
this.object = object;
- this.parent = parent;
this.handlers = {};
this.on('listening', function () {
@@ -69,14 +68,13 @@
/**
* Listener abstract layer
*/
- function CommunicationAbstract(parent, object, layerID, assignID) {
+ function CommunicationAbstract(object, layerID, assignID) {
var self = this;
this.assignID = assignID;
this.layerID = layerID;
this.online = false;
this.object = object;
- this.parent = parent;
this.handlers = {};
this.handle = null;
@@ -101,12 +99,11 @@
/**
* Requester abstract layer
*/
- function RequesterAbstract(parent, object) {
+ function RequesterAbstract(object) {
var self = this;
this.assignID = null;
this.online = false;
- this.parent = parent;
this.object = object;
this.handlers = {};
this.handle = null;
View
@@ -39,7 +39,7 @@
// Create and store layer object
this.layerID += 1;
- var layer = new layerCollection.Listener(this, object, this.layerID);
+ var layer = new layerCollection.Listener(object, this.layerID);
this.layers[layer.layerID] = layer;
// Relay errors form layer to top
@@ -88,7 +88,7 @@
// Create new connection and assing with ID
self.assignID += 1;
- var communcation = new layerCollection.Communication(self, object, layer.layerID, self.assignID);
+ var communcation = new layerCollection.Communication(object, layer.layerID, self.assignID);
self.connections[communcation.assignID] = communcation;
layer.connections[communcation.assignID] = communcation;
@@ -129,7 +129,7 @@
var self = this;
// check that communcation is online
- if (this.self.online === false) {
+ if (this.communication.online === false) { // FIX ME: ipc has no online property
this.root.emit('error', new Error("could not handle a request from a online communication"));
return;
}
@@ -154,7 +154,7 @@
if (!(err instanceof Error)) {
error = new Error(err);
}
- self.root.emit('request', error, method, args, null);
+ this.root.emit('request', error, method, args, null);
this.callback(false, helpers.error2object(error));
}
};
View
@@ -10,10 +10,9 @@
exports.globalHandlers = {};
- function MessageHandler(parent, handlers) {
+ function MessageHandler(root, handlers) {
this.handlers = helpers.mergeObjects(handlers, exports.globalHandlers);
- this.root = parent;
- this.parent = parent;
+ this.root = root;
this.callbacks = {};
this.callbackID = 0;
}
@@ -23,22 +22,22 @@
return new SubHandler(this, communication);
};
- function SubHandler(parent, communication) {
- this.root = parent.root;
- this.parent = parent;
+ function SubHandler(master, communication) {
+ this.root = master.root;
+ this.master = master;
this.communication = communication;
}
SubHandler.prototype.handleMessage = function(message) {
var self = this;
if (message.query) {
- this.parent.callbacks[message.query].apply(null, message.args);
+ this.master.callbacks[message.query].apply(null, message.args);
} else if(message.echo) {
- this.parent.handlers[message.method].apply({
- self: self,
- communication: self.communication,
- root: self.root,
+ this.master.handlers[message.method].apply({
+ ipc: this,
+ communication: this.communication,
+ root: this.root,
callback: function () {
self.communication.send({
query: message.echo,
@@ -50,15 +49,15 @@
};
SubHandler.prototype.send = function (method, args, callback) {
- var nextID = this.parent.callbackID += 1;
+ var nextID = this.master.callbackID += 1;
this.communication.send({
method: method,
args: args,
echo: nextID
});
- this.parent.callbacks[nextID] = callback;
+ this.master.callbacks[nextID] = callback;
};
-})();
+})();
View
@@ -30,7 +30,7 @@
// Create and store layer object
var layerCollection = exports.layers[layerName];
- this.layer = new layerCollection.Requester(this, object);
+ this.layer = new layerCollection.Requester(object);
// add lisenter to connect stack
if (this.lisenter) {
@@ -82,7 +82,7 @@
layer.assignID = id;
// setup all request functions
- this.root.remote = new RemoteWrapper(this.self, methods);
+ this.root.remote = new RemoteWrapper(this.ipc, methods);
// this will set online in remote
this.callback();
@@ -94,11 +94,11 @@
/**
* RemoteWrapper
*/
- function RemoteWrapper(parent, methods) {
+ function RemoteWrapper(ipc, methods) {
function requestWrapper(name) {
return function () {
- request(parent, name, arguments);
+ request(ipc, name, helpers.toArray(arguments));
};
}
@@ -109,28 +109,25 @@
}
// request a method from the listener
- function request(parent, name, args) {
+ function request(ipc, name, args) {
// check online
- if (!parent.root.online) {
- parent.root.emit('error', new Error("Could not make a request, channel is offline"));
+ if (!ipc.root.online) {
+ ipc.root.emit('error', new Error("Could not make a request, channel is offline"));
return;
}
- // convert args to a real array
- args = helpers.toArray(args);
-
// store callback for later
var callback = args.pop();
// check that a callback is set
if (typeof callback !== 'function') {
- parent.root.emit('error', new TypeError("No callback specified"));
+ ipc.root.emit('error', new TypeError("No callback specified"));
return;
}
// send request to remote
- parent.send('call', [name, args], function (sucess, content) {
+ ipc.send('call', [name, args], function (sucess, content) {
if (sucess) {
callback.apply({
error: null
View
@@ -113,8 +113,6 @@
// this will be called from core, when a message need to be sended
// 1: when a method in the remote object is called
Requester.prototype.send = function (message) {
- // we will not send messages if the channel is closed
- if (this.online === false) return;
// just send message JSON will be handled by node.js core
this.object.send(message);

0 comments on commit 6ca5df6

Please sign in to comment.