Week 8, day 1

Last night I went to bed extremely unhappy with my code. I even had to ask for help on Stack Overflow. As I lay in bed I began to wonder if there could be a better way.

And sure enough there was! More after the break.

ToDo app

I refactored the living daylights out of my code, trimming every ounce of fat away and can happily say I have something to be proud of. Unfortunately, I didn't get my protractor end-to-end tests working but that's just something I'll have to discuss with my coach in code review tomorrow.

toDoList.controller('ToDoListController', [function(){
  var self = this;

  self.itemList = [];
  self.view = 1;

  self.addItem = function(){
    self.itemList.push({'name': self.newItem, 'isCompleted': false});
    self.newItem = '';
  };

  self.clearCompleted = function(){
    self.itemList = self.itemList.filter(function(item){
      return !item.isCompleted;
    });
  };

  self.setView = function(selection){
    self.view = selection;
  };

  self.isView = function(selection){
    return self.view === selection;
  };
}]);

You should've seen the spaghetti that was my first version, in fact you can on my Git if you go back a few commits on master.

Written on May 4, 2015