This commit is contained in:
Julian Viereck 2011-09-05 17:42:58 -07:00
parent 0134143c67
commit 71ff8ee586
7 changed files with 154 additions and 122 deletions

23
worker/message_handler.js Normal file
View file

@ -0,0 +1,23 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
function MessageHandler(actionHandler, postMessage, scope) {
this.onMessage = function(event) {
var data = event.data;
if (data.action in actionHandler) {
actionHandler[data.action].call(scope, data.data);
} else {
throw 'Unkown action from worker: ' + data.action;
}
};
this.send = function(actionName, data) {
postMessage({
action: actionName,
data: data
});
}
}