From 9cd3708b63935190c87f21bad68a0ce9dfe082d2 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 14 Nov 2014 13:33:55 -0500 Subject: [PATCH] Instead of using a "discoveryLoading" action, return `true` so it can bubble up itself. --- .../discourse/controllers/discovery/categories.js.es6 | 5 ++++- .../discourse/controllers/discovery/topics.js.es6 | 5 ++++- .../javascripts/discourse/routes/build-category-route.js.es6 | 5 ----- .../javascripts/discourse/routes/build-topic-route.js.es6 | 4 +--- app/assets/javascripts/discourse/routes/discovery_route.js | 3 ++- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/discovery/categories.js.es6 b/app/assets/javascripts/discourse/controllers/discovery/categories.js.es6 index 72daaf1b5..0fff6219a 100644 --- a/app/assets/javascripts/discourse/controllers/discovery/categories.js.es6 +++ b/app/assets/javascripts/discourse/controllers/discovery/categories.js.es6 @@ -13,7 +13,10 @@ export default DiscoveryController.extend({ // Don't refresh if we're still loading if (this.get('controllers.discovery.loading')) { return; } - this.send('discoveryLoading'); + // If we `send('loading')` here, due to returning true it bubbles up to the + // router and ember throws an error due to missing `handlerInfos`. + // Lesson learned: Don't call `loading` yourself. + this.set('controllers.discovery.loading', true); Discourse.CategoryList.list('categories').then(function(list) { self.set('model', list); self.send('loadingComplete'); diff --git a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 index 1c547eeae..f5bea7b6e 100644 --- a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 +++ b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 @@ -42,7 +42,10 @@ var controllerOpts = { // Don't refresh if we're still loading if (this.get('controllers.discovery.loading')) { return; } - this.send('discoveryLoading'); + // If we `send('loading')` here, due to returning true it bubbles up to the + // router and ember throws an error due to missing `handlerInfos`. + // Lesson learned: Don't call `loading` yourself. + this.set('controllers.discovery.loading', true); Discourse.TopicList.find(filter).then(function(list) { self.setProperties({ model: list, selected: [] }); diff --git a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 b/app/assets/javascripts/discourse/routes/build-category-route.js.es6 index 812e63a3f..ec736d5e2 100644 --- a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 +++ b/app/assets/javascripts/discourse/routes/build-category-route.js.es6 @@ -5,10 +5,6 @@ export default function(filter, params) { return Discourse.Route.extend({ queryParams: queryParams, - beforeModel: function(transition) { - transition.send('discoveryLoading'); - }, - model: function(modelParams) { return Discourse.Category.findBySlug(modelParams.slug, modelParams.parentSlug); }, @@ -89,7 +85,6 @@ export default function(filter, params) { }); this.controllerFor('search').set('searchContext', model.get('searchContext')); - this.controllerFor('discovery').send('loadingComplete'); this.set('topics', null); this.openTopicDraft(topics); diff --git a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 index a27c7b34f..f00bd5d17 100644 --- a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 +++ b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 @@ -17,8 +17,7 @@ export default function(filter, extras) { return Discourse.Route.extend({ queryParams: queryParams, - beforeModel: function(transition) { - transition.send('discoveryLoading'); + beforeModel: function() { this.controllerFor('navigation/default').set('filterMode', filter); }, @@ -61,7 +60,6 @@ export default function(filter, extras) { this.openTopicDraft(model); this.controllerFor('navigation/default').set('canCreateTopic', model.get('can_create_topic')); - this.controllerFor('discovery').send('loadingComplete'); }, renderTemplate: function() { diff --git a/app/assets/javascripts/discourse/routes/discovery_route.js b/app/assets/javascripts/discourse/routes/discovery_route.js index a919dad4b..a4db51aa2 100644 --- a/app/assets/javascripts/discourse/routes/discovery_route.js +++ b/app/assets/javascripts/discourse/routes/discovery_route.js @@ -19,12 +19,13 @@ Discourse.DiscoveryRoute = Discourse.Route.extend(Discourse.ScrollTop, Discourse }, actions: { - discoveryLoading: function() { + loading: function() { var controller = this.controllerFor('discovery'); // If we're already loading don't do anything if (controller.get('loading')) { return; } controller.set('loading', true); + return true; }, loadingComplete: function() {