cleanup worker basics
This commit is contained in:
parent
8bb97fbbea
commit
d2b141b68e
4 changed files with 12 additions and 27 deletions
|
|
@ -68,7 +68,7 @@ exports.launch = function(env) {
|
|||
docs.js.setUndoManager(new UndoManager());
|
||||
|
||||
var worker = new WorkerClient("../..", ["ace", "pilot"], "ace/worker/demo", "Demo");
|
||||
|
||||
worker.send("juhu");
|
||||
|
||||
docs.css = new Document(document.getElementById("csstext").innerHTML);
|
||||
docs.css.setMode(new CssMode());
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
exports.Demo = function(sender) {
|
||||
var Demo = exports.Demo = function(sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
};
|
||||
|
||||
(function() {
|
||||
|
||||
|
|
@ -11,6 +11,6 @@ exports.Demo = function(sender) {
|
|||
console.log("JUHU")
|
||||
}
|
||||
|
||||
}).call(exports.Demot.prototype);
|
||||
}).call(Demo.prototype);
|
||||
|
||||
});
|
||||
|
|
@ -11,31 +11,24 @@ define(function(require, exports, module) {
|
|||
var oop = require("pilot/oop");
|
||||
var EventEmitter = require("pilot/event_emitter").EventEmitter;
|
||||
|
||||
var WorkerClient = function(baseUrl, topLevelNamespaces, module, clazz) {
|
||||
var WorkerClient = function(baseUrl, topLevelNamespaces, module, classname) {
|
||||
|
||||
this.callbacks = [];
|
||||
var workerUrl = require.nameToUrl("ace/worker/host", null, "_");
|
||||
var worker = this.$worker = new Worker(workerUrl);
|
||||
|
||||
//context = s.contexts[contextName],
|
||||
//config = context.config;
|
||||
//debugger;
|
||||
|
||||
console.log(require.nameToUrl("ace", null, "_"))
|
||||
console.log(require.nameToUrl("pilot", null, "_"))
|
||||
|
||||
var tlns = {};
|
||||
for (var i=0; i<topLevelNamespaces.length; i++) {
|
||||
var ns = topLevelNamespaces[i];
|
||||
tlns[ns] = require.nameToUrl(ns, null, "_").replace(/.js$/, "").replace(require.config.baseUrl, "");
|
||||
}
|
||||
console.log(tlns)
|
||||
|
||||
this.$worker.postMessage({
|
||||
init : true,
|
||||
tlns: tlns,
|
||||
base: baseUrl,
|
||||
module: module,
|
||||
clazz: clazz
|
||||
classname: classname
|
||||
});
|
||||
|
||||
this.callbackId = 1;
|
||||
|
|
@ -47,7 +40,6 @@ var WorkerClient = function(baseUrl, topLevelNamespaces, module, clazz) {
|
|||
};
|
||||
this.$worker.onmessage = function(e) {
|
||||
var msg = e.data;
|
||||
//console.log("rec", msg)
|
||||
switch(msg.type) {
|
||||
case "log":
|
||||
console.log(msg.data);
|
||||
|
|
|
|||
|
|
@ -15,13 +15,9 @@ var require = function(name) {
|
|||
|
||||
var chunks = name.split("/");
|
||||
chunks[0] = require.tlns[chunks[0]] || chunks[0];
|
||||
name = chunks.join("/")
|
||||
path = require.baseUrl + "/" + chunks.join("/") + ".js"
|
||||
|
||||
console.log(name)
|
||||
console.log(require.baseUrl)
|
||||
|
||||
console.log(require.baseUrl + "/" + name + ".js");
|
||||
importScripts(require.baseUrl + "/" + name + ".js");
|
||||
importScripts(path);
|
||||
return require.modules[name].exports;
|
||||
};
|
||||
require.modules = {};
|
||||
|
|
@ -50,9 +46,7 @@ function initSender() {
|
|||
var EventEmitter = require("pilot/event_emitter").EventEmitter;
|
||||
var oop = require("pilot/oop");
|
||||
|
||||
console.log("init sender")
|
||||
|
||||
var Sender = function() {}
|
||||
var Sender = function() {};
|
||||
|
||||
(function() {
|
||||
|
||||
|
|
@ -82,11 +76,10 @@ var main;
|
|||
var sender;
|
||||
|
||||
onmessage = function(e) {
|
||||
console.log(e.data)
|
||||
var msg = e.data;
|
||||
if (msg.command)
|
||||
bgtokenizer[msg.command].apply(bgtokenizer, msg.args);
|
||||
else if (msg.init) {
|
||||
main[msg.command].apply(main, msg.args);
|
||||
else if (msg.init) {
|
||||
initBaseUrls(msg.base, msg.tlns);
|
||||
sender = initSender();
|
||||
var clazz = require(msg.module)[msg.classname];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue