aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Crosby2012-05-29 16:36:05 -0700
committerPhil Crosby2012-05-29 16:36:05 -0700
commit4f7d314135793bf315304d2663df2144441dc33a (patch)
treed8a18d854f20e475bebadfa854186741524c2b72
parentaf17e5c0fc703ab31f855859f429158cde666131 (diff)
downloadvimium-4f7d314135793bf315304d2663df2144441dc33a.tar.bz2
Have Function.curry take varargs instead of an array.
-rw-r--r--content_scripts/vomnibar.js12
-rw-r--r--lib/utils.js3
2 files changed, 10 insertions, 5 deletions
diff --git a/content_scripts/vomnibar.js b/content_scripts/vomnibar.js
index 97f8b1c1..3fedc8c4 100644
--- a/content_scripts/vomnibar.js
+++ b/content_scripts/vomnibar.js
@@ -195,11 +195,15 @@ var vomnibar = (function() {
this.filterPort.onMessage.addListener(function(msg) {
if (msg.id != id) return;
// The result objects coming from the background page will be of the form:
- // { html: "", action: { functionName: "", args: [] } }
- // functionName will be either "navigateToUrl" or "switchToTab". args will be a URL or a tab ID.
+ // { html: "", action: "", url: "" }
+ // action will be either "navigateToUrl" or "switchToTab".
var results = msg.results.map(function(result) {
- var functionToCall = completionActions[result.action.functionName];
- result.performAction = functionToCall.curry(result.action.args);
+ var functionToCall = completionActions[result.action];
+ if (result.action == "navigateToUrl")
+ functionToCall = functionToCall.curry(result.url);
+ else if (result.action == "switchToTab")
+ functionToCall = functionToCall.curry(result.tabId);
+ result.performAction = functionToCall;
return result;
});
callback(results);
diff --git a/lib/utils.js b/lib/utils.js
index cc68ba8c..ac6f32c3 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -169,7 +169,8 @@ Function.prototype.proxy = function(self) {
* This creates a new function out of an existing function, where the new function takes fewer arguments.
* This allows us to pass around functions instead of functions + a partial list of arguments.
*/
-Function.prototype.curry = function(fixedArguments) {
+Function.prototype.curry = function() {
+ var fixedArguments = Array.copy(arguments);
var fn = this;
return function() { return fn.apply(this, fixedArguments.concat(Array.copy(arguments))); };
};