Skip to content

Commit

Permalink
new iterative behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Aug 12, 2011
1 parent f01e022 commit 770c047
Show file tree
Hide file tree
Showing 5 changed files with 365 additions and 163 deletions.
46 changes: 22 additions & 24 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,29 @@ app.configure = function(env, func) {
* Template Rendering
*/

app.render = (function() {
var compile = (function() {
var cache = {};
return function(id) {
if (!cache[id]) {
var engine = app.settings.engine
, el = DOM.select(id)[0];
if (engine.compile) {
app.settings.engine =
engine = engine.compile;
}
cache[id] = engine(DOM.getContent(el));
}
return cache[id];
};
})();
return function(el, id, locals) {
if (typeof el === 'string') {
return compile(el)(id);
app._compile = function(id) {
var cache = app._cache
|| (app._cache = {});
if (!cache[id]) {
var engine = app.settings.engine
, el = DOM.select(id)[0];
if (engine.compile) {
app.settings.engine =
engine = engine.compile;
}
DOM.setContent(el, compile(id)(locals));
};
})();
cache[id] = engine(DOM.getContent(el));
}
return cache[id];
};

app.render = function(el, id, locals) {
if (typeof el === 'string') {
return app._compile(el)(id);
}
DOM.setContent(el, app._compile(id)(locals));
};

DOM.implement('render', app.render);
//DOM.implement('render', app.render);

/**
* Router
Expand All @@ -78,7 +76,7 @@ path.update = function() {
router.dispatch(cur);
};

if (window.history.pushState) {
if (history.pushState) {
path.changed = false;

path.get = function getPath() {
Expand Down
Loading

0 comments on commit 770c047

Please sign in to comment.