Skip to content

Commit

Permalink
continued work on getting things working..
Browse files Browse the repository at this point in the history
  • Loading branch information
jayphelps committed Jul 11, 2012
1 parent ffbac5c commit fa8ff62
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/Class.js
Expand Up @@ -318,7 +318,7 @@
prototype.__construct = instanceMembers.__construct || function () {};

// Pass a reference to the super class implementations
prototype.super = superClass.prototype;
prototype.__super = superClass.prototype;

// Actual JS constructor that wraps the class's constructor so we can
// call super constructors
Expand All @@ -336,12 +336,12 @@
constructors.push(this.__construct);
}

var superDuper = this.super;
var superDuper = this.__super;

// Walk the super class chain pushing the constructors in the stack
while (superDuper && superDuper.__construct) {
constructors.push(superDuper.__construct);
superDuper = superDuper.super;
superDuper = superDuper.__super;
}

// Run all the constructors, starting from the bottom (reverse)
Expand Down
4 changes: 4 additions & 0 deletions src/Object.js
@@ -1,3 +1,5 @@
MLImport("Class.js");

/**
* Does nothing right now...
*
Expand All @@ -6,6 +8,8 @@
*/
ML.Object = ML.Class.create({}, {

isObject: true,

create: function (obj) {
return obj;
}
Expand Down
1 change: 0 additions & 1 deletion src/Pane.js
Expand Up @@ -20,7 +20,6 @@ ML.Pane = ML.Class.create({ extend: ML.View }, {
rootViewController: null,

__rootViewControllerDidChange: function (controller) {
console.log(controller)
if ( !ML.implementsInterface(controller) ) {
throw Error("rootViewController does not conform to the ML.ViewDelegateInterface");
}
Expand Down
7 changes: 7 additions & 0 deletions src/Responder.js
@@ -1,3 +1,6 @@
MLImport("Class.js");
MLImport("Object.js");

/**
* No documentation available yet.
*
Expand All @@ -7,6 +10,10 @@
*/
ML.Responder = ML.Class.create({

extend: ML.Object

}, /** @lends ML.Responder# */ {

nextResponder: null,

makeFirstResponder: function () {
Expand Down
73 changes: 54 additions & 19 deletions src/View.js
Expand Up @@ -177,13 +177,19 @@ MLImport("Responder.js");
// update it with our current classes.
// Otherwise, we'll just sit on the changes
if (!classList.isUpdating) {
var layer = view.layer;
var className = layer.className;
var isSVG = !ML.isUndefined(className.baseVal);

// The first time this runs we need to merge any
// existing classNames off the real layer element
// with our ClassList otherwise we'll overwrite them
if (!classList._hasSetClassNameBefore) {

if (isSVG) {
className = className.baseVal;
}
// CSS Classes that already existed on the layer
var originalClasses = view.layer.className.split(" ");
var originalClasses = className.split(" ");

// Prevent infite recursion
classList.isUpdating = YES;
Expand All @@ -200,8 +206,14 @@ MLImport("Responder.js");
classList._hasSetClassNameBefore = YES;
}

var newClassName = classList.join(" ");

// Finally, change the real className of the HTML element
view.layer.className = classList.join(" ");
if (isSVG) {
layer.className.baseVal = newClassName;
} else {
layer.className = newClassName;
}
}
});
}
Expand Down Expand Up @@ -296,7 +308,42 @@ MLImport("Responder.js");
* @return {void}
*/
__getLayer: function () {
return this.layer || this.render();
if (!this.layer) {
var context = this.getRenderContext();

// Allow pre-hooks before render
this.willRender();

// Actually render the layer with the given context
this.render(context);

// Get the layer out of our context
this.layer = context.getElement()

this.classList._updateClassName();

this.setIsRendered(YES);

// Let them know the view is now rendered and the layer exists
this.didRender();
}

return this.layer;
},

// =====================================================================
// renderContext + getter
// =====================================================================

/**
* @property
* @default null
* @type ML.RenderContext
*/
renderContext: null,

__getRenderContext: function () {
return this.renderContext || (this.renderContext = new ML.RenderContext(this.tagName));
},

// =====================================================================
Expand Down Expand Up @@ -461,22 +508,10 @@ MLImport("Responder.js");
*
* @return {void}
*/
render: function () {
// Allow pre-hooks before render
this.willRender();

if (!this.layer) {
// Create our layer as an HTML element
this.layer = document.createElement(this.tagName);
}

this.setIsRendered(YES);
this.classList._updateClassName();
render: function (context) {
context.drawElement(this.tagName);

// Let them know the view is now rendered and the layer exists
this.didRender();

return this.layer;
return context.getElement();
},

/**
Expand Down
7 changes: 7 additions & 0 deletions test/todos/ListView.js
Expand Up @@ -32,6 +32,13 @@ Todos.ListView = ML.Class.create({ extend: ML.View }, {
listItem = listItems.splice(index, 1)[0];
console.log(listItem.view, this)
this.removeChild(listItem.view);
},

_render: function (context) {
context.begin();
var layer = context.createElement(this.tagName);
context.push("Hello world");
context.end();
}

});
96 changes: 92 additions & 4 deletions tools/MLLoadApplication.js
Expand Up @@ -3,8 +3,33 @@
* it or have it watch your files, for example, if you don't have node.js.
*/

// 2394

function between(x, min, max) {
return x >= min && x <= max;
}

var totalLineCount = 0;
var files = [];

(function (window, document) {

function injectDebugScript(source) {
var header = "data:text/javascript;charset=utf-8,";
var src = header + source;
var scriptElement = document.createElement("script");

scriptElement.type = "text/javascript";//"text/x-javascript-debug";
scriptElement.text = source;
//scriptElement.src = src;

var headElement = document.getElementsByTagName("head")[0];

headElement && headElement.appendChild(scriptElement);

return src;
}

function MLImport(filePath) {
var pathname = window.location.pathname;
var currentPath = MLImport.currentPath || location.origin + pathname.substring(0, pathname.lastIndexOf('/')) + "/";
Expand All @@ -26,8 +51,21 @@
throw new Error("Importing file failed: " + filePath + " with status code: " + request.status);
}

//totalLineCount;

var sourceCode = request.responseText;

var lineCount = sourceCode.match(/(\r\n|\n|\r)/gm).length + 1;
var startLineNumber = totalLineCount;
totalLineCount += lineCount;

files.push({
path: filePath,
lines: lineCount,
start: startLineNumber,
end: totalLineCount
});

var oldPath = MLImport.currentPath;
MLImport.currentPath = fullPath.split("/").slice(0, -1).join("/") + "/";

Expand All @@ -41,36 +79,86 @@
return match;
});



MLImport.currentPath = oldPath;

MLImport[fullPath] = true;

return preprocessedCode;
}

function shimError(msg, lineNumber) {
console.log(totalLineCount, lineNumber);
var file;

for (var i = 0, l = files.length; i < l; i++) {
file = files[i];

if ( between(lineNumber, file.start, file.end) ) {
console.log(file.path, lineNumber-file.start, file.start, file.lines);
break;
}
}

var err = TypeError(msg);
console.log('adsf', err, err.stack);

err.sourceURL = "file:///Users/jayphelps/Projects/MLKit/src/" + file.path;
err.fileName = "http://localhost/test/todos/" + file.path;
err.lineNumber = 346;
err.line = 346;
err.column = 10;

throw err;

//throw Error("ADSF");
}

function MLLoadApplication(filePath) {
var pathname = window.location.pathname;
var currentPath = MLImport.currentPath || location.origin + pathname.substring(0, pathname.lastIndexOf('/')) + "/";
var fullPath = currentPath + filePath;

fucker = fullPath;

var preprocessedCode = MLImport(filePath);

// We inject a script tag with a bogus type so we can reference the
// correct line if an exception is thrown during eval. A neat trick
// I figured out playing around. Likely only works in WebKit though.
//var debugSrc = injectDebugScript(preprocessedCode);

//console.log(preprocessedCode + "\n//@ sourceURL=" + "fuck.js")

//console.log(files.length, files);

window.onerror = function (msg, path, lineNumber) {
window.onerror = null;

setTimeout(function () {
shimError(msg, lineNumber);
}, 0);

return true;
};

try {
// So we eval in the global context
eval(preprocessedCode);
//document.write(preprocessedCode);
eval(preprocessedCode + "//@ sourceURL=" + fullPath);
//eval("(function () { function foo() { bar } bar()})();");
} catch (e) {
alert('d')
// In some browsers (WebKit at least) syntax errors show this file
// and the actual eval line as the error, and setting the sourceURL
// doesn't work, so we'll generate our own generic error instead
if (e.name === "SyntaxError") {
var err = Error(e.message);
err.name = "MLImport SyntaxError";
err.sourceURL = fullPath;
err.sourceURL = "fuck.js";
throw err;
}

console.log('DID IT', e)
// This is so the correct file is shown in WebKit debuggers. Neat eh?
e.sourceURL = fullPath;
throw e;
Expand Down

0 comments on commit fa8ff62

Please sign in to comment.