Jhernandez has uploaded a new change for review.
https://gerrit.wikimedia.org/r/304999
Change subject: Fix InfiniteScroll to unbind scroll events when disabled
......................................................................
Fix InfiniteScroll to unbind scroll events when disabled
Previously the component would bind to scroll events and never unbind leaving
a handler active and as such un-freeable memory.
This change makes the component bind to scroll when active, and unbind from it
when triggered/disabled, making it more efficient.
Bug: T124870
Change-Id: Ifa6638f257f51fb4e82d1f61a41960476fe4507e
---
M resources/mobile.infiniteScroll/InfiniteScroll.js
1 file changed, 13 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/99/304999/1
diff --git a/resources/mobile.infiniteScroll/InfiniteScroll.js
b/resources/mobile.infiniteScroll/InfiniteScroll.js
index 6787c9e..201f5d4 100644
--- a/resources/mobile.infiniteScroll/InfiniteScroll.js
+++ b/resources/mobile.infiniteScroll/InfiniteScroll.js
@@ -56,8 +56,7 @@
*/
function InfiniteScroll( threshold ) {
this.threshold = threshold || 100;
- this.enabled = true;
- this._bindScroll();
+ this.enable();
OO.EventEmitter.call( this );
}
OO.mixinClass( InfiniteScroll, OO.EventEmitter );
@@ -69,7 +68,16 @@
* @private
*/
_bindScroll: function () {
- M.on( 'scroll:throttled', $.proxy( this, '_onScroll' )
);
+ if (!this._scrollHandler) {
+ this._scrollHandler = $.proxy( this,
'_onScroll' );
+ M.on( 'scroll:throttled', this._scrollHandler );
+ }
+ },
+ _unbindScroll: function () {
+ if (this._scrollHandler) {
+ M.off( 'scroll:throttled', this._scrollHandler
);
+ this._scrollHandler = null;
+ }
},
/**
* Scroll handler. Triggers load event when near the end of the
container.
@@ -106,6 +114,7 @@
*/
enable: function () {
this.enabled = true;
+ this._bindScroll();
},
/**
* Disable the InfiniteScroll so that it doesn't trigger events.
@@ -113,6 +122,7 @@
*/
disable: function () {
this.enabled = false;
+ this._unbindScroll();
},
/**
* Set the element to compare to scroll position to
--
To view, visit https://gerrit.wikimedia.org/r/304999
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifa6638f257f51fb4e82d1f61a41960476fe4507e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits