From 091d6dc9fce1808c20508c06ee2d2609469da521 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 20 Apr 2020 16:51:36 -0400 Subject: [PATCH] DEV: Triggering "saw" on every element seems pointless We don't seem to wire this up to any listeners, so why waste time doing all this work? --- .../discourse/components/discovery-topics-list.js | 4 +--- .../javascripts/discourse/components/user-stream.js | 5 +---- app/assets/javascripts/discourse/lib/eyeline.js | 12 ------------ 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/discourse/components/discovery-topics-list.js b/app/assets/javascripts/discourse/components/discovery-topics-list.js index 30a0118a339..28ab1efab59 100644 --- a/app/assets/javascripts/discourse/components/discovery-topics-list.js +++ b/app/assets/javascripts/discourse/components/discovery-topics-list.js @@ -38,9 +38,7 @@ const DiscoveryTopicsListComponent = Component.extend(UrlRefresh, LoadMore, { Discourse.updateContextCount(0); this.model.loadMore().then(hasMoreResults => { schedule("afterRender", () => this.saveScrollPosition()); - if (!hasMoreResults) { - this.eyeline.flushRest(); - } else if ($(window).height() >= $(document).height()) { + if (hasMoreResults && $(window).height() >= $(document).height()) { this.send("loadMore"); } }); diff --git a/app/assets/javascripts/discourse/components/user-stream.js b/app/assets/javascripts/discourse/components/user-stream.js index 62d9fe7f0d8..aadd188699a 100644 --- a/app/assets/javascripts/discourse/components/user-stream.js +++ b/app/assets/javascripts/discourse/components/user-stream.js @@ -110,10 +110,7 @@ export default Component.extend(LoadMore, { this.set("loading", true); const stream = this.stream; - stream.findItems().then(() => { - this.set("loading", false); - this.eyeline.flushRest(); - }); + stream.findItems().then(() => this.set("loading", false)); } } }); diff --git a/app/assets/javascripts/discourse/lib/eyeline.js b/app/assets/javascripts/discourse/lib/eyeline.js index d31602e4da0..53f2a8435ad 100644 --- a/app/assets/javascripts/discourse/lib/eyeline.js +++ b/app/assets/javascripts/discourse/lib/eyeline.js @@ -78,7 +78,6 @@ Eyeline.prototype.update = function() { // If you hit the bottom we mark all the elements as seen. Otherwise, just the first one if (!atBottom) { - appEvents.trigger("saw", { detail: $elem }); return false; } if (i === $elements.length - 1) { @@ -87,15 +86,4 @@ Eyeline.prototype.update = function() { }); }; -// Call this when we know aren't loading any more elements. Mark the rest as seen -Eyeline.prototype.flushRest = function() { - if (ENV.environment === "test") { - return; - } - - $(this.selector).each((i, elem) => - this.appEvents.trigger("saw", { detail: $(elem) }) - ); -}; - export default Eyeline;