Skip to content

Commit

Permalink
MasterView: adds pre and post render signals.
Browse files Browse the repository at this point in the history
(cherry picked from commit a228f49c792c576a01f68d3f7ca914da80660ed1)
  • Loading branch information
pardo-bsso committed Feb 5, 2014
1 parent 7ca27bd commit 56d94d6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions public/js/views/masterview.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ window.MasterView = Backbone.View.extend({
initialize: function() {
var self = this;

_.extend(this, Backbone.Events);

// This allows us to hook before and after rendering happens.
// XXX: keep the _.bindAll, otherwise 'this' will point to the
// global object inside render()
_.bindAll(this, 'render');
this.render = _.wrap(this.render, function(render) {
this.trigger('prerender');
render();
this.trigger('postrender');
});

// This allows the view to be extended without losing bindings
this.events = _.extend({}, this.events, this.genericEvents);
this.delegateEvents();
Expand Down

2 comments on commit 56d94d6

@xaiki
Copy link
Member

@xaiki xaiki commented on 56d94d6 Feb 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks sane.
shouldn't we push this to something more generic, i.e. KO/KB ?

@pardo-bsso
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Knockout already has an afterRender hook. However when I did that I was interested in knowing about all the boilerplate associated with a view , not just the knockout part.

Please sign in to comment.