jenkins-bot has submitted this change and it was merged.
Change subject: ve.dm.MWTransclusionModel: Clean up and fix logic error
......................................................................
ve.dm.MWTransclusionModel: Clean up and fix logic error
* Reduce duplication by calling #removePart (equal, line by line)
* Reset `remove` at the start of each iteration, it was leaking
through to future iterations.
* Minor simplification in property access.
Change-Id: Ie0a83d582804bc50131ca5a8da36b0605dd4a6c3
---
M modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js
1 file changed, 9 insertions(+), 11 deletions(-)
Approvals:
Catrope: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js
b/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js
index 173db9f..7cbfbeb 100644
--- a/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js
+++ b/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js
@@ -98,28 +98,25 @@
* @fires change
*/
ve.dm.MWTransclusionModel.prototype.process = function ( queue ) {
- var i, len, item, title, index,
- remove = 0;
+ var i, len, item, title, index, remove;
for ( i = 0, len = queue.length; i < len; i++ ) {
+ remove = 0;
item = queue[i];
+
if ( item.add instanceof ve.dm.MWTemplateModel ) {
title = item.add.getTitle();
if ( hasOwn.call( specCache, title ) &&
specCache[title] ) {
item.add.getSpec().extend( specCache[title] );
}
}
+
// Auto-remove if already existing
- index = ve.indexOf( item.add, this.parts );
- if ( index !== -1 ) {
- this.parts.splice( index, 1 );
- item.add.disconnect( this );
- this.emit( 'replace', item.add, null );
- }
+ this.removePart( item.add );
+
// Add at index, or end if none was given
- if ( item.index !== undefined ) {
- index = item.index;
- } else if ( item.remove ) {
+ index = item.index;
+ if ( index !== undefined && item.remove ) {
index = ve.indexOf( item.remove, this.parts );
if ( index !== -1 ) {
remove = 1;
@@ -136,6 +133,7 @@
item.remove.disconnect( this );
}
this.emit( 'replace', item.remove || null, item.add );
+
// Resolve promises
if ( item.deferred ) {
item.deferred.resolve();
--
To view, visit https://gerrit.wikimedia.org/r/108956
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie0a83d582804bc50131ca5a8da36b0605dd4a6c3
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits