Merge pull request #1255 from ajaxorg/uiworker

Uiworker
This commit is contained in:
Lennart Kats 2013-02-22 03:40:39 -08:00
commit 7d7867c149
5 changed files with 24 additions and 20 deletions

View file

@ -236,7 +236,7 @@ function jsFileList(path, filter) {
filter = /_test/; filter = /_test/;
return fs.readdirSync(path).map(function(x) { return fs.readdirSync(path).map(function(x) {
if (x.slice(-3) == ".js" && !filter.test(x)) if (x.slice(-3) == ".js" && !filter.test(x) && !/\s/.test(x))
return x.slice(0, -3); return x.slice(0, -3);
}).filter(function(x){ return !!x }); }).filter(function(x){ return !!x });
} }
@ -269,9 +269,6 @@ function getWriteFilters(options, projectType) {
if (options.filters) if (options.filters)
filters = filters.concat(options.filters); filters = filters.concat(options.filters);
if (projectType == "worker")
return filters;
if (options.noconflict) if (options.noconflict)
filters.push(namespace(options.ns)); filters.push(namespace(options.ns));

View file

@ -53,6 +53,8 @@ require("./worker/worker_client");
require("./keyboard/hash_handler"); require("./keyboard/hash_handler");
require("./placeholder"); require("./placeholder");
require("./mode/folding/fold_mode"); require("./mode/folding/fold_mode");
require("./theme/textmate");
exports.config = require("./config"); exports.config = require("./config");
/** /**
@ -92,6 +94,9 @@ exports.edit = function(el) {
onResize: editor.resize.bind(editor) onResize: editor.resize.bind(editor)
}; };
event.addListener(window, "resize", env.onResize); event.addListener(window, "resize", env.onResize);
editor.on("destroy", function() {
event.removeListener(window, "resize", env.onResize);
});
el.env = editor.env = env; el.env = editor.env = env;
return editor; return editor;
}; };

View file

@ -2105,6 +2105,7 @@ var Editor = function(renderer, session) {
**/ **/
this.destroy = function() { this.destroy = function() {
this.renderer.destroy(); this.renderer.destroy();
this._emit("destroy", this);
}; };
}).call(Editor.prototype); }).call(Editor.prototype);

View file

@ -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,10 @@ var console = {
postMessage({type: "log", data: msgs}); postMessage({type: "log", data: msgs});
} }
}; };
var window = { window.window = window;
console: console window.ace = window;
};
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 +37,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 +64,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 +96,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 +132,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 +154,4 @@ onmessage = function(e) {
sender._emit(msg.event, msg.data); sender._emit(msg.event, msg.data);
} }
}; };
})(this);

View file

@ -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();