Move kwApply from actor.js to util.js

This commit is contained in:
Tony Garnock-Jones 2014-08-30 13:46:36 -07:00
parent 18c4b184e5
commit 85c6c228a3
2 changed files with 17 additions and 21 deletions

View File

@ -1,5 +1,5 @@
var Reflect = require("./reflect.js");
var Minimart = require("./minimart.js");
var util = require("./util.js");
var World = Minimart.World;
var Route = Minimart.Route;
@ -178,7 +178,7 @@ function finalizeActor(behavior, chunks) {
{
var matchResult = Route.matchPattern(e.message, projections[i]);
if (matchResult) {
kwApply(chunk.handler, this, matchResult);
util.kwApply(chunk.handler, this, matchResult);
}
}
break;
@ -257,20 +257,6 @@ function finalizeActor(behavior, chunks) {
behavior.updateRoutes();
}
function kwApply(f, thisArg, args) {
var formals = Reflect.formalParameters(f);
var actuals = []
for (var i = 0; i < formals.length; i++) {
var formal = formals[i];
if (!(formal in args)) {
throw new Error("Function parameter '"+formal+"' not present in args");
}
actuals.push(args[formal]);
}
return f.apply(thisArg, actuals);
}
///////////////////////////////////////////////////////////////////////////
module.exports.Actor = Actor;
module.exports.kwApply = kwApply;

View File

@ -1,13 +1,23 @@
// Minimal jQueryish utilities. Reimplemented because jQuery needs
// window to exist, and we want to run in Web Worker context as well.
var Reflect = require("./reflect.js");
function extend(what, _with) {
module.exports.extend = function (what, _with) {
for (var prop in _with) {
if (_with.hasOwnProperty(prop)) {
what[prop] = _with[prop];
}
}
return what;
}
};
module.exports.extend = extend;
module.exports.kwApply = function (f, thisArg, args) {
var formals = Reflect.formalParameters(f);
var actuals = []
for (var i = 0; i < formals.length; i++) {
var formal = formals[i];
if (!(formal in args)) {
throw new Error("Function parameter '"+formal+"' not present in args");
}
actuals.push(args[formal]);
}
return f.apply(thisArg, actuals);
};