DRY up a common view pattern
Define a Whisper.View base class that automatically parses and renders templates and attributes defined by the subclass. This saves us a good number of lines of code as well as some marginal memory overhead, since we are no longer saving per-instance copies of template strings.
This commit is contained in:
parent
7c9ad975bb
commit
1bb480f6ea
16 changed files with 109 additions and 60 deletions
|
@ -18,12 +18,9 @@
|
|||
|
||||
window.Whisper = window.Whisper || {};
|
||||
|
||||
Whisper.KeyVerificationView = Backbone.View.extend({
|
||||
Whisper.KeyVerificationView = Whisper.View.extend({
|
||||
className: 'key-verification',
|
||||
initialize: function(options) {
|
||||
this.template = $('#key-verification').html();
|
||||
Mustache.parse(this.template);
|
||||
},
|
||||
template: $('#key-verification').html(),
|
||||
events: {
|
||||
'click .back': 'goBack'
|
||||
},
|
||||
|
@ -37,12 +34,11 @@
|
|||
|
||||
});
|
||||
},
|
||||
render: function() {
|
||||
this.$el.html(Mustache.render(this.template, {
|
||||
attributes: function() {
|
||||
return {
|
||||
your_key: this.splitKey(this.model.your_key),
|
||||
their_key: this.splitKey(this.model.their_key)
|
||||
}));
|
||||
return this;
|
||||
};
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue