Skip to content

Commit

Permalink
fix(rxNotify): message dismissed if scope being watched is destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Lamping committed Mar 5, 2014
1 parent 0947baf commit fbfa4d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
16 changes: 5 additions & 11 deletions src/rxNotify/rxNotify.js
Expand Up @@ -106,6 +106,11 @@ angular.module('encore.ui.rxNotify', ['ngSanitize'])
cb = addToStack;
} else if (changeType == 'dismiss') {
cb = dismiss;

// add a listener to dismiss message if scope is destroyed
scope.$on('$destroy', function () {
dismiss(message);
});
}

scope.$watch(prop, function (newVal) {
Expand Down Expand Up @@ -215,17 +220,6 @@ angular.module('encore.ui.rxNotify', ['ngSanitize'])
addAllNext();
});

// if page changes, cancel messages waiting on variable updates
$rootScope.$on('$routeChangeStart', function () {
_.each(stacks, function (stack) {
_.each(stack, function (message) {
if (_.isArray(message.dismiss)) {
dismiss(message);
}
});
});
});

// expose public API
return {
add: add,
Expand Down
5 changes: 2 additions & 3 deletions src/rxNotify/rxNotify.spec.js
Expand Up @@ -264,7 +264,7 @@ describe('rxNotify', function () {
expect(notifySvc.stacks[defaultStack].length).to.equal(0);
});

it('should dismiss message waiting on scope update if page changed', function () {
it('should dismiss message waiting on scope update if scope destroyed', function () {
// set expression to equal true (showing)
scope.loaded = false;

Expand All @@ -276,8 +276,7 @@ describe('rxNotify', function () {
// validate in stack
expect(notifySvc.stacks[defaultStack][0]).to.eql(msg);

// simulate route change
rootScope.$broadcast('$routeChangeStart');
scope.$destroy();

// validate not in stack
expect(notifySvc.stacks[defaultStack].length).to.equal(0);
Expand Down

0 comments on commit fbfa4d2

Please sign in to comment.