From 92118dd1d1f3db4abc5405f04707b5f3e0deec88 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 17 May 2017 10:29:18 +0800 Subject: [PATCH] FIX: Use observer to rerender widget instead. --- .../discourse/components/topic-notifications-button.js.es6 | 7 ++----- .../javascripts/discourse/components/topic-timeline.js.es6 | 5 +++++ .../discourse/widgets/topic-notifications-button.js.es6 | 4 +--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/discourse/components/topic-notifications-button.js.es6 b/app/assets/javascripts/discourse/components/topic-notifications-button.js.es6 index b53717855de..35aefe20475 100644 --- a/app/assets/javascripts/discourse/components/topic-notifications-button.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-notifications-button.js.es6 @@ -9,14 +9,11 @@ export default MountWidget.extend({ }, @observes('topic.details.notification_level') - _triggerEvent() { - this.appEvents.trigger('topic-notifications-button:changed', { - type: 'notification', id: this.get('topic.details.notification_level') - }); + _queueRerender() { + this.queueRerender(); }, didInsertElement() { this._super(); - this.dispatch('topic-notifications-button:changed', 'topic-notifications-button'); } }); diff --git a/app/assets/javascripts/discourse/components/topic-timeline.js.es6 b/app/assets/javascripts/discourse/components/topic-timeline.js.es6 index a5abbb6c245..5b1840250e1 100644 --- a/app/assets/javascripts/discourse/components/topic-timeline.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-timeline.js.es6 @@ -38,6 +38,11 @@ export default MountWidget.extend(Docking, { this.queueRerender(() => this.queueDockCheck()); }, + @observes('topic.details.notification_level') + _queueRerender() { + this.queueRerender(); + }, + dockCheck(info) { const mainOffset = $('#main').offset(); const offsetTop = mainOffset ? mainOffset.top : 0; diff --git a/app/assets/javascripts/discourse/widgets/topic-notifications-button.js.es6 b/app/assets/javascripts/discourse/widgets/topic-notifications-button.js.es6 index bd37c8b4d8a..4bf84e56316 100644 --- a/app/assets/javascripts/discourse/widgets/topic-notifications-button.js.es6 +++ b/app/assets/javascripts/discourse/widgets/topic-notifications-button.js.es6 @@ -91,9 +91,7 @@ export default createWidget('topic-notifications-button', { topicNotificationsButtonChanged(msg) { switch(msg.type) { case 'notification': - if (this.attrs.topic.get('details.notification_level') !== msg.id) { - this.notificationLevelChanged(msg.id); - } + this.notificationLevelChanged(msg.id); break; } }