Adrian Lang has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/268066

Change subject: Remove slow $().closest call from snakview
......................................................................

Remove slow $().closest call from snakview

The `encapsulatedBy` option was too complicated anyway, since a `snakview`
would always be encapsulated if this option is set; it does not need to check
whether its parent actually exists.

Bug: T125642
Change-Id: Ib6d806886f79e5c3df362f3611aa7d4026cc0eb0
---
M view/resources/jquery/wikibase/snakview/snakview.js
M view/resources/wikibase/view/ViewFactory.js
M view/tests/qunit/wikibase/view/ViewFactory.tests.js
3 files changed, 16 insertions(+), 31 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/66/268066/1

diff --git a/view/resources/jquery/wikibase/snakview/snakview.js 
b/view/resources/jquery/wikibase/snakview/snakview.js
index 26602b7..c79c568 100644
--- a/view/resources/jquery/wikibase/snakview/snakview.js
+++ b/view/resources/jquery/wikibase/snakview/snakview.js
@@ -46,10 +46,8 @@
  * @param {dataTypes.DataTypeStore} options.dataTypeStore
  *        Required to retrieve and evaluate a proper `dataTypes.DataType` 
object when interacting on
  *        a "value" `Variation`.
- * @param {string} [options.encapsulatedBy]
- *        If the `snakview`s DOM node has a parent that is selectable by the 
provided CSS selector,
- *        the `Property` part of the `snakview` is not (re-)rendered when 
initializing the
- *        `snakview` unless the `snakview`s whole DOM structure is empty.
+ * @param {boolean} [options.drawProperty=true]
+ *        The `Property` part of the `snakview` is not rendered when 
`drawProperty` is false.
  */
 /**
  * @event afterstartediting
@@ -99,7 +97,7 @@
                entityStore: null,
                valueViewBuilder: null,
                dataTypeStore: null,
-               encapsulatedBy: null
+               drawProperty: true
        },
 
        /**
@@ -158,7 +156,7 @@
                        snakTypeSelectorIsEmpty = 
!this.$snakTypeSelector.contents().length,
                        snakValueIsEmpty = !this.$snakValue.contents().length;
 
-               if ( propertyIsEmpty && !this._isEncapsulated() ) {
+               if ( propertyIsEmpty && this.options.drawProperty ) {
                        this.drawProperty();
                }
 
@@ -175,18 +173,6 @@
                        // This clearly implies draw() since it requires visual 
changes!
                        this.startEditing();
                }
-       },
-
-       /**
-        * @private
-        *
-        * @return {boolean}
-        */
-       _isEncapsulated: function() {
-               return !!(
-                       this.options.encapsulatedBy
-                       && this.element.closest( this.options.encapsulatedBy 
).length
-               );
        },
 
        /**
@@ -724,7 +710,7 @@
                        propertyId = this.value().property;
 
                if ( this.options.locked.property
-                       && ( this.$property.contents().length || 
this._isEncapsulated() )
+                       && ( this.$property.contents().length || 
this.options.drawProperty )
                ) {
                        return deferred.resolve().promise();
                }
diff --git a/view/resources/wikibase/view/ViewFactory.js 
b/view/resources/wikibase/view/ViewFactory.js
index f318fd3..d0a11e0 100644
--- a/view/resources/wikibase/view/ViewFactory.js
+++ b/view/resources/wikibase/view/ViewFactory.js
@@ -321,7 +321,7 @@
                                                buildSnakView: $.proxy(
                                                        this.getSnakView,
                                                        this,
-                                                       ':' + 
$.wikibase.statementview.prototype.widgetFullName.toLowerCase()
+                                                       true
                                                ),
                                                claimsChanger: 
this._entityChangersFactory.getClaimsChanger(),
                                                entityIdPlainFormatter: 
this._entityIdPlainFormatter,
@@ -382,7 +382,7 @@
                        listItemWidget: $.wikibase.snakview,
                        newItemOptionsFn: $.proxy( function( value ) {
                                return this._getSnakViewOptions(
-                                       null,
+                                       true,
                                        {
                                                locked: {
                                                        // Do not allow 
changing the property when editing existing an snak.
@@ -401,26 +401,26 @@
        /**
         * Construct a suitable view for the given snak on the given DOM element
         *
-        * @param {string|null} encapsulatedBy A jQuery selector for getting 
the encapsulating view
+        * @param {boolean} drawProperty Whether the snakview should draw its 
property
         * @param {Object} options An object with keys `locked` and 
`autoStartEditing`
         * @param {wikibase.datamodel.Snak|null} snak
         * @param {jQuery} $dom
         * @return {jQuery.wikibase.snakview} The constructed snakview
         */
-       SELF.prototype.getSnakView = function( encapsulatedBy, options, snak, 
$dom ) {
+       SELF.prototype.getSnakView = function( drawProperty, options, snak, 
$dom ) {
                return this._getView(
                        'snakview',
                        $dom,
-                       this._getSnakViewOptions( encapsulatedBy, options, snak 
)
+                       this._getSnakViewOptions( drawProperty, options, snak )
                );
        };
 
        /**
-        * @param {string|null} encapsulatedBy A jQuery selector for getting 
the encapsulating view
+        * @param {boolean} drawProperty Whether the snakview should draw its 
property
         * @param {Object} options An object with keys `locked` and 
`autoStartEditing`
         * @param {wikibase.datamodel.Snak|null} snak
         */
-       SELF.prototype._getSnakViewOptions = function( encapsulatedBy, options, 
snak ) {
+       SELF.prototype._getSnakViewOptions = function( drawProperty, options, 
snak ) {
                return {
                        value: snak || undefined,
                        locked: options.locked,
@@ -430,7 +430,7 @@
                        entityIdPlainFormatter: this._entityIdPlainFormatter,
                        entityStore: this._entityStore,
                        valueViewBuilder: this._getValueViewBuilder(),
-                       encapsulatedBy: encapsulatedBy
+                       drawProperty: drawProperty
                };
        };
 
diff --git a/view/tests/qunit/wikibase/view/ViewFactory.tests.js 
b/view/tests/qunit/wikibase/view/ViewFactory.tests.js
index 71e05eb..62b9ea3 100644
--- a/view/tests/qunit/wikibase/view/ViewFactory.tests.js
+++ b/view/tests/qunit/wikibase/view/ViewFactory.tests.js
@@ -477,7 +477,7 @@
                                },
                                autoStartEditing: undefined,
                                dataTypeStore: dataTypeStore,
-                               encapsulatedBy: null,
+                               drawProperty: true,
                                entityIdHtmlFormatter: entityIdHtmlFormatter,
                                entityIdPlainFormatter: entityIdPlainFormatter,
                                entityStore: entityStore,
@@ -531,7 +531,6 @@
                                parserStore,
                                userLanguages
                        ),
-                       encapsulatedBy = 'encapsulatedBy',
                        options = {},
                        $dom = $( '<div/>' );
 
@@ -539,7 +538,7 @@
 
                sinon.spy( wb, 'ValueViewBuilder' );
 
-               viewFactory.getSnakView( encapsulatedBy, options, value, $dom );
+               viewFactory.getSnakView( false, options, value, $dom );
 
                sinon.assert.calledWith(
                        $.wikibase.snakview,
@@ -552,7 +551,7 @@
                                entityIdPlainFormatter: entityIdPlainFormatter,
                                entityStore: entityStore,
                                valueViewBuilder: 
wb.ValueViewBuilder.returnValues[0],
-                               encapsulatedBy: encapsulatedBy
+                               drawProperty: false
                        } )
                );
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib6d806886f79e5c3df362f3611aa7d4026cc0eb0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Adrian Lang <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to