
var NotificationsController = SingleModelController.createComponent("NotificationsController");

NotificationsController.defineAlias("model", "notifications");

NotificationsController.defineMethod("updateView", function () {
  if (!this.view) return;

  var bottom = 0;
  this.notifications.notifications = this.notifications.notifications.filter(function (notification) {
    var element = this.view.querySelector("[data-ica-notification-id='{0}']".format(notification.componentId));

    // Check existing element
    if (element) {
      element.style.bottom = bottom + "px";
    } else {
      // Create new view
      var fragment;
      switch (notification.constructor) {
      case BasicNotification:
        fragment = BasicNotificationController.createViewFragment();
        element = fragment.querySelector(".notification");
        element.style.bottom = bottom + "px";
        this.view.appendChild(fragment);
        new BasicNotificationController(notification, element).componentOf = this;
        break;
      case ProgressNotification:
      case XHRProgressNotification:
        fragment = XHRProgressNotificationController.createViewFragment();
        element = fragment.querySelector(".notification");
        element.style.bottom = bottom + "px";
        this.view.appendChild(fragment);
        new XHRProgressNotificationController(notification, element).componentOf = this;
        break;
      default:
        console.warn("Unhandled item:", notification.constructor);
        return false;
      }
    }

    bottom += element.offsetHeight + 8; // 16 px margin top & bottom

    return true;
  }.bind(this));
});

@@ -616,26 +616,55 @@
 iew%0A
-      var fragment
+%0A      // Match controller%0A      var Controller
 ;%0A  
@@ -732,33 +732,27 @@
 ication:
-%0A        fragment
+ Controller
  = Basic
@@ -777,194 +777,124 @@
 ller
-.createViewFragment();%0A        element = fragment.querySelector(%22.notification%22);%0A        element.style.bottom = bottom + %22px%22;%0A        this.view.appendChild(fragment);%0A        new Basic
+; break;%0A      case ProgressNotification: Controller = ProgressNotificationController; break;%0A      case XHRProgress
 Noti
@@ -893,32 +893,34 @@
 ressNotification
+: 
 Controller(notif
@@ -917,143 +917,196 @@
 ller
-(notification, element).componentOf = this;%0A        break;%0A      case ProgressNotification:%0A      case XHRProgressNotification:
+ = XHRProgressNotificationController; break;%0A      default:%0A        console.warn(%22Unhandled item:%22, notification.constructor);%0A        return false;%0A      %7D%0A%0A      // Create view
 %0A      
- 
+var
  fra
@@ -1113,39 +1113,16 @@
 gment = 
-XHRProgressNotification
 Controll
@@ -1146,18 +1146,16 @@
 ment();%0A
-  
       el
@@ -1205,26 +1205,24 @@
 on%22);%0A      
-  
 element.styl
@@ -1247,18 +1247,16 @@
 + %22px%22;%0A
-  
       th
@@ -1296,37 +1296,12 @@
     
-  
 new 
-XHRProgressNotification
 Cont
@@ -1354,135 +1354,8 @@
 is;%0A
-        break;%0A      default:%0A        console.warn(%22Unhandled item:%22, notification.constructor);%0A        return false;%0A      %7D%0A
     

Optimize controller view update