Skip to content

Commit

Permalink
Merge pull request #26 from m0nzderr/2.0.0-wip
Browse files Browse the repository at this point in the history
2.0.0 wip
  • Loading branch information
m0nzderr committed Jul 10, 2016
2 parents 32d85ae + 6a4e231 commit 96e9fc8
Show file tree
Hide file tree
Showing 18 changed files with 585 additions and 297 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Here is why:

Roadmap/Progress:
```
(<wip>) - 2.0.0 first release estimated on ~~Jan 1 2016~~ UPD: Mar 1 2016.
(<wip>) - 2.0.0-beta release estimated on Sep 1 2016.
|
( ) - Minimal complete documentation (getting started, usage of runtime library,
: gulp-browserify recipes, XVDL specification)
Expand Down
45 changes: 29 additions & 16 deletions browser/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ var html = require("../core/html"),
commons = require("../core/commons"),
promise = commons.promise,
inside = commons.inside,
runtime = require("../runtime"),
isClearest = commons.is._,
isValue = commons.is.value;

//App = require("../interface/app");

var KEY_ATTR = commons.constant.ATTR;
var ATTRIBUTE_PREFIX = commons.constant.ATTRIBUTE_PREFIX;

/**
* Simplest builder implementation that wraps around browser implementation.
Expand All @@ -31,6 +32,14 @@ function BrowserApp(document, wrapper) {
this.wrapper = wrapper;
this.root = null;
this.queue = null;

// add window references (for debugging pruposes only)
if (typeof window !== 'undefined') {
window[commons.constant.CLEAREST] = {
app: this,
runtime: runtime
}
}
}


Expand Down Expand Up @@ -58,11 +67,11 @@ BrowserApp.prototype.render = function (view, presentation) {

// remove old attributes
for (var attr in localAttributes) {
if (attr ==='id'){
if (attr === 'id') {
//FIXME: create another logic to prevent ids from being removed
continue;
}
var key = KEY_ATTR + attr;
var key = ATTRIBUTE_PREFIX + attr;
if (plain || presentation[key] === undefined || presentation[key] === null) {
view.removeAttribute(attr);
}
Expand All @@ -71,10 +80,8 @@ BrowserApp.prototype.render = function (view, presentation) {
if (!plain) {
// add new attributes
for (var key in presentation) {
if (key.charAt(0) === KEY_ATTR) {
var attr = key.slice(1);
view.setAttribute(attr, presentation[key]);
localAttributes[attr] = true;
if (key.length > 1 && key.charAt(0) === ATTRIBUTE_PREFIX) {
var attr = key.slice(1); view.setAttribute(attr, presentation[key]); localAttributes[attr] = true;
}
}
}
Expand All @@ -84,25 +91,32 @@ BrowserApp.prototype.render = function (view, presentation) {
};

BrowserApp.prototype.process = function () {
return promise.resolve(this.root.process());
return promise.resolve(this.root)
.then(function (root) {
return root.process()
})
.then(null, function (error) {
console.error("Unhandeled application error:", error.stack ? error.stack : error);
throw error;
});
};

//--- event handling ---//
BrowserApp.prototype.on = function(element, event, handler, options) {
element.addEventListener(event, handler, options );
BrowserApp.prototype.on = function (element, event, handler, options) {
element.addEventListener(event, handler, options);
};

BrowserApp.prototype.off = function(element, event, handler, options){
element.removeEventListener(event, handler, options );
BrowserApp.prototype.off = function (element, event, handler, options) {
element.removeEventListener(event, handler, options);
};

BrowserApp.prototype.event = function(event,initializer){
BrowserApp.prototype.event = function (event, initializer) {
//TODO 2.1.0: add compatibility with older browsers
return new CustomEvent(event, initializer);
}

BrowserApp.prototype.trigger = function(element, event){
if (typeof document !== 'undefined'){
BrowserApp.prototype.trigger = function (element, event) {
if (typeof document !== 'undefined') {
if (typeof event === 'string') {
//FIXME: 2.1.0 remove deprecated code
var e = document.createEvent("HTMLEvents");
Expand All @@ -116,7 +130,6 @@ BrowserApp.prototype.trigger = function(element, event){
};



module.exports = BrowserApp;


0 comments on commit 96e9fc8

Please sign in to comment.