From e064db35d97575b2beb95a326cbf82645e73b33f Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Mon, 24 Jun 2019 10:58:59 +0200 Subject: [PATCH] REFACTOR: removes self pattern from eyeline lib (#7796) --- .../javascripts/discourse/lib/eyeline.js.es6 | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/eyeline.js.es6 b/app/assets/javascripts/discourse/lib/eyeline.js.es6 index e18f0a45542..f49801f0996 100644 --- a/app/assets/javascripts/discourse/lib/eyeline.js.es6 +++ b/app/assets/javascripts/discourse/lib/eyeline.js.es6 @@ -12,8 +12,7 @@ Eyeline.prototype.update = function() { windowHeight = $(window).height(), docViewBottom = docViewTop + windowHeight, $elements = $(this.selector), - bottomOffset = $elements.last().offset(), - self = this; + bottomOffset = $elements.last().offset(); let atBottom = false; if (bottomOffset) { @@ -21,7 +20,7 @@ Eyeline.prototype.update = function() { bottomOffset.top <= docViewBottom && bottomOffset.top >= docViewTop; } - return $elements.each(function(i, elem) { + return $elements.each((i, elem) => { const $elem = $(elem), elemTop = $elem.offset().top, elemBottom = elemTop + $elem.height(); @@ -45,17 +44,17 @@ Eyeline.prototype.update = function() { // If you hit the bottom we mark all the elements as seen. Otherwise, just the first one if (!atBottom) { - self.trigger("saw", { detail: $elem }); + this.trigger("saw", { detail: $elem }); if (i === 0) { - self.trigger("sawTop", { detail: $elem }); + this.trigger("sawTop", { detail: $elem }); } return false; } if (i === 0) { - self.trigger("sawTop", { detail: $elem }); + this.trigger("sawTop", { detail: $elem }); } if (i === $elements.length - 1) { - return self.trigger("sawBottom", { detail: $elem }); + return this.trigger("sawBottom", { detail: $elem }); } }); }; @@ -65,10 +64,8 @@ Eyeline.prototype.flushRest = function() { if (Ember.testing) { return; } - const self = this; - $(this.selector).each(function(i, elem) { - return self.trigger("saw", { detail: $(elem) }); - }); + + $(this.selector).each((i, elem) => this.trigger("saw", { detail: $(elem) })); }; RSVP.EventTarget.mixin(Eyeline.prototype);