Skip to content

Commit

Permalink
Housekeeping
Browse files Browse the repository at this point in the history
Added tests/code to handle views with no model
Added devDependencies to get build.js working
Tweaks to get jshint passing
  • Loading branch information
Michael Garvin committed Jan 6, 2014
1 parent 0b54250 commit b920a75
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
human-model.min.js
human-view.min.js
test.js
idealUse.js
test/*
1 change: 0 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
"node": true,
"indent": 2,
"strict": true,
"es5": true,
"eqnull": true
}
10 changes: 5 additions & 5 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ var bundle = require('browserify')();
var fs = require('fs');
var uglify = require('uglify-js');


bundle.add('./human-view');
bundle.bundle({standalone: 'HumanView'}, function (err, source) {
if (err) console.error(err);
fs.writeFile('human-view.min.js', uglify.minify(source, {fromString: true}).code, function (err) {
if (err) throw err;
});
'use strict';
if (err) console.error(err);
fs.writeFile('human-view.min.js', uglify.minify(source, {fromString: true}).code, function (err) {
if (err) throw err;
});
});
5 changes: 3 additions & 2 deletions human-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// If view has an 'el' it's a single view not
// an array of views registered by renderCollection
// so we store a reference to the parent view.
if (view.el) view.parent = self;
if (view.el) view.parent = this;
return view;
},

Expand Down Expand Up @@ -68,6 +68,7 @@
var model = specificModel || this.model;
var bindingObject = bindings || this;

if (!model) throw new Error('Cannot register bindings without a model');
_.each(types, function (methodName, bindingType) {
_.each(bindingObject[bindingType], function (selector, key) {
var func;
Expand Down Expand Up @@ -124,7 +125,7 @@
// Commbo for renderWithTemplate and registering bindings
renderAndBind: function (context, templateArg) {
this.renderWithTemplate(context, templateArg);
this.registerBindings();
if (this.model) this.registerBindings();
return this;
},

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
"browser": "./human-view.js",
"devDependencies": {
"precommit-hook": "",
"backbone": "1.0.0"
"backbone": "1.0.0",
"browserify": "3.19.0",
"uglify-js": "2.4.8",
"underscore": "~1.5.2"
},
"scripts": {
"validate": "jshint ."
}
}
20 changes: 20 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,23 @@ test('classBindings', function () {
ok(!view.$el.hasClass('active'));
ok(view.$el.hasClass('low'));
});

module('error case: no model');

//test('renderAndBind with no model', function () {
//var View = HumanView.extend({
//template: '<li><span></span><img/></li>',
//textBindings: { name: 'span' }
//});
//var view = new View();
//ok(view.renderAndBind()); //Should not throw error
//});

test('registerBindings with no model', function () {
var View = HumanView.extend({
template: '<li><span></span><img/></li>',
textBindings: { name: 'span' }
});
var view = new View();
throws(view.registerBindings, Error, 'Throws error on no model');
});

0 comments on commit b920a75

Please sign in to comment.