diff --git a/src/actor.js b/src/actor.js index c2a772e..e55d239 100644 --- a/src/actor.js +++ b/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; diff --git a/src/util.js b/src/util.js index 3b20f3b..af781ee 100644 --- a/src/util.js +++ b/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); +};