Skip to content

Instantly share code, notes, and snippets.

@dbarrionuevo
Created August 28, 2014 23:26
Show Gist options
  • Select an option

  • Save dbarrionuevo/e1ae8797246aab2dea6b to your computer and use it in GitHub Desktop.

Select an option

Save dbarrionuevo/e1ae8797246aab2dea6b to your computer and use it in GitHub Desktop.
var NotificationsService = function () {
this.MAX_LEN = 10;
this.notificationsArchive = new NotificationsArchive();
this.notifications = [];
};
NotificationsService.prototype.push = function (notification) {
var newLen, notificationToArchive;
newLen = this.notifications.unshift(notification);
if (newLen > this.MAX_LEN) {
notificationToArchive = this.notifications.pop();
this.notificationsArchive.archive(notificationToArchive);
}
};
NotificationsService.prototype.getCurrent = function () {
return this.notifications;
};
@roperzh

roperzh commented Aug 28, 2014

Copy link
Copy Markdown
var NotificationsService = function() {
  var MAX_LEN = 10;
  var notificationsArchive = new NotificationsArchive();
  var notifications = [];

  return {
    push: function(notification) {
      var newLen, notificationToArchive;

      newLen = notifications.unshift(notification);

      if (newLen > MAX_LEN) {
        notificationToArchive = notifications.pop();
        notificationsArchive.archive(notificationToArchive);
      }
    },

    getCurrent: function() {
      return notifications;
    }
  }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment