jenkins-bot has submitted this change and it was merged.

Change subject: Toolbar: Defer computation of the narrow threshold
......................................................................


Toolbar: Defer computation of the narrow threshold

Computing this during initialization causes an expensive reflow,
but we only ever actually use this value in the window resize
handler. Caching it is good, but lazy-compute it on first use
instead of slowing down initialization.

Change-Id: I18077599ccd9012e6d3c834b6635687bf087639c
---
M src/Toolbar.js
1 file changed, 16 insertions(+), 2 deletions(-)

Approvals:
  Jforrester: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/Toolbar.js b/src/Toolbar.js
index 39e4f41..4df56d8 100644
--- a/src/Toolbar.js
+++ b/src/Toolbar.js
@@ -306,6 +306,7 @@
        this.$bar = $( '<div>' );
        this.$actions = $( '<div>' );
        this.initialized = false;
+       this.narrowThreshold = null;
        this.onWindowResizeHandler = this.onWindowResize.bind( this );
 
        // Events
@@ -388,8 +389,22 @@
 OO.ui.Toolbar.prototype.onWindowResize = function () {
        this.$element.toggleClass(
                'oo-ui-toolbar-narrow',
-               this.$bar.width() <= this.narrowThreshold
+               this.$bar.width() <= this.getNarrowThreshold()
        );
+};
+
+/**
+ * Get the (lazily-computed) width threshold for applying the 
oo-ui-toolbar-narrow
+ * class.
+ *
+ * @private
+ * @return {number} Width threshold in pixels
+ */
+OO.ui.Toolbar.prototype.getNarrowThreshold = function () {
+       if ( this.narrowThreshold === null ) {
+               this.narrowThreshold = this.$group.width() + 
this.$actions.width();
+       }
+       return this.narrowThreshold;
 };
 
 /**
@@ -399,7 +414,6 @@
 OO.ui.Toolbar.prototype.initialize = function () {
        if ( !this.initialized ) {
                this.initialized = true;
-               this.narrowThreshold = this.$group.width() + 
this.$actions.width();
                $( this.getElementWindow() ).on( 'resize', 
this.onWindowResizeHandler );
                this.onWindowResize();
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/311215
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I18077599ccd9012e6d3c834b6635687bf087639c
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to