Skip to content
This repository was archived by the owner on Sep 23, 2023. It is now read-only.

Commit a96f996

Browse files
edg2sMatmaRex
authored andcommitted
Prefer ES6 arrow functions to anonymous functions
1 parent 59d3d9c commit a96f996

File tree

3 files changed

+33
-38
lines changed

3 files changed

+33
-38
lines changed

js/PatchSelectWidget.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
}() );
1414

1515
window.PatchSelectWidget = function PatchSelectWidget( config ) {
16-
const widget = this;
17-
1816
this.$formInput = $( '<input>' ).attr( {
1917
type: 'hidden',
2018
name: config.name
@@ -29,8 +27,8 @@ window.PatchSelectWidget = function PatchSelectWidget( config ) {
2927

3028
// Assume that a whole patch number was pasted
3129
// TODO: Upstream?
32-
this.input.$input.on( 'paste', function () {
33-
setTimeout( widget.doInputEnter.bind( widget ) );
30+
this.input.$input.on( 'paste', () => {
31+
setTimeout( this.doInputEnter.bind( this ) );
3432
} );
3533

3634
this.$element
@@ -60,15 +58,14 @@ window.PatchSelectWidget.prototype.getTagInfoFromInput = function ( value ) {
6058
};
6159

6260
window.PatchSelectWidget.prototype.addTagFromInput = function () {
63-
const widget = this;
6461
// Handle multi line inputs, e.g. from paste
6562
// TODO: Upstream?
6663
const tagInfos = this.input.getValue().trim().split( /[ \n]/ )
6764
.map( this.getTagInfoFromInput.bind( this ) );
6865

69-
tagInfos.forEach( function ( tagInfo ) {
70-
if ( tagInfo && widget.addTag( tagInfo.data, tagInfo.label ) ) {
71-
widget.clearInput();
66+
tagInfos.forEach( ( tagInfo ) => {
67+
if ( tagInfo && this.addTag( tagInfo.data, tagInfo.label ) ) {
68+
this.clearInput();
7269
}
7370
} );
7471
};
@@ -93,8 +90,7 @@ window.PatchSelectWidget.prototype.onInputKeyPress = function ( e ) {
9390
};
9491

9592
window.PatchSelectWidget.prototype.createTagItemWidget = function () {
96-
const widget = this,
97-
patchCache = this.constructor.static.patchCache,
93+
const patchCache = this.constructor.static.patchCache,
9894
// eslint-disable-next-line max-len
9995
item = window.PatchSelectWidget.super.prototype.createTagItemWidget.apply( this, arguments ),
10096
patch = item.getData().trim();
@@ -111,7 +107,7 @@ window.PatchSelectWidget.prototype.createTagItemWidget = function () {
111107
$.get( 'api.php', { action: 'patchmeta', patch: patch } ) :
112108
$.Deferred().reject( 'Invalid patch number' ).promise()
113109
);
114-
patchCache[ patch ].then( function ( response ) {
110+
patchCache[ patch ].then( ( response ) => {
115111
const data = { input: patch };
116112
if ( !response.length ) {
117113
return $.Deferred().reject( 'Could not find patch' ).promise();
@@ -141,12 +137,12 @@ window.PatchSelectWidget.prototype.createTagItemWidget = function () {
141137
)
142138
);
143139
// Update input after ID normalization
144-
widget.onChangeTags();
145-
widget.updateInputSize();
146-
} ).then( null, function ( err ) {
140+
this.onChangeTags();
141+
this.updateInputSize();
142+
} ).then( null, ( err ) => {
147143
item.setLabel( item.getData().input + ': ' + err );
148144
item.toggleValid( false );
149-
widget.updateInputSize();
145+
this.updateInputSize();
150146
} );
151147

152148
return item;
@@ -157,7 +153,7 @@ window.PatchSelectWidget.prototype.onChangeTags = function () {
157153

158154
this.$formInput.val(
159155
// Join items with a pipe as the hidden input is single line
160-
this.items.map( function ( item ) {
156+
this.items.map( ( item ) => {
161157
const data = item.getData();
162158
return data.r ?
163159
// 'latest' means the user didn't specify a patchset, and so wants the latest one.
@@ -167,18 +163,18 @@ window.PatchSelectWidget.prototype.onChangeTags = function () {
167163
);
168164

169165
const linkedTasks = {};
170-
this.items.forEach( function ( item ) {
166+
this.items.forEach( ( item ) => {
171167
const data = item.getData();
172168
if ( data.linkedTasks ) {
173-
data.linkedTasks.forEach( function ( task ) {
169+
data.linkedTasks.forEach( ( task ) => {
174170
linkedTasks[ task ] = true;
175171
} );
176172
}
177173
} );
178174

179175
this.emit( 'linkedTasks', Object.keys( linkedTasks ) );
180176

181-
const patchKey = this.items.map( function ( item ) {
177+
const patchKey = this.items.map( ( item ) => {
182178
const data = item.getData();
183179
return data.r + ',' + data.p;
184180
} ).sort().join( '|' );

js/index.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
const patchesInput = OO.ui.infuse( $( '.form-patches' ) );
1010
const patchesLayout = OO.ui.infuse( $( '.form-patches-layout' ) );
1111

12-
form.addEventListener( 'submit', function ( e ) {
12+
form.addEventListener( 'submit', ( e ) => {
1313
// Blur is not fired on patchesInput, so call manually
1414
patchesInput.doInputEnter();
1515

1616
if ( !patchesInput.getValue().length ) {
1717
OO.ui.confirm(
1818
'Are you sure you want to create a demo with no patches applied?'
19-
).then( function ( confirmed ) {
19+
).then( ( confirmed ) => {
2020
if ( confirmed ) {
2121
form.submit();
2222
}
@@ -29,9 +29,9 @@
2929
return false;
3030
} );
3131

32-
patchesInput.on( 'matchWikis', function ( wikis ) {
32+
patchesInput.on( 'matchWikis', ( wikis ) => {
3333
patchesLayout.setWarnings(
34-
( wikis || [] ).map( function ( wiki ) {
34+
( wikis || [] ).map( ( wiki ) => {
3535
wiki = wiki.slice( 0, 10 );
3636
return $( '<span>' ).append(
3737
document.createTextNode( 'A wiki with these patches already exists: ' ),
@@ -48,13 +48,12 @@
4848
const taskLabel = new OO.ui.LabelWidget( { classes: [ 'form-announce-taskList' ] } );
4949
announceLayout.$field.append( taskLabel.$element );
5050

51-
// eslint-disable-next-line no-inner-declarations
52-
function updateLinkedTasks( linkedTasks ) {
51+
const updateLinkedTasks = ( linkedTasks ) => {
5352
let $label = $( [] );
5453
if ( !linkedTasks.length ) {
5554
$label = $( '<em>' ).text( 'No linked tasks found.' );
5655
} else {
57-
linkedTasks.forEach( function ( task ) {
56+
linkedTasks.forEach( ( task ) => {
5857
const id = 'T' + task;
5958
if ( $label.length ) {
6059
$label = $label.add( document.createTextNode( ', ' ) );
@@ -70,7 +69,7 @@
7069
} );
7170
}
7271
taskLabel.setLabel( $label );
73-
}
72+
};
7473

7574
patchesInput.on( 'linkedTasks', updateLinkedTasks );
7675
updateLinkedTasks( [] );
@@ -89,7 +88,7 @@
8988

9089
if ( $( '.showClosedButton' ).length ) {
9190
const showClosedButton = OO.ui.infuse( $( '.showClosedButton' ) );
92-
showClosedButton.on( 'click', function () {
91+
showClosedButton.on( 'click', () => {
9392
closedWikis.setSelected( true );
9493
updateTableClasses();
9594
} );
@@ -101,7 +100,7 @@
101100
const reposField = OO.ui.infuse( $( '.form-repos-field' ) );
102101
const branchSelect = OO.ui.infuse( $( '.form-branch' ) );
103102

104-
branchSelect.on( 'change', function () {
103+
branchSelect.on( 'change', () => {
105104
const branch = branchSelect.value;
106105
for ( const repo in window.repoBranches ) {
107106
const validBranch = window.repoBranches[ repo ].indexOf( branch ) !== -1;
@@ -114,7 +113,7 @@
114113

115114
const reposFieldLabel = reposField.getLabel();
116115

117-
presetInput.on( 'change', OO.ui.debounce( function () {
116+
presetInput.on( 'change', OO.ui.debounce( () => {
118117
const val = presetInput.getValue();
119118
if ( val === 'custom' ) {
120119
reposField.$body[ 0 ].open = true;
@@ -123,7 +122,7 @@
123122
reposInput.setValue( window.presets[ val ] );
124123
}
125124
} ) );
126-
reposInput.on( 'change', OO.ui.debounce( function () {
125+
reposInput.on( 'change', OO.ui.debounce( () => {
127126
const val = reposInput.getValue();
128127
let matchingPresetName = 'custom';
129128
for ( const presetName in window.presets ) {
@@ -137,7 +136,7 @@
137136
}
138137

139138
let selected = 0, enabled = 0;
140-
reposInput.checkboxMultiselectWidget.items.forEach( function ( option ) {
139+
reposInput.checkboxMultiselectWidget.items.forEach( ( option ) => {
141140
if ( !option.isDisabled() ) {
142141
enabled++;
143142
if ( option.isSelected() ) {
@@ -154,14 +153,14 @@
154153
const instantCommonsCheckbox = OO.ui.infuse( $( '.form-instantCommons' ) );
155154
const instantCommonsMethodDropdown = OO.ui.infuse( $( '.form-instantCommonsMethod' ) );
156155

157-
instantCommonsCheckbox.on( 'change', function ( value ) {
156+
instantCommonsCheckbox.on( 'change', ( value ) => {
158157
instantCommonsMethodDropdown.setDisabled( !value );
159158
} );
160159

161160
const languageInput = OO.ui.infuse( $( '.form-language' ) );
162161
languageInput.setValidation( /^[a-z-]{2,}$/ );
163162

164-
$( '.copyWiki' ).on( 'click', function ( e ) {
163+
$( '.copyWiki' ).on( 'click', ( e ) => {
165164
const params = new URL( this.href ).searchParams;
166165
patchesInput.setValue( params.get( 'patches' ) ? params.get( 'patches' ).split( ',' ) : [] );
167166
branchSelect.setValue( 'origin/' + params.get( 'branch' ) );
@@ -180,7 +179,7 @@
180179
icon: 'bellOutline'
181180
} );
182181

183-
const onRequestPermission = function ( permission ) {
182+
const onRequestPermission = ( permission ) => {
184183
notifToggle.setValue( permission === 'granted' );
185184
if ( permission === 'granted' ) {
186185
notifField.setLabel( 'You will get a browser notification when your wiki is ready' );
@@ -190,7 +189,7 @@
190189
}
191190
};
192191

193-
const onNotifChange = function ( value ) {
192+
const onNotifChange = ( value ) => {
194193
if ( !value ) {
195194
localStorage.setItem( 'patchdemo-notifications', '0' );
196195
notifField.setLabel( notifFieldLabel );
@@ -210,7 +209,7 @@
210209
}
211210

212211
let $lastMatch = $( [] );
213-
$( window ).on( 'hashchange', function () {
212+
$( window ).on( 'hashchange', () => {
214213
if ( location.hash.match( /^#[0-9a-f]{10}$/ ) ) {
215214
$lastMatch.removeClass( 'highlight' );
216215
$lastMatch = $( location.hash ).closest( 'tr' );

js/new.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
document.getElementsByClassName( 'openWiki' )[ 0 ]
1212
);
1313

14-
pd.notify = function ( message, body ) {
14+
pd.notify = ( message, body ) => {
1515
if ( 'Notification' in window && +localStorage.getItem( 'patchdemo-notifications' ) ) {
1616
// eslint-disable-next-line no-new
1717
new Notification(

0 commit comments

Comments
 (0)