Skip to content

Commit

Permalink
check first to see if we already have a container generated by Mojito…
Browse files Browse the repository at this point in the history
… and don't render a template unless it's model has changes
  • Loading branch information
add0n committed Jan 4, 2013
1 parent 532b858 commit 83966df
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/app/autoload/mojito-yaf-client.client.js
Expand Up @@ -453,10 +453,12 @@ YUI.add('mojito-yaf-client', function(Y, NAME) {
model.after('change', this.render, this);
}

container = Y.Node.create('<div id="' + params.id +
'" class="mojit"></div>');
if (attachPoint = this.getDOMAttachPoint()) {
attachPoint.append(container);
if (!(container = Y.one('#' + params.id))) {
container = Y.Node.create('<div id="' + params.id +
'" class="mojit"></div>');
if (attachPoint = this.getDOMAttachPoint()) {
attachPoint.append(container);
}
}

container.getDOMNode()._mojit = params.mojit;
Expand Down Expand Up @@ -518,15 +520,17 @@ YUI.add('mojito-yaf-client', function(Y, NAME) {

if (!(model = this.get('model'))) {
html = this.get('templateEngine').render(
template,
null);
template,
null);
} else {
html = this.get('templateEngine').render(
template,
this.get('model').toJSON());
if (Object.keys(model.changed).length > 0) {
html = this.get('templateEngine').render(
template,
this.get('model').toJSON());
}
}

container.append(html);
container.setHTML(html);
}
}, {
ATTRS: {
Expand Down

0 comments on commit 83966df

Please sign in to comment.