Skip to content

Commit

Permalink
fix: ensure timers are cleaned up on service destroy (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
makepanic authored and Scott Batson committed Nov 19, 2019
1 parent 5ad7d8d commit f2229f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions addon/services/flash-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export default Service.extend({
this.queue = emberArray();
},

willDestroy() {
this._super(...arguments);
this.clearMessages();
},

add(options = {}) {
this._enqueue(this._newFlashMessage(options));

Expand All @@ -53,6 +58,7 @@ export default Service.extend({
return;
}

flashes.forEach(flash => flash.destroyMessage());
flashes.clear();

return this;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/services/flash-messages-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module('FlashMessagesService', function(hooks) {
service.success('foo');
service.success('bar');
service.success('baz');
service.clearMessages();
run(() => service.clearMessages());

assert.equal(typeOf(get(service, 'queue')), 'array', 'it returns an array');
assert.equal(get(service, 'queue.length'), 0, 'it clears the array');
Expand Down

0 comments on commit f2229f4

Please sign in to comment.