Jonas Kress (WMDE) has uploaded a new change for review.

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

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

Revert "Remove slow $().closest call from snakview"

This reverts commit fb67fac6d5eec57735993479dd685cd4375ea42d.

Change-Id: I2b2dd8718cffa1e876ab2b68be43eb66b34130e6
---
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, 31 insertions(+), 16 deletions(-)


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

diff --git a/view/resources/jquery/wikibase/snakview/snakview.js 
b/view/resources/jquery/wikibase/snakview/snakview.js
index c79c568..26602b7 100644
--- a/view/resources/jquery/wikibase/snakview/snakview.js
+++ b/view/resources/jquery/wikibase/snakview/snakview.js
@@ -46,8 +46,10 @@
  * @param {dataTypes.DataTypeStore} options.dataTypeStore
  *        Required to retrieve and evaluate a proper `dataTypes.DataType` 
object when interacting on
  *        a "value" `Variation`.
- * @param {boolean} [options.drawProperty=true]
- *        The `Property` part of the `snakview` is not rendered when 
`drawProperty` is false.
+ * @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.
  */
 /**
  * @event afterstartediting
@@ -97,7 +99,7 @@
                entityStore: null,
                valueViewBuilder: null,
                dataTypeStore: null,
-               drawProperty: true
+               encapsulatedBy: null
        },
 
        /**
@@ -156,7 +158,7 @@
                        snakTypeSelectorIsEmpty = 
!this.$snakTypeSelector.contents().length,
                        snakValueIsEmpty = !this.$snakValue.contents().length;
 
-               if ( propertyIsEmpty && this.options.drawProperty ) {
+               if ( propertyIsEmpty && !this._isEncapsulated() ) {
                        this.drawProperty();
                }
 
@@ -173,6 +175,18 @@
                        // 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
+               );
        },
 
        /**
@@ -710,7 +724,7 @@
                        propertyId = this.value().property;
 
                if ( this.options.locked.property
-                       && ( this.$property.contents().length || 
this.options.drawProperty )
+                       && ( this.$property.contents().length || 
this._isEncapsulated() )
                ) {
                        return deferred.resolve().promise();
                }
diff --git a/view/resources/wikibase/view/ViewFactory.js 
b/view/resources/wikibase/view/ViewFactory.js
index 8bc8073..f318fd3 100644
--- a/view/resources/wikibase/view/ViewFactory.js
+++ b/view/resources/wikibase/view/ViewFactory.js
@@ -321,7 +321,7 @@
                                                buildSnakView: $.proxy(
                                                        this.getSnakView,
                                                        this,
-                                                       false
+                                                       ':' + 
$.wikibase.statementview.prototype.widgetFullName.toLowerCase()
                                                ),
                                                claimsChanger: 
this._entityChangersFactory.getClaimsChanger(),
                                                entityIdPlainFormatter: 
this._entityIdPlainFormatter,
@@ -382,7 +382,7 @@
                        listItemWidget: $.wikibase.snakview,
                        newItemOptionsFn: $.proxy( function( value ) {
                                return this._getSnakViewOptions(
-                                       true,
+                                       null,
                                        {
                                                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 {boolean} drawProperty Whether the snakview should draw its 
property
+        * @param {string|null} encapsulatedBy A jQuery selector for getting 
the encapsulating view
         * @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( drawProperty, options, snak, 
$dom ) {
+       SELF.prototype.getSnakView = function( encapsulatedBy, options, snak, 
$dom ) {
                return this._getView(
                        'snakview',
                        $dom,
-                       this._getSnakViewOptions( drawProperty, options, snak )
+                       this._getSnakViewOptions( encapsulatedBy, options, snak 
)
                );
        };
 
        /**
-        * @param {boolean} drawProperty Whether the snakview should draw its 
property
+        * @param {string|null} encapsulatedBy A jQuery selector for getting 
the encapsulating view
         * @param {Object} options An object with keys `locked` and 
`autoStartEditing`
         * @param {wikibase.datamodel.Snak|null} snak
         */
-       SELF.prototype._getSnakViewOptions = function( drawProperty, options, 
snak ) {
+       SELF.prototype._getSnakViewOptions = function( encapsulatedBy, options, 
snak ) {
                return {
                        value: snak || undefined,
                        locked: options.locked,
@@ -430,7 +430,7 @@
                        entityIdPlainFormatter: this._entityIdPlainFormatter,
                        entityStore: this._entityStore,
                        valueViewBuilder: this._getValueViewBuilder(),
-                       drawProperty: drawProperty
+                       encapsulatedBy: encapsulatedBy
                };
        };
 
diff --git a/view/tests/qunit/wikibase/view/ViewFactory.tests.js 
b/view/tests/qunit/wikibase/view/ViewFactory.tests.js
index 62b9ea3..71e05eb 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,
-                               drawProperty: true,
+                               encapsulatedBy: null,
                                entityIdHtmlFormatter: entityIdHtmlFormatter,
                                entityIdPlainFormatter: entityIdPlainFormatter,
                                entityStore: entityStore,
@@ -531,6 +531,7 @@
                                parserStore,
                                userLanguages
                        ),
+                       encapsulatedBy = 'encapsulatedBy',
                        options = {},
                        $dom = $( '<div/>' );
 
@@ -538,7 +539,7 @@
 
                sinon.spy( wb, 'ValueViewBuilder' );
 
-               viewFactory.getSnakView( false, options, value, $dom );
+               viewFactory.getSnakView( encapsulatedBy, options, value, $dom );
 
                sinon.assert.calledWith(
                        $.wikibase.snakview,
@@ -551,7 +552,7 @@
                                entityIdPlainFormatter: entityIdPlainFormatter,
                                entityStore: entityStore,
                                valueViewBuilder: 
wb.ValueViewBuilder.returnValues[0],
-                               drawProperty: false
+                               encapsulatedBy: encapsulatedBy
                        } )
                );
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2b2dd8718cffa1e876ab2b68be43eb66b34130e6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de>

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

Reply via email to