joelf (8) [Avatar] Offline
#1
Could we refactor this code in the UpdateTaskCommand class file from :

public function result(event:Object):void {
  var resultEvent:ResultEvent = ResultEvent(event);
  var modelsmilieomodoModelLocator = PomodoModelLocator.getInstance();
  var newTask:XML = XML(event.result);

  for (var i:int = 0; i < model.tasksXLC.length; i++)
  {
    var ithTask:XML =
    XML(model.tasksXLC.getItemAt(i));
    if (ithTask.id == newTask.id) {
      model.tasksXLC.setItemAt(newTask, i);
      break;
    }
  }

}

to something like this :

public function result(event:Object):void {
  var resultEvent:ResultEvent = ResultEvent(event);
  var modelsmilieomodoModelLocator = PomodoModelLocator.getInstance();
  var newTask:XML = XML(event.result);

  for each(var ithTask:XML in model.tasksXLC) {
    if (ithTask.id == newTask.id) {
      ithTask = newTask;
      break;
    }
  }
}

?
The later appears easier to read.
peterarmstrong (94) [Avatar] Offline
#2
Re: Code refactoring suggestions
Hi Joel,

The book is in typesetting now, so I am only really able to apply fairly small fixes for bugs, not enhancements. (I do agree that the latter is more readable btw.)

Thanks,
Peter