Commit 6da5aa7a authored by Kent C. Dodds's avatar Kent C. Dodds

Fix jscs issues found in #1403...

I am so sorry that this results in a bunch of whitespace change
and git history nuking 💣
parent 8e849917
......@@ -9,40 +9,40 @@
* @param {object} view The view instance
*/
function Controller(model, view) {
var that = this;
that.model = model;
that.view = view;
var self = this;
self.model = model;
self.view = view;
that.view.bind('newTodo', function (title) {
that.addItem(title);
self.view.bind('newTodo', function (title) {
self.addItem(title);
});
that.view.bind('itemEdit', function (item) {
that.editItem(item.id);
self.view.bind('itemEdit', function (item) {
self.editItem(item.id);
});
that.view.bind('itemEditDone', function (item) {
that.editItemSave(item.id, item.title);
self.view.bind('itemEditDone', function (item) {
self.editItemSave(item.id, item.title);
});
that.view.bind('itemEditCancel', function (item) {
that.editItemCancel(item.id);
self.view.bind('itemEditCancel', function (item) {
self.editItemCancel(item.id);
});
that.view.bind('itemRemove', function (item) {
that.removeItem(item.id);
self.view.bind('itemRemove', function (item) {
self.removeItem(item.id);
});
that.view.bind('itemToggle', function (item) {
that.toggleComplete(item.id, item.completed);
self.view.bind('itemToggle', function (item) {
self.toggleComplete(item.id, item.completed);
});
that.view.bind('removeCompleted', function () {
that.removeCompletedItems();
self.view.bind('removeCompleted', function () {
self.removeCompletedItems();
});
that.view.bind('toggleAll', function (status) {
that.toggleAll(status.completed);
self.view.bind('toggleAll', function (status) {
self.toggleAll(status.completed);
});
}
......@@ -62,9 +62,9 @@
* todo-list
*/
Controller.prototype.showAll = function () {
var that = this;
that.model.read(function (data) {
that.view.render('showEntries', data);
var self = this;
self.model.read(function (data) {
self.view.render('showEntries', data);
});
};
......@@ -72,9 +72,9 @@
* Renders all active tasks
*/
Controller.prototype.showActive = function () {
var that = this;
that.model.read({ completed: false }, function (data) {
that.view.render('showEntries', data);
var self = this;
self.model.read({ completed: false }, function (data) {
self.view.render('showEntries', data);
});
};
......@@ -82,9 +82,9 @@
* Renders all completed tasks
*/
Controller.prototype.showCompleted = function () {
var that = this;
that.model.read({ completed: true }, function (data) {
that.view.render('showEntries', data);
var self = this;
self.model.read({ completed: true }, function (data) {
self.view.render('showEntries', data);
});
};
......@@ -93,15 +93,15 @@
* object and it'll handle the DOM insertion and saving of the new item.
*/
Controller.prototype.addItem = function (title) {
var that = this;
var self = this;
if (title.trim() === '') {
return;
}
that.model.create(title, function () {
that.view.render('clearNewTodo');
that._filter(true);
self.model.create(title, function () {
self.view.render('clearNewTodo');
self._filter(true);
});
};
......@@ -109,9 +109,9 @@
* Triggers the item editing mode.
*/
Controller.prototype.editItem = function (id) {
var that = this;
that.model.read(id, function (data) {
that.view.render('editItem', {id: id, title: data[0].title});
var self = this;
self.model.read(id, function (data) {
self.view.render('editItem', {id: id, title: data[0].title});
});
};
......@@ -119,13 +119,13 @@
* Finishes the item editing mode successfully.
*/
Controller.prototype.editItemSave = function (id, title) {
var that = this;
var self = this;
if (title.trim()) {
that.model.update(id, {title: title}, function () {
that.view.render('editItemDone', {id: id, title: title});
self.model.update(id, {title: title}, function () {
self.view.render('editItemDone', {id: id, title: title});
});
} else {
that.removeItem(id);
self.removeItem(id);
}
};
......@@ -133,9 +133,9 @@
* Cancels the item editing mode.
*/
Controller.prototype.editItemCancel = function (id) {
var that = this;
that.model.read(id, function (data) {
that.view.render('editItemDone', {id: id, title: data[0].title});
var self = this;
self.model.read(id, function (data) {
self.view.render('editItemDone', {id: id, title: data[0].title});
});
};
......@@ -147,26 +147,26 @@
* storage
*/
Controller.prototype.removeItem = function (id) {
var that = this;
that.model.remove(id, function () {
that.view.render('removeItem', id);
var self = this;
self.model.remove(id, function () {
self.view.render('removeItem', id);
});
that._filter();
self._filter();
};
/**
* Will remove all completed items from the DOM and storage.
*/
Controller.prototype.removeCompletedItems = function () {
var that = this;
that.model.read({ completed: true }, function (data) {
var self = this;
self.model.read({ completed: true }, function (data) {
data.forEach(function (item) {
that.removeItem(item.id);
self.removeItem(item.id);
});
});
that._filter();
self._filter();
};
/**
......@@ -179,16 +179,16 @@
* @param {boolean|undefined} silent Prevent re-filtering the todo items
*/
Controller.prototype.toggleComplete = function (id, completed, silent) {
var that = this;
that.model.update(id, { completed: completed }, function () {
that.view.render('elementComplete', {
var self = this;
self.model.update(id, { completed: completed }, function () {
self.view.render('elementComplete', {
id: id,
completed: completed
});
});
if (!silent) {
that._filter();
self._filter();
}
};
......@@ -197,14 +197,14 @@
* Just pass in the event object.
*/
Controller.prototype.toggleAll = function (completed) {
var that = this;
that.model.read({ completed: !completed }, function (data) {
var self = this;
self.model.read({ completed: !completed }, function (data) {
data.forEach(function (item) {
that.toggleComplete(item.id, completed, true);
self.toggleComplete(item.id, completed, true);
});
});
that._filter();
self._filter();
};
/**
......@@ -212,16 +212,16 @@
* number of todos.
*/
Controller.prototype._updateCount = function () {
var that = this;
that.model.getCount(function (todos) {
that.view.render('updateElementCount', todos.active);
that.view.render('clearCompletedButton', {
var self = this;
self.model.getCount(function (todos) {
self.view.render('updateElementCount', todos.active);
self.view.render('clearCompletedButton', {
completed: todos.completed,
visible: todos.completed > 0
});
that.view.render('toggleAll', {checked: todos.completed === todos.total});
that.view.render('contentBlockVisibility', {visible: todos.total > 0});
self.view.render('toggleAll', {checked: todos.completed === todos.total});
self.view.render('contentBlockVisibility', {visible: todos.total > 0});
});
};
......
......@@ -15,8 +15,8 @@
return htmlEscapes[chr];
};
var reUnescapedHtml = /[&<>"'`]/g,
reHasUnescapedHtml = new RegExp(reUnescapedHtml.source);
var reUnescapedHtml = /[&<>"'`]/g;
var reHasUnescapedHtml = new RegExp(reUnescapedHtml.source);
var escape = function (string) {
return (string && reHasUnescapedHtml.test(string))
......
......@@ -93,40 +93,40 @@
};
View.prototype.render = function (viewCmd, parameter) {
var that = this;
var self = this;
var viewCommands = {
showEntries: function () {
that.$todoList.innerHTML = that.template.show(parameter);
self.$todoList.innerHTML = self.template.show(parameter);
},
removeItem: function () {
that._removeItem(parameter);
self._removeItem(parameter);
},
updateElementCount: function () {
that.$todoItemCounter.innerHTML = that.template.itemCounter(parameter);
self.$todoItemCounter.innerHTML = self.template.itemCounter(parameter);
},
clearCompletedButton: function () {
that._clearCompletedButton(parameter.completed, parameter.visible);
self._clearCompletedButton(parameter.completed, parameter.visible);
},
contentBlockVisibility: function () {
that.$main.style.display = that.$footer.style.display = parameter.visible ? 'block' : 'none';
self.$main.style.display = self.$footer.style.display = parameter.visible ? 'block' : 'none';
},
toggleAll: function () {
that.$toggleAll.checked = parameter.checked;
self.$toggleAll.checked = parameter.checked;
},
setFilter: function () {
that._setFilter(parameter);
self._setFilter(parameter);
},
clearNewTodo: function () {
that.$newTodo.value = '';
self.$newTodo.value = '';
},
elementComplete: function () {
that._elementComplete(parameter.id, parameter.completed);
self._elementComplete(parameter.id, parameter.completed);
},
editItem: function () {
that._editItem(parameter.id, parameter.title);
self._editItem(parameter.id, parameter.title);
},
editItemDone: function () {
that._editItemDone(parameter.id, parameter.title);
self._editItemDone(parameter.id, parameter.title);
}
};
......@@ -139,18 +139,18 @@
};
View.prototype._bindItemEditDone = function (handler) {
var that = this;
$delegate(that.$todoList, 'li .edit', 'blur', function () {
var self = this;
$delegate(self.$todoList, 'li .edit', 'blur', function () {
if (!this.dataset.iscanceled) {
handler({
id: that._itemId(this),
id: self._itemId(this),
title: this.value
});
}
});
$delegate(that.$todoList, 'li .edit', 'keypress', function (event) {
if (event.keyCode === that.ENTER_KEY) {
$delegate(self.$todoList, 'li .edit', 'keypress', function (event) {
if (event.keyCode === self.ENTER_KEY) {
// Remove the cursor from the input when you hit enter just like if it
// were a real form
this.blur();
......@@ -159,57 +159,57 @@
};
View.prototype._bindItemEditCancel = function (handler) {
var that = this;
$delegate(that.$todoList, 'li .edit', 'keyup', function (event) {
if (event.keyCode === that.ESCAPE_KEY) {
var self = this;
$delegate(self.$todoList, 'li .edit', 'keyup', function (event) {
if (event.keyCode === self.ESCAPE_KEY) {
this.dataset.iscanceled = true;
this.blur();
handler({id: that._itemId(this)});
handler({id: self._itemId(this)});
}
});
};
View.prototype.bind = function (event, handler) {
var that = this;
var self = this;
if (event === 'newTodo') {
$on(that.$newTodo, 'change', function () {
handler(that.$newTodo.value);
$on(self.$newTodo, 'change', function () {
handler(self.$newTodo.value);
});
} else if (event === 'removeCompleted') {
$on(that.$clearCompleted, 'click', function () {
$on(self.$clearCompleted, 'click', function () {
handler();
});
} else if (event === 'toggleAll') {
$on(that.$toggleAll, 'click', function () {
$on(self.$toggleAll, 'click', function () {
handler({completed: this.checked});
});
} else if (event === 'itemEdit') {
$delegate(that.$todoList, 'li label', 'dblclick', function () {
handler({id: that._itemId(this)});
$delegate(self.$todoList, 'li label', 'dblclick', function () {
handler({id: self._itemId(this)});
});
} else if (event === 'itemRemove') {
$delegate(that.$todoList, '.destroy', 'click', function () {
handler({id: that._itemId(this)});
$delegate(self.$todoList, '.destroy', 'click', function () {
handler({id: self._itemId(this)});
});
} else if (event === 'itemToggle') {
$delegate(that.$todoList, '.toggle', 'click', function () {
$delegate(self.$todoList, '.toggle', 'click', function () {
handler({
id: that._itemId(this),
id: self._itemId(this),
completed: this.checked
});
});
} else if (event === 'itemEditDone') {
that._bindItemEditDone(handler);
self._bindItemEditDone(handler);
} else if (event === 'itemEditCancel') {
that._bindItemEditCancel(handler);
self._bindItemEditCancel(handler);
}
};
......
......@@ -198,7 +198,7 @@ describe('controller', function () {
view.trigger('toggleAll', {completed: false});
expect(view.render).toHaveBeenCalledWith('elementComplete', {id : 42, completed : false});
expect(view.render).toHaveBeenCalledWith('elementComplete', {id: 42, completed: false});
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment