fix loading of worker files from UIWorkerClient
This commit is contained in:
parent
f8f277d79b
commit
36f9b537cc
2 changed files with 16 additions and 16 deletions
|
|
@ -1,9 +1,10 @@
|
||||||
"no use strict";
|
"no use strict";
|
||||||
|
;(function(window) {
|
||||||
|
if (typeof window.window != "undefined" && window.document) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof window != "undefined" && window.document)
|
window.console = {
|
||||||
throw "atempt to load ace worker into main window instead of webWorker";
|
|
||||||
|
|
||||||
var console = {
|
|
||||||
log: function() {
|
log: function() {
|
||||||
var msgs = Array.prototype.slice.call(arguments, 0);
|
var msgs = Array.prototype.slice.call(arguments, 0);
|
||||||
postMessage({type: "log", data: msgs});
|
postMessage({type: "log", data: msgs});
|
||||||
|
|
@ -13,11 +14,9 @@ var console = {
|
||||||
postMessage({type: "log", data: msgs});
|
postMessage({type: "log", data: msgs});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var window = {
|
window.window = window;
|
||||||
console: console
|
|
||||||
};
|
|
||||||
|
|
||||||
var normalizeModule = function(parentId, moduleName) {
|
window.normalizeModule = function(parentId, moduleName) {
|
||||||
// normalize plugin requires
|
// normalize plugin requires
|
||||||
if (moduleName.indexOf("!") !== -1) {
|
if (moduleName.indexOf("!") !== -1) {
|
||||||
var chunks = moduleName.split("!");
|
var chunks = moduleName.split("!");
|
||||||
|
|
@ -37,7 +36,7 @@ var normalizeModule = function(parentId, moduleName) {
|
||||||
return moduleName;
|
return moduleName;
|
||||||
};
|
};
|
||||||
|
|
||||||
var require = function(parentId, id) {
|
window.require = function(parentId, id) {
|
||||||
if (!id.charAt)
|
if (!id.charAt)
|
||||||
throw new Error("worker.js require() accepts only (parentId, id) as arguments");
|
throw new Error("worker.js require() accepts only (parentId, id) as arguments");
|
||||||
|
|
||||||
|
|
@ -64,7 +63,7 @@ var require = function(parentId, id) {
|
||||||
require.modules = {};
|
require.modules = {};
|
||||||
require.tlns = {};
|
require.tlns = {};
|
||||||
|
|
||||||
var define = function(id, deps, factory) {
|
window.define = function(id, deps, factory) {
|
||||||
if (arguments.length == 2) {
|
if (arguments.length == 2) {
|
||||||
factory = deps;
|
factory = deps;
|
||||||
if (typeof id != "string") {
|
if (typeof id != "string") {
|
||||||
|
|
@ -96,11 +95,11 @@ var define = function(id, deps, factory) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function initBaseUrls(topLevelNamespaces) {
|
window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
|
||||||
require.tlns = topLevelNamespaces;
|
require.tlns = topLevelNamespaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
function initSender() {
|
window.initSender = function initSender() {
|
||||||
|
|
||||||
var EventEmitter = require(null, "ace/lib/event_emitter").EventEmitter;
|
var EventEmitter = require(null, "ace/lib/event_emitter").EventEmitter;
|
||||||
var oop = require(null, "ace/lib/oop");
|
var oop = require(null, "ace/lib/oop");
|
||||||
|
|
@ -132,10 +131,10 @@ function initSender() {
|
||||||
return new Sender();
|
return new Sender();
|
||||||
}
|
}
|
||||||
|
|
||||||
var main;
|
window.main = null;
|
||||||
var sender;
|
window.sender = null;
|
||||||
|
|
||||||
onmessage = function(e) {
|
window.onmessage = function(e) {
|
||||||
var msg = e.data;
|
var msg = e.data;
|
||||||
if (msg.command) {
|
if (msg.command) {
|
||||||
if (main[msg.command])
|
if (main[msg.command])
|
||||||
|
|
@ -154,3 +153,4 @@ onmessage = function(e) {
|
||||||
sender._emit(msg.event, msg.data);
|
sender._emit(msg.event, msg.data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
})(this);
|
||||||
|
|
@ -203,7 +203,7 @@ var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
|
||||||
this.postMessage({type: "event", name: name, data: data});
|
this.postMessage({type: "event", name: name, data: data});
|
||||||
};
|
};
|
||||||
|
|
||||||
require([mod], function(Main) {
|
config.loadModule(["worker", mod], function(Main) {
|
||||||
main = new Main[classname](sender);
|
main = new Main[classname](sender);
|
||||||
while (_self.messageBuffer.length)
|
while (_self.messageBuffer.length)
|
||||||
processNext();
|
processNext();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue