Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
markyen committed Feb 9, 2015
1 parent acd8ccc commit 25dc21f
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,29 +848,32 @@ RingPop.prototype.handleOrProxyAll =
var keys = opts.keys;
var req = opts.req;
var localHandler = opts.localHandler;
var whoami = this.whoami();

var reses = {};
var dests = mapUniq(keys, this.lookup.bind(this));
dests.forEach(function(dest) {
return dests.reduce(function(responses, dest) {
var res = hammock.Response();
if (self.whoami() === dest) {
if (whoami === dest) {
self.logger.trace('handleOrProxyAll was handled', {
keys: keys,
url: req && req.url
});
process.nextTick(localHandler.bind(null, req, res));
} else {
process.nextTick(self.proxyReq.bind(self, _.defaults({
dest: dest,
res: res
}, opts)));
self.logger.trace('handleOrProxyAll was proxied', {
keys: keys,
url: req && req.url
});
process.nextTick(self.proxyReq.bind(self, {
keys: keys,
req: req,
res: res,
dest: dest
}));
}
reses[dest] = res;
});
return reses;

function mapUniq(list, iteratee) {
return Object.keys(list.reduce(function(acc, val) {
acc[iteratee(val)] = null;
return acc;
}, {}));
}
responses[dest] = res;
return responses;
}, {});
};

RingPop.prototype.validateProps = function validateProps(opts, props) {
Expand All @@ -883,4 +886,11 @@ RingPop.prototype.validateProps = function validateProps(opts, props) {
}
};

function mapUniq(list, iteratee) {
return Object.keys(list.reduce(function(acc, val) {
acc[iteratee(val)] = null;
return acc;
}, {}));
}

module.exports = RingPop;

0 comments on commit 25dc21f

Please sign in to comment.