Move kwApply from actor.js to util.js
parent
18c4b184e5
commit
85c6c228a3
18
src/actor.js
18
src/actor.js
|
@ -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;
|
||||
|
|
20
src/util.js
20
src/util.js
|
@ -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);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue