var utils = require('../../utils');

module.exports = TimerViewModel;

function TimerViewModel(events, element) {
  var self = this;

  self.events = events;
  self.element = element;
  self.chronos = new Chronos();

  self.state = self.INITIAL;

  element.innerHTML = '0:00:00';

  events.on('startTimer', function () {
    self.state = self.RUNNING;
  });

  events.on('pauseTimer', function () {
    self.state = self.PAUSED;
  });

  events.on('resetTimer', function () {
    self.state = self.INITIAL;
  });


  setInterval(function () {
    self.tick();
  }, 100);

}

TimerViewModel.prototype.tick = function () {
  var self = this;

  self.chronos.tick();
  self.state.update(self.chronos);
};

TimerViewModel.prototype.INITIAL = new State('INITIAL', function (chronos) { /* do nothing */ });
TimerViewModel.prototype.RUNNING = new State('RUNNING', function (chronos) { chronos.addDelta(); });
TimerViewModel.prototype.PAUSED = new State('PAUSED', function (chronos) { /* do nothing */ });

function Chronos() {
  var self = this;

  var now = new Date().getTime();
  self.currentTick = now;
  self.lastTick = now;
  self.elapsedTime = 0;
}
Chronos.prototype.tick = function () {
  var self = this;

  var now = new Date().getTime();
  self.lastTick = self.currentTick;
  self.currentTick = now;
};
Chronos.prototype.addDelta = function () {
  var self = this;

  var delta = self.currentTick - self.lastTick;
  self.elapsedTime += delta;
};

function State(identifier, updater) {
  var self = this;

  self.identifier = identifier;
  self.updater = updater;
}
State.prototype.update = function (chronos) {
  this.updater(chronos);
};
@@ -219,18 +219,16 @@
 nos();%0D%0A
-%0D%0A
   self.s
@@ -283,24 +283,43 @@
 :00:00';%0D%0A%0D%0A
+  self.reset();%0D%0A%0D%0A
   events.on(
@@ -519,36 +519,23 @@
    self.
-state = self.INITIAL
+reset()
 ;%0D%0A  %7D);
@@ -604,18 +604,16 @@
 ;%0D%0A%0D%0A%7D%0D%0A
-%0D%0A
 TimerVie
@@ -693,24 +693,24 @@
 os.tick();%0D%0A
-
   self.state
@@ -736,16 +736,153 @@
 s);%0D%0A%7D;%0D
+%0ATimerViewModel.prototype.reset = function () %7B%0D%0A  var self = this;%0D%0A%0D%0A  self.chronos = new Chronos();%0D%0A  self.state = self.INITIAL;%0D%0A%7D;%0D
 %0A%0D%0ATimer

Create a reset function