Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

Notification Clearall not Removing Elements from View #320

Closed
liamfd opened this issue Dec 16, 2014 · 1 comment
Closed

Notification Clearall not Removing Elements from View #320

liamfd opened this issue Dec 16, 2014 · 1 comment

Comments

@liamfd
Copy link

liamfd commented Dec 16, 2014

In addition to the $scope.apply issue detailed elsewhere, I have been having difficulty getting the notification clearall to run properly.

The notification open:
FoundationApi.publish('my-notification', { color:"alert", content: 'Bad news.', position:"top middle"});

The close:
FoundationApi.publish('my-notification', 'clearall');

Currently, it goes through the function, but the notification remains visible on the page. It's possible it's something on my end (again) but I did create a small patch, if others are having this issue.

Currently, it looks like (in notification.js):

    controller.clearAll = function() {
      notifications = [];
    };

This does not remove the notification. However, if we change it to

    controller.clearAll = function() {
      notifications.length = 0;
    };

Or

    controller.clearAll = function() {
      while(notifications.length > 0) {
        notifications.pop();
      }
    };

(which is more performant, according to this stackoverflow post) they are removed appropriately. I've seen behavior like this before when trying to empty arrays in services, and I believe it was because setting it to an empty array creates a new object, and breaks the data binding, whereas the other two methods only modify the current object.

Also, in the very limited testing I've managed to do, this has worked sans $scope.apply().

Finally, would it be possible to add a section to the docs that explains how to close notifications programmatically? I wound up spelunking in the source to find FoundationApi.publish('my-notification', 'clearall');

@liamfd liamfd changed the title Notification Clearall not Running Notification Clearall not Removing Notification Elements from View Dec 16, 2014
@liamfd liamfd changed the title Notification Clearall not Removing Notification Elements from View Notification Clearall not Removing Elements from View Dec 16, 2014
@AntJanus
Copy link
Contributor

Good catch. I'm submitting a fix.

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

No branches or pull requests

3 participants