mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-26 13:20:48 +00:00
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:
34
test/views/whisper_view_test.js
Normal file
34
test/views/whisper_view_test.js
Normal file
@@ -0,0 +1,34 @@
|
||||
describe('Whisper.View', function() {
|
||||
it('renders a template with attributes', function() {
|
||||
var viewClass = Whisper.View.extend({
|
||||
template: '<div>{{ variable }}</div>',
|
||||
attributes: {
|
||||
variable: 'value'
|
||||
}
|
||||
});
|
||||
|
||||
var view = new viewClass();
|
||||
view.render();
|
||||
assert.strictEqual(view.$el.html(), '<div>value</div>');
|
||||
});
|
||||
it('renders a template with no attributes', function() {
|
||||
var viewClass = Whisper.View.extend({
|
||||
template: '<div>static text</div>'
|
||||
});
|
||||
|
||||
var view = new viewClass();
|
||||
view.render();
|
||||
assert.strictEqual(view.$el.html(), '<div>static text</div>');
|
||||
});
|
||||
it('renders a template function with attributes function', function() {
|
||||
var viewClass = Whisper.View.extend({
|
||||
template: function() { return '<div>{{ variable }}</div>'; },
|
||||
attributes: function() {
|
||||
return { variable: 'value' };
|
||||
}
|
||||
});
|
||||
var view = new viewClass();
|
||||
view.render();
|
||||
assert.strictEqual(view.$el.html(), '<div>value</div>');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user