Skip to content

Instantly share code, notes, and snippets.

@erichocean
Created May 29, 2011 10:20
Show Gist options
  • Save erichocean/997630 to your computer and use it in GitHub Desktop.
Save erichocean/997630 to your computer and use it in GitHub Desktop.
improved SC.TemplateView
SC.mixin(SC.TemplateView.prototype,
/** @scope SC.TemplateView.prototype */{
templateNameDidChange: function() {
SC.Logger.debug("Template name was set to " + this.get('templateName'));
this.rerender();
}.observes('template'),
/**
Called when the template property associated with this view changes.
We destroy all registered children, then render the view again and insert
it into DOM.
*/
rerender: function() {
var idx, len, childViews, childView;
childViews = this.get('childViews');
len = childViews.get('length');
for (idx = len-1; idx >= 0; idx--) {
childView = childViews[idx];
childView.$().remove();
childView.removeFromParent();
childView.destroy();
}
var context = this.renderContext(this.get('tagName'));
var elem;
this.renderToContext(context);
elem = context.element();
this.$().replaceWith(elem);
this.set('layer', elem);
this._notifyDidCreateLayer();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment