From c927748304280a86790b3e3d67e827c0028cbd84 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Mon, 16 Sep 2024 16:04:30 +0100 Subject: [PATCH] Remove unnecessary context variables Change-Id: I5e715dd77a81bd42570e87e9fae67f5687b78e12 --- .../ext.templateDataGenerator.data/Model.js | 7 ++- .../SourceHandler.js | 4 +- .../Dialog.js | 43 +++++++++---------- .../Target.js | 16 +++---- 4 files changed, 30 insertions(+), 40 deletions(-) diff --git a/modules/ext.templateDataGenerator.data/Model.js b/modules/ext.templateDataGenerator.data/Model.js index e78a3e3e..91b3f38a 100644 --- a/modules/ext.templateDataGenerator.data/Model.js +++ b/modules/ext.templateDataGenerator.data/Model.js @@ -312,15 +312,14 @@ Model.prototype.getMissingParams = function () { * @return {Object} Parameters added. -1 for failure. */ Model.prototype.importSourceCodeParameters = function () { - const model = this, - allParamNames = this.getAllParamNames(), + const allParamNames = this.getAllParamNames(), existingArray = [], importedArray = [], skippedArray = []; // Check existing params allParamNames.forEach( ( paramKey ) => { - if ( model.sourceCodeParameters.indexOf( paramKey ) !== -1 ) { + if ( this.sourceCodeParameters.indexOf( paramKey ) !== -1 ) { existingArray.push( paramKey ); } } ); @@ -328,7 +327,7 @@ Model.prototype.importSourceCodeParameters = function () { // Add sourceCodeParameters to the model this.sourceCodeParameters.forEach( ( sourceCodeParameter ) => { if ( existingArray.indexOf( sourceCodeParameter ) === -1 ) { - model.addParam( sourceCodeParameter ); + this.addParam( sourceCodeParameter ); importedArray.push( sourceCodeParameter ); } else { skippedArray.push( sourceCodeParameter ); diff --git a/modules/ext.templateDataGenerator.data/SourceHandler.js b/modules/ext.templateDataGenerator.data/SourceHandler.js index 98922e38..8e679982 100644 --- a/modules/ext.templateDataGenerator.data/SourceHandler.js +++ b/modules/ext.templateDataGenerator.data/SourceHandler.js @@ -114,8 +114,6 @@ SourceHandler.prototype.buildModel = function ( wikitext ) { * @return {jQuery.Promise} Promise resolving into template parameter array */ SourceHandler.prototype.getParametersFromTemplateSource = function ( wikitext ) { - const sourceHandler = this; - let params = []; if ( !this.templateSourceCodePromise ) { // Check given page text first @@ -141,7 +139,7 @@ SourceHandler.prototype.getParametersFromTemplateSource = function ( wikitext ) ) { pageContent = resp.query.pages[ resp.query.pageids[ 0 ] ].revisions[ 0 ][ '*' ]; } - return sourceHandler.extractParametersFromTemplateCode( pageContent ); + return this.extractParametersFromTemplateCode( pageContent ); }, // Resolve an empty parameters array () => $.Deferred().resolve( [] ) diff --git a/modules/ext.templateDataGenerator.editTemplatePage/Dialog.js b/modules/ext.templateDataGenerator.editTemplatePage/Dialog.js index 613f876e..8c7cfdb9 100644 --- a/modules/ext.templateDataGenerator.editTemplatePage/Dialog.js +++ b/modules/ext.templateDataGenerator.editTemplatePage/Dialog.js @@ -1337,7 +1337,7 @@ Dialog.prototype.importParametersFromTemplateCode = function () { */ Dialog.prototype.getSetupProcess = function ( data ) { return Dialog.super.prototype.getSetupProcess.call( this, data ) - .next( function () { + .next( () => { this.isSetup = false; this.reset(); @@ -1397,7 +1397,7 @@ Dialog.prototype.getSetupProcess = function ( data ) { this.panels.$element.show(); this.actions.setAbilities( { apply: false } ); - }, this ); + } ); }; /** @@ -1494,64 +1494,63 @@ Dialog.prototype.switchPanels = function ( panel ) { */ Dialog.prototype.getActionProcess = function ( action ) { if ( action === 'add' ) { - return new OO.ui.Process( function () { + return new OO.ui.Process( () => { this.switchPanels( this.addParamPanel ); - }, this ); + } ); } if ( action === 'done' ) { - return new OO.ui.Process( function () { + return new OO.ui.Process( () => { // setMapInfo with the value and keep the done button active this.model.setMapInfo( this.mapsCache ); this.model.originalMaps = OO.copy( this.mapsCache ); this.switchPanels(); - }, this ); + } ); } if ( action === 'back' ) { - return new OO.ui.Process( function () { + return new OO.ui.Process( () => { this.switchPanels(); - }, this ); + } ); } if ( action === 'maps' ) { - return new OO.ui.Process( function () { + return new OO.ui.Process( () => { this.switchPanels( this.editMapsPanel ); - }, this ); + } ); } if ( action === 'cancel' ) { - return new OO.ui.Process( function () { + return new OO.ui.Process( () => { this.mapsCache = OO.copy( this.model.getOriginalMapsInfo() ); this.model.restoreOriginalMaps(); this.populateMapsItems( this.mapsCache ); this.onCancelAddingMap(); this.switchPanels(); - }, this ); + } ); } if ( action === 'delete' ) { - return new OO.ui.Process( function () { + return new OO.ui.Process( () => { this.model.deleteParam( this.selectedParamKey ); this.switchPanels(); - }, this ); + } ); } if ( action === 'apply' ) { - return new OO.ui.Process( function () { + return new OO.ui.Process( () => { Metrics.logEvent( this.model.getOriginalTemplateDataObject() ? 'save-page-edit' : 'save-page-create' ); this.emit( 'apply', this.model.outputTemplateData() ); this.close( { action: action } ); - }, this ); + } ); } if ( !action && this.modified ) { - return new OO.ui.Process( function () { - const dialog = this; - return OO.ui.confirm( mw.msg( 'templatedata-modal-confirmcancel' ) ) + return new OO.ui.Process( + () => OO.ui.confirm( mw.msg( 'templatedata-modal-confirmcancel' ) ) .then( ( result ) => { if ( result ) { - dialog.close(); + this.close(); } else { return $.Deferred().resolve().promise(); } - } ); - }, this ); + } ) + ); } // Fallback to parent handler return Dialog.super.prototype.getActionProcess.call( this, action ); diff --git a/modules/ext.templateDataGenerator.editTemplatePage/Target.js b/modules/ext.templateDataGenerator.editTemplatePage/Target.js index 5fba71ff..a1c8e9e1 100644 --- a/modules/ext.templateDataGenerator.editTemplatePage/Target.js +++ b/modules/ext.templateDataGenerator.editTemplatePage/Target.js @@ -15,8 +15,6 @@ const Dialog = require( './Dialog.js' ), * @param {Object} config */ function Target( $textarea, config ) { - const target = this; - // Parent constructor Target.super.call( this, config ); @@ -86,7 +84,7 @@ function Target( $textarea, config ) { mw.message( 'templatedata-string-exists-hack-message' ).parse() ); - target.setEditNoticeMessage( msg, 'warning' ); + this.setEditNoticeMessage( msg, 'warning' ); } } } ); @@ -154,8 +152,6 @@ Target.prototype.openEditDialog = function ( dataModel ) { * @method onEditOpenDialogButton */ Target.prototype.onEditOpenDialogButton = function () { - const target = this; - this.originalWikitext = this.$textarea.textSelection( 'getContents' ); // Build the model @@ -163,7 +159,7 @@ Target.prototype.onEditOpenDialogButton = function () { .then( // Success ( model ) => { - target.openEditDialog( model ); + this.openEditDialog( model ); }, // Failure () => { @@ -189,9 +185,9 @@ Target.prototype.onEditOpenDialogButton = function () { // Open the dialog with an empty model const model = Model.static.newFromObject( null, - target.sourceHandler.getTemplateSourceCodeParams() + this.sourceHandler.getTemplateSourceCodeParams() ); - target.openEditDialog( model ); + this.openEditDialog( model ); } } ); } @@ -246,8 +242,6 @@ Target.prototype.replaceTemplateData = function ( newTemplateData ) { * @param {Object} templateData New templatedata */ Target.prototype.onDialogApply = function ( templateData ) { - const target = this; - if ( Object.keys( templateData ).length > 1 || Object.keys( templateData.params ).length > 0 @@ -270,7 +264,7 @@ Target.prototype.onDialogApply = function ( templateData ) { ] } ).closed.then( ( data ) => { if ( data && data.action === 'apply' ) { - target.replaceTemplateData( templateData ); + this.replaceTemplateData( templateData ); } } ); }