<commit_before>define(['app'], function (app) {
  "use strict";

  var labels = {
    'pomodoro': {
      'title': 'Pomodoro finished!',
      'body':  'Time for a break.'
    },
    'break': {
      'title': "Break time's over!",
      'body':  'Back to work.'
    }
  };

  return app.factory('timeService',
    ['$rootScope', 'pomodoroService', 'notificationService', 'settingsService',
    function (rootScope, pomodoroService, notificationService, settingsService) {

    function TimedSession () {
      this.completed = 0;
      this.isPomo = true;
      this.autoStart = true;
      this.timeInterval = pomodoroService.pomodoro();
    }
    TimedSession.prototype.complete = function () {
      if (this.isPomo) {
        this.autoStart = true;
        this.timeInterval = this.finishedPomo();
      }
      else {
        this.autoStart = false;
        this.timeInterval = this.finishedBreak();
      }

      this.isPomo = !this.isPomo;
    };
    TimedSession.prototype.finishedPomo = function () {
      this.completed++;

      return (this.completed % 4 === 0)
        ? pomodoroService.longBreak()
        : pomodoroService.shortBreak();
    };
    TimedSession.prototype.finishedBreak = function () {
      return pomodoroService.pomodoro();
    };

    var session = new TimedSession();

    return {
      timerFinished: function () {
        var copy = (session.isPomo) ? labels.pomodoro : labels['break'];

        if (settingsService.get().alarms.notification) {
          notificationService.display(copy.title, copy.body);
        }

        rootScope.$broadcast('timeInterval:complete', session.isPomo, session.timeInterval.minutes);

        session.complete();

        rootScope.$broadcast('timeInterval:new', session.timeInterval, session.autoStart);
      }
    };
  }]);
});<commit_msg>✒ Prevent subscribers from altering session's time interval<commit_after>define(['app'], function (app) {
  "use strict";

  var labels = {
    'pomodoro': {
      'title': 'Pomodoro finished!',
      'body':  'Time for a break.'
    },
    'break': {
      'title': "Break time's over!",
      'body':  'Back to work.'
    }
  };

  function clone (obj) {
    var result = {};
    for (var i in obj) {
      if (obj.hasOwnProperty(i)) {
        result[i] = obj[i];
      }
    }

    return result;
  }

  return app.factory('timeService',
    ['$rootScope', 'pomodoroService', 'notificationService', 'settingsService',
    function (rootScope, pomodoroService, notificationService, settingsService) {

    function TimedSession () {
      this.completed = 0;
      this.isPomo = true;
      this.autoStart = true;
      this.timeInterval = pomodoroService.pomodoro();
    }
    TimedSession.prototype.complete = function () {
      if (this.isPomo) {
        this.autoStart = true;
        this.timeInterval = this.finishedPomo();
      }
      else {
        this.autoStart = false;
        this.timeInterval = this.finishedBreak();
      }

      this.isPomo = !this.isPomo;
    };
    TimedSession.prototype.finishedPomo = function () {
      this.completed++;

      return (this.completed % 4 === 0)
        ? pomodoroService.longBreak()
        : pomodoroService.shortBreak();
    };
    TimedSession.prototype.finishedBreak = function () {
      return pomodoroService.pomodoro();
    };

    var session = new TimedSession();

    return {
      timerFinished: function () {
        var copy = (session.isPomo) ? labels.pomodoro : labels['break'];

        if (settingsService.get().alarms.notification) {
          notificationService.display(copy.title, copy.body);
        }

        rootScope.$broadcast('timeInterval:complete', session.isPomo, session.timeInterval.minutes);

        session.complete();

        rootScope.$broadcast('timeInterval:new', clone(session.timeInterval), session.autoStart);
      }
    };
  }]);
});
{'fraction_non_alphanumeric': 0.13989637305699482, 'fraction_numerical': 0.0015544041450777201, 'mean_word_length': 2.594972067039106, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3917665', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1136, 'n_words': 217}