Move kwApply from actor.js to util.js
This commit is contained in:
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 Minimart = require("./minimart.js");
|
||||||
|
var util = require("./util.js");
|
||||||
var World = Minimart.World;
|
var World = Minimart.World;
|
||||||
var Route = Minimart.Route;
|
var Route = Minimart.Route;
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ function finalizeActor(behavior, chunks) {
|
||||||
{
|
{
|
||||||
var matchResult = Route.matchPattern(e.message, projections[i]);
|
var matchResult = Route.matchPattern(e.message, projections[i]);
|
||||||
if (matchResult) {
|
if (matchResult) {
|
||||||
kwApply(chunk.handler, this, matchResult);
|
util.kwApply(chunk.handler, this, matchResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -257,20 +257,6 @@ function finalizeActor(behavior, chunks) {
|
||||||
behavior.updateRoutes();
|
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.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
|
var Reflect = require("./reflect.js");
|
||||||
// window to exist, and we want to run in Web Worker context as well.
|
|
||||||
|
|
||||||
function extend(what, _with) {
|
module.exports.extend = function (what, _with) {
|
||||||
for (var prop in _with) {
|
for (var prop in _with) {
|
||||||
if (_with.hasOwnProperty(prop)) {
|
if (_with.hasOwnProperty(prop)) {
|
||||||
what[prop] = _with[prop];
|
what[prop] = _with[prop];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return what;
|
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