From c629a1aac48252b319ce50348939312b098b066e Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Thu, 2 Nov 2017 10:43:56 -0500 Subject: [PATCH 1/6] Make notifications.clear public and emit event --- src/notification-manager.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/notification-manager.js b/src/notification-manager.js index df5e5fb42..3d15419d5 100644 --- a/src/notification-manager.js +++ b/src/notification-manager.js @@ -199,8 +199,10 @@ class NotificationManager { /* Section: Managing Notifications */ - + + // Public: Clear all the notifications. clear () { this.notifications = [] + this.emitter.emit('did-clear-notifications') } } From a565988c6f8aca6cfb4ebf6bd4902aa6ae5796c3 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Thu, 2 Nov 2017 10:59:04 -0500 Subject: [PATCH 2/6] add event --- src/notification-manager.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/notification-manager.js b/src/notification-manager.js index 3d15419d5..cd2a06e9e 100644 --- a/src/notification-manager.js +++ b/src/notification-manager.js @@ -27,6 +27,15 @@ class NotificationManager { return this.emitter.on('did-add-notification', callback) } + // Public: Invoke the given callback after the notifications have been cleared. + // + // * `callback` {Function} to be called after the notifications are cleared. + // + // Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. + onDidClearNotifications (callback) { + return this.emitter.on('did-clear-notifications', callback) + } + /* Section: Adding Notifications */ From 076308ab7343cc907722e7094a7402e51c6c6128 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Thu, 16 Nov 2017 00:10:13 -0600 Subject: [PATCH 3/6] fix linting --- src/notification-manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/notification-manager.js b/src/notification-manager.js index cd2a06e9e..a0ae139d3 100644 --- a/src/notification-manager.js +++ b/src/notification-manager.js @@ -208,7 +208,7 @@ class NotificationManager { /* Section: Managing Notifications */ - + // Public: Clear all the notifications. clear () { this.notifications = [] From fe4df885d650724e5f11ccbc024c518a6d34d0fd Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Thu, 16 Nov 2017 00:29:24 -0600 Subject: [PATCH 4/6] add tests --- spec/notification-manager-spec.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/notification-manager-spec.js b/spec/notification-manager-spec.js index 3f6a20b67..b62569ee6 100644 --- a/spec/notification-manager-spec.js +++ b/spec/notification-manager-spec.js @@ -66,4 +66,27 @@ describe('NotificationManager', () => { expect(notification.getType()).toBe('success') }) }) + + describe('clearing notifications', function () { + it('clears the notifications when ::clear has been called', function(){ + manager.addSuccess('success') + expect(manager.getNotifications().length).toBe(1) + manager.clear() + expect(manager.getNotifications().length).toBe(0) + }) + + describe('adding events', () => { + let addSpy + + beforeEach(() => { + addSpy = jasmine.createSpy() + manager.onDidClearNotifications(addSpy) + }) + + it('emits an event when the notifications have been cleared', () => { + manager.clear() + expect(addSpy).toHaveBeenCalled() + }) + }) + }) }) From d28166b1e4dbb3875fb8b340c2d494285d88faac Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Fri, 8 Dec 2017 16:15:51 -0600 Subject: [PATCH 5/6] code cleanup --- spec/notification-manager-spec.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/notification-manager-spec.js b/spec/notification-manager-spec.js index b62569ee6..a3ba63905 100644 --- a/spec/notification-manager-spec.js +++ b/spec/notification-manager-spec.js @@ -68,7 +68,7 @@ describe('NotificationManager', () => { }) describe('clearing notifications', function () { - it('clears the notifications when ::clear has been called', function(){ + it('clears the notifications when ::clear has been called', () => { manager.addSuccess('success') expect(manager.getNotifications().length).toBe(1) manager.clear() @@ -76,16 +76,16 @@ describe('NotificationManager', () => { }) describe('adding events', () => { - let addSpy + let clearSpy beforeEach(() => { - addSpy = jasmine.createSpy() - manager.onDidClearNotifications(addSpy) + clearSpy = jasmine.createSpy() + manager.onDidClearNotifications(clearSpy) }) it('emits an event when the notifications have been cleared', () => { manager.clear() - expect(addSpy).toHaveBeenCalled() + expect(clearSpy).toHaveBeenCalled() }) }) }) From b89bfa26c33465d386fa819bd31b3b6cfa1952f6 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Fri, 8 Dec 2017 16:18:06 -0600 Subject: [PATCH 6/6] more cleanup --- spec/notification-manager-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/notification-manager-spec.js b/spec/notification-manager-spec.js index a3ba63905..3a8544d4e 100644 --- a/spec/notification-manager-spec.js +++ b/spec/notification-manager-spec.js @@ -67,7 +67,7 @@ describe('NotificationManager', () => { }) }) - describe('clearing notifications', function () { + describe('clearing notifications', () => { it('clears the notifications when ::clear has been called', () => { manager.addSuccess('success') expect(manager.getNotifications().length).toBe(1)