Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/260723
Change subject: Performance and readability of independent statement ordering
......................................................................
Performance and readability of independent statement ordering
Bug: T119946
Change-Id: I834177ef05d97dcde327a0e00dd7647937ddba20
---
M view/resources/jquery/wikibase/jquery.wikibase.listview.ListItemAdapter.js
M view/resources/jquery/wikibase/jquery.wikibase.listview.js
M view/resources/wikibase/view/ViewFactory.js
3 files changed, 21 insertions(+), 21 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/23/260723/1
diff --git
a/view/resources/jquery/wikibase/jquery.wikibase.listview.ListItemAdapter.js
b/view/resources/jquery/wikibase/jquery.wikibase.listview.ListItemAdapter.js
index dfe3c8d..b4747e3 100644
--- a/view/resources/jquery/wikibase/jquery.wikibase.listview.ListItemAdapter.js
+++ b/view/resources/jquery/wikibase/jquery.wikibase.listview.ListItemAdapter.js
@@ -29,18 +29,18 @@
* A function called when the related `listview` is
instantiating a new list item. The
* function has to return an `Object` which will then be used as
`options` object for a
* new widget (which is specified in the `listItemWidget`
option).
- * The new new list item's value is given as the function's
first parameter, if an empty
+ * The new list item's value is given as the function's first
parameter, if an empty
* list item should be created, the value will be `null`. The
function's context is the
* `ListItemAdapter` instance.
- * Either `newItemOptionsFn` or `getNewItem` has to be passed.
+ * Either the `newItemOptionsFn` or the `getNewItem` option has
to be passed.
* @param {Function} [options.getNewItem]
* A function called when the related `listview` is
instantiating a new list item. The
* function has to return an instance of
`options.listItemWidget`.
- * The new new list item's value is given as the function's
first parameter, if an empty
+ * The new list item's value is given as the function's first
parameter, if an empty
* list item should be created, the value will be `null`. The
function's context is the
* `ListItemAdapter` instance. The second parameter is the DOM
element the list item widget
* should be initialized on.
- * Either `newItemOptionsFn` or `getNewItem` has to be passed.
+ * Either the `newItemOptionsFn` or the `getNewItem` option has
to be passed.
*
* @throws {Error} if a required option is not specified properly.
* @throws {Error} if the widget specified in the `listItemWidget`
option does not feature a
@@ -120,7 +120,11 @@
* @return {jQuery.Widget}
*/
newListItem: function( $subject, value ) {
- return this._options.getNewItem( value, $subject[0] );
+ var item = this._options.getNewItem( value, $subject[0]
);
+ if( !( item instanceof $.Widget ) ) {
+ throw new Error( 'The "getNewItem" option must
return a jQuery.Widget' );
+ }
+ return item;
}
} );
diff --git a/view/resources/jquery/wikibase/jquery.wikibase.listview.js
b/view/resources/jquery/wikibase/jquery.wikibase.listview.js
index 83816e1..f1dd8c3 100644
--- a/view/resources/jquery/wikibase/jquery.wikibase.listview.js
+++ b/view/resources/jquery/wikibase/jquery.wikibase.listview.js
@@ -165,13 +165,13 @@
var i, items = this.option( 'value' );
if ( items === null ) {
- this._initFromDom();
- return;
- }
-
- // initialize view for each of the list item values:
- for ( i in items ) {
- this.addItem( items[i] );
+ for ( i = this._reusedItems.length; i--; ) {
+ this.addItem( null );
+ }
+ } else {
+ for ( i in items ) {
+ this.addItem( items[i] );
+ }
}
},
@@ -340,12 +340,6 @@
this._lia.newListItem( $newLi, liValue );
return $newLi;
- },
-
- _initFromDom: function() {
- while ( this._reusedItems.length > 0 ) {
- this.addItem( null );
- }
},
/**
diff --git a/view/resources/wikibase/view/ViewFactory.js
b/view/resources/wikibase/view/ViewFactory.js
index e0933c9..2546931 100644
--- a/view/resources/wikibase/view/ViewFactory.js
+++ b/view/resources/wikibase/view/ViewFactory.js
@@ -218,7 +218,7 @@
/**
* Construct a suitable view for the list of statement groups for the
given entity on the given DOM element
*
- * @param {wikibase.datamodel.Entity} entity
+ * @param {wikibase.datamodel.Item|wikibase.datamodel.Property} entity
* @param {jQuery} $dom
* @return {jQuery.wikibase.statementgrouplistview} The constructed
statementgrouplistview
**/
@@ -233,7 +233,8 @@
function( guid ) {
var res = null;
statementGroupSet.each(
function() {
-
this.getItemContainer().each( function() {
+ // FIXME: This accesses
a private property to avoid cloning.
+
this._groupableCollection.each( function() {
if (
this.getClaim().getGuid() === guid ) {
res =
this;
}
@@ -281,6 +282,7 @@
**/
SELF.prototype.getStatementListView = function( entityId, propertyId,
getStatementForGuid, value, $dom ) {
propertyId = propertyId || $dom.closest(
'.wikibase-statementgroupview' ).attr( 'id' );
+
return this._getView(
'statementlistview',
$dom,
@@ -289,7 +291,7 @@
listItemAdapter:
this.getListItemAdapterForStatementView(
entityId,
function( dom ) {
- var guidMatch =
dom.className.match( /wikibase-statement-([^ ]+)/ );
+ var guidMatch =
dom.className.match( /wikibase-statement-(\S+)/ );
return guidMatch ?
getStatementForGuid( guidMatch[ 1 ] ) : null;
},
propertyId
--
To view, visit https://gerrit.wikimedia.org/r/260723
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I834177ef05d97dcde327a0e00dd7647937ddba20
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits