Skip to content

Instantly share code, notes, and snippets.

@ericf
Created January 4, 2012 21:19
Show Gist options
  • Select an option

  • Save ericf/1562192 to your computer and use it in GitHub Desktop.

Select an option

Save ericf/1562192 to your computer and use it in GitHub Desktop.
UserPageView = Y.Base.create('userPageView', Y.View, [], {
initializer: function () {
var user = this.get('model'),
repos = this.get('modelList');
// This view serves as a "page"-level view containing two sub-views to
// which it delegates rendering and stitches together the resulting UI.
// Sub-views are created to render the `User` and `RepoList`.
this.userView = new UserView({model: user});
this.repoListView = new RepoListView({modelList: repos});
// This will cause the sub-views' custom events to bubble up to here.
this.userView.addTarget(this);
this.repoListView.addTarget(this);
},
// This destructor is specified so this view's sub-views can be properly
// destroyed and cleaned up.
destructor: function () {
this.userView.destroy();
this.repoListView.destroy();
delete this.userView;
delete this.repoListView;
},
create: function (container) {
// Adds CSS class to the container node.
return Y.one(container).addClass('user-page');
},
render: function () {
// A document fragment is created to hold the resulting HTML created
// from rendering to two sub-views.
var content = Y.one(Y.config.doc.createDocumentFragment());
// This renders each of the two sub-views into the document fragment,
// then sets the fragment as the contents of this view's container.
content.append(this.userView.render().get('container'));
content.append(this.repoListView.render().get('container'));
this.get('container').setContent(content);
return this;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment