Replace all usage of `bind()` with arrow functions
This left all test files untouched.
Change-Id: I677383d51adb5bf8ca7fd5f18f16c34eca8b3498
diff --git a/polygerrit-ui/app/elements/admin/gr-admin-view/gr-admin-view.js b/polygerrit-ui/app/elements/admin/gr-admin-view/gr-admin-view.js
index 9affc1b..d861681 100644
--- a/polygerrit-ui/app/elements/admin/gr-admin-view/gr-admin-view.js
+++ b/polygerrit-ui/app/elements/admin/gr-admin-view/gr-admin-view.js
@@ -130,8 +130,8 @@
}
return getAdminLinks(this._account,
- this.$.restAPI.getAccountCapabilities.bind(this.$.restAPI),
- this.$.jsAPI.getAdminMenuLinks.bind(this.$.jsAPI),
+ params => this.$.restAPI.getAccountCapabilities(params),
+ () => this.$.jsAPI.getAdminMenuLinks(),
options)
.then(res => {
this._filteredLinks = res.links;
diff --git a/polygerrit-ui/app/elements/admin/gr-create-change-dialog/gr-create-change-dialog.ts b/polygerrit-ui/app/elements/admin/gr-create-change-dialog/gr-create-change-dialog.ts
index 66f7586..ba22eff 100644
--- a/polygerrit-ui/app/elements/admin/gr-create-change-dialog/gr-create-change-dialog.ts
+++ b/polygerrit-ui/app/elements/admin/gr-create-change-dialog/gr-create-change-dialog.ts
@@ -90,7 +90,7 @@
constructor() {
super();
- this._query = this._getRepoBranchesSuggestions.bind(this);
+ this._query = (input: string) => this._getRepoBranchesSuggestions(input);
}
/** @override */
diff --git a/polygerrit-ui/app/elements/admin/gr-group-members/gr-group-members.js b/polygerrit-ui/app/elements/admin/gr-group-members/gr-group-members.js
index dff279e..0fb57d3 100644
--- a/polygerrit-ui/app/elements/admin/gr-group-members/gr-group-members.js
+++ b/polygerrit-ui/app/elements/admin/gr-group-members/gr-group-members.js
@@ -66,13 +66,13 @@
_queryMembers: {
type: Function,
value() {
- return this._getAccountSuggestions.bind(this);
+ return input => this._getAccountSuggestions(input);
},
},
_queryIncludedGroup: {
type: Function,
value() {
- return this._getGroupSuggestions.bind(this);
+ return input => this._getGroupSuggestions(input);
},
},
_groupOwner: {
diff --git a/polygerrit-ui/app/elements/change-list/gr-dashboard-view/gr-dashboard-view.js b/polygerrit-ui/app/elements/change-list/gr-dashboard-view/gr-dashboard-view.js
index dbfb6be..0658e16 100644
--- a/polygerrit-ui/app/elements/change-list/gr-dashboard-view/gr-dashboard-view.js
+++ b/polygerrit-ui/app/elements/change-list/gr-dashboard-view/gr-dashboard-view.js
@@ -66,7 +66,7 @@
createChangeTap: {
type: Function,
value() {
- return this._createChangeTap.bind(this);
+ return e => this._createChangeTap(e);
},
},
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js
index 0285f26..fba4b53 100644
--- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js
+++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js
@@ -1295,10 +1295,10 @@
if (this._getActionOverflowIndex(type, buttonKey) !== -1) {
this.push('_disabledMenuActions', buttonKey === '/' ? 'delete' :
buttonKey);
- return function() {
+ return () => {
this._actionLoadingMessage = '';
this._disabledMenuActions = [];
- }.bind(this);
+ };
}
// Otherwise it's a top-level action.
@@ -1306,11 +1306,11 @@
.querySelector(`[data-action-key="${buttonKey}"]`);
buttonEl.setAttribute('loading', true);
buttonEl.disabled = true;
- return function() {
+ return () => {
this._actionLoadingMessage = '';
buttonEl.removeAttribute('loading');
buttonEl.disabled = false;
- }.bind(this);
+ };
}
/**
@@ -1324,7 +1324,7 @@
this._setLoadingOnButtonWithKey(action.__type, action.__key);
this._send(action.method, opt_payload, endpoint, revAction, cleanupFn,
- action).then(this._handleResponse.bind(this, action));
+ action).then(res => this._handleResponse(action, res));
}
_showActionDialog(dialog) {
@@ -1570,7 +1570,7 @@
return revisionActionValues
.concat(changeActionValues)
- .sort(this._actionComparator.bind(this))
+ .sort((a, b) => this._actionComparator(a, b))
.map(action => {
if (ACTIONS_WITH_ICONS.has(action.__key)) {
action.icon = action.__key;
diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js
index 2174791..2504419 100644
--- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js
+++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js
@@ -512,20 +512,20 @@
})
.then(() => this._initActiveTabs(this.params));
- this.addEventListener('comment-save', this._handleCommentSave.bind(this));
- this.addEventListener('comment-refresh', this._reloadDrafts.bind(this));
+ this.addEventListener('comment-save', e => this._handleCommentSave(e));
+ this.addEventListener('comment-refresh', e => this._reloadDrafts(e));
this.addEventListener('comment-discard',
- this._handleCommentDiscard.bind(this));
+ e => this._handleCommentDiscard(e));
this.addEventListener('change-message-deleted',
() => this._reload());
this.addEventListener('editable-content-save',
- this._handleCommitMessageSave.bind(this));
+ e => this._handleCommitMessageSave(e));
this.addEventListener('editable-content-cancel',
- this._handleCommitMessageCancel.bind(this));
+ e => this._handleCommitMessageCancel(e));
this.addEventListener('open-fix-preview',
- this._onOpenFixPreview.bind(this));
+ e => this._onOpenFixPreview(e));
this.addEventListener('close-fix-preview',
- this._onCloseFixPreview.bind(this));
+ e => this._onCloseFixPreview(e));
this.listen(window, 'scroll', '_handleScroll');
this.listen(document, 'visibilitychange', '_handleVisibilityChange');
@@ -1183,7 +1183,7 @@
_maybeShowRevertDialog() {
getPluginLoader().awaitPluginsLoaded()
- .then(this._getLoggedIn.bind(this))
+ .then(() => this._getLoggedIn())
.then(loggedIn => {
if (!loggedIn || !this._change ||
this._change.status !== ChangeStatus.MERGED) {
@@ -1663,7 +1663,7 @@
_getChangeDetail() {
const detailCompletes = this.$.restAPI.getChangeDetail(
- this._changeNum, this._handleGetChangeDetailError.bind(this));
+ this._changeNum, r => this._handleGetChangeDetailError(r));
const editCompletes = this._getEdit();
const prefCompletes = this._getPreferences();
diff --git a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.js b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.js
index d7a41f1..6ecdabb 100644
--- a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.js
+++ b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.js
@@ -616,7 +616,7 @@
this.disabled = true;
- const errFn = this._handle400Error.bind(this);
+ const errFn = r => this._handle400Error(r);
return this._saveReview(reviewInput, errFn)
.then(response => {
if (!response) {
diff --git a/polygerrit-ui/app/elements/core/gr-error-manager/gr-error-manager.ts b/polygerrit-ui/app/elements/core/gr-error-manager/gr-error-manager.ts
index 11996c1..162caa4 100644
--- a/polygerrit-ui/app/elements/core/gr-error-manager/gr-error-manager.ts
+++ b/polygerrit-ui/app/elements/core/gr-error-manager/gr-error-manager.ts
@@ -365,10 +365,8 @@
this._alertElement = this._createToastAlert();
this._alertElement.type = ErrorType.AUTH;
- this._alertElement.show(
- errorText,
- actionText,
- this._createLoginPopup.bind(this)
+ this._alertElement.show(errorText, actionText, () =>
+ this._createLoginPopup()
);
this.fire('iron-announce', {text: errorText}, {bubbles: true});
this._refreshingCredentials = true;
diff --git a/polygerrit-ui/app/elements/core/gr-keyboard-shortcuts-dialog/gr-keyboard-shortcuts-dialog.ts b/polygerrit-ui/app/elements/core/gr-keyboard-shortcuts-dialog/gr-keyboard-shortcuts-dialog.ts
index 33e720b..4bd90ea 100644
--- a/polygerrit-ui/app/elements/core/gr-keyboard-shortcuts-dialog/gr-keyboard-shortcuts-dialog.ts
+++ b/polygerrit-ui/app/elements/core/gr-keyboard-shortcuts-dialog/gr-keyboard-shortcuts-dialog.ts
@@ -64,9 +64,9 @@
constructor() {
super();
- this.keyboardShortcutDirectoryListener = this._onDirectoryUpdated.bind(
- this
- );
+ this.keyboardShortcutDirectoryListener = (
+ d?: Map<ShortcutSection, SectionView>
+ ) => this._onDirectoryUpdated(d);
}
/** @override */
diff --git a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js
index 03c7212..88c4cef 100644
--- a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js
+++ b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js
@@ -274,8 +274,8 @@
this._topMenus = result[1];
return getAdminLinks(account,
- this.$.restAPI.getAccountCapabilities.bind(this.$.restAPI),
- this.$.jsAPI.getAdminMenuLinks.bind(this.$.jsAPI))
+ params => this.$.restAPI.getAccountCapabilities(params),
+ () => this.$.jsAPI.getAdminMenuLinks())
.then(res => {
this._adminLinks = res.links;
});
diff --git a/polygerrit-ui/app/elements/core/gr-smart-search/gr-smart-search.js b/polygerrit-ui/app/elements/core/gr-smart-search/gr-smart-search.js
index 772b412..813298c 100644
--- a/polygerrit-ui/app/elements/core/gr-smart-search/gr-smart-search.js
+++ b/polygerrit-ui/app/elements/core/gr-smart-search/gr-smart-search.js
@@ -44,19 +44,22 @@
_projectSuggestions: {
type: Function,
value() {
- return this._fetchProjects.bind(this);
+ return (predicate, expression) =>
+ this._fetchProjects(predicate, expression);
},
},
_groupSuggestions: {
type: Function,
value() {
- return this._fetchGroups.bind(this);
+ return (predicate, expression) =>
+ this._fetchGroups(predicate, expression);
},
},
_accountSuggestions: {
type: Function,
value() {
- return this._fetchAccounts.bind(this);
+ return (predicate, expression) =>
+ this._fetchAccounts(predicate, expression);
},
},
/**
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.ts b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.ts
index 1be08ab..6412068 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.ts
+++ b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder.ts
@@ -109,7 +109,11 @@
throw Error('Invalid line length from preferences.');
}
- this._layerUpdateListener = this._handleLayerUpdate.bind(this);
+ this._layerUpdateListener = (
+ start: LineNumber,
+ end: LineNumber,
+ side: Side
+ ) => this._handleLayerUpdate(start, end, side);
for (const layer of this.layers) {
if (layer.addListener) {
layer.addListener(this._layerUpdateListener);
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.ts b/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.ts
index ebd410e..6f51793 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.ts
+++ b/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.ts
@@ -169,7 +169,7 @@
moveDown() {
if (this._getViewMode() === DiffViewMode.SIDE_BY_SIDE) {
- this.$.cursorManager.next(this._rowHasSide.bind(this));
+ this.$.cursorManager.next((row: Element) => this._rowHasSide(row));
} else {
this.$.cursorManager.next();
}
@@ -177,7 +177,7 @@
moveUp() {
if (this._getViewMode() === DiffViewMode.SIDE_BY_SIDE) {
- this.$.cursorManager.previous(this._rowHasSide.bind(this));
+ this.$.cursorManager.previous((row: Element) => this._rowHasSide(row));
} else {
this.$.cursorManager.previous();
}
@@ -185,7 +185,9 @@
moveToVisibleArea() {
if (this._getViewMode() === DiffViewMode.SIDE_BY_SIDE) {
- this.$.cursorManager.moveToVisibleArea(this._rowHasSide.bind(this));
+ this.$.cursorManager.moveToVisibleArea((row: Element) =>
+ this._rowHasSide(row)
+ );
} else {
this.$.cursorManager.moveToVisibleArea();
}
@@ -193,7 +195,7 @@
moveToNextChunk(clipToTop?: boolean, navigateToNextFile?: boolean) {
this.$.cursorManager.next(
- this._isFirstRowOfChunk.bind(this),
+ (row: HTMLElement) => this._isFirstRowOfChunk(row),
target => (target?.parentNode as HTMLElement)?.scrollHeight || 0,
clipToTop,
navigateToNextFile
@@ -202,17 +204,21 @@
}
moveToPreviousChunk() {
- this.$.cursorManager.previous(this._isFirstRowOfChunk.bind(this));
+ this.$.cursorManager.previous((row: HTMLElement) =>
+ this._isFirstRowOfChunk(row)
+ );
this._fixSide();
}
moveToNextCommentThread() {
- this.$.cursorManager.next(this._rowHasThread.bind(this));
+ this.$.cursorManager.next((row: HTMLElement) => this._rowHasThread(row));
this._fixSide();
}
moveToPreviousCommentThread() {
- this.$.cursorManager.previous(this._rowHasThread.bind(this));
+ this.$.cursorManager.previous((row: HTMLElement) =>
+ this._rowHasThread(row)
+ );
this._fixSide();
}
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
index 314c322..0b02245 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
@@ -312,7 +312,7 @@
});
this.addEventListener('open-fix-preview',
- this._onOpenFixPreview.bind(this));
+ e => this._onOpenFixPreview(e));
this.$.cursor.push('diffs', this.$.diffHost);
const onRender = () => {
diff --git a/polygerrit-ui/app/elements/shared/gr-account-list/gr-account-list.js b/polygerrit-ui/app/elements/shared/gr-account-list/gr-account-list.js
index 5f1f9b0..76899b3 100644
--- a/polygerrit-ui/app/elements/shared/gr-account-list/gr-account-list.js
+++ b/polygerrit-ui/app/elements/shared/gr-account-list/gr-account-list.js
@@ -103,7 +103,7 @@
_querySuggestions: {
type: Function,
value() {
- return this._getSuggestions.bind(this);
+ return input => this._getSuggestions(input);
},
},
diff --git a/polygerrit-ui/app/elements/shared/gr-alert/gr-alert.ts b/polygerrit-ui/app/elements/shared/gr-alert/gr-alert.ts
index 046218b..e5806f0 100644
--- a/polygerrit-ui/app/elements/shared/gr-alert/gr-alert.ts
+++ b/polygerrit-ui/app/elements/shared/gr-alert/gr-alert.ts
@@ -74,7 +74,7 @@
/** @override */
attached() {
super.attached();
- this._boundTransitionEndHandler = this._handleTransitionEnd.bind(this);
+ this._boundTransitionEndHandler = () => this._handleTransitionEnd();
this.addEventListener('transitionend', this._boundTransitionEndHandler);
}
diff --git a/polygerrit-ui/app/elements/shared/gr-lib-loader/gr-lib-loader.ts b/polygerrit-ui/app/elements/shared/gr-lib-loader/gr-lib-loader.ts
index b18439b..ad97d02 100644
--- a/polygerrit-ui/app/elements/shared/gr-lib-loader/gr-lib-loader.ts
+++ b/polygerrit-ui/app/elements/shared/gr-lib-loader/gr-lib-loader.ts
@@ -73,7 +73,7 @@
if (!this._hljsState.loading) {
this._hljsState.loading = true;
this._loadScript(this._getHLJSUrl())
- .then(this._onHLJSLibLoaded.bind(this))
+ .then(() => this._onHLJSLibLoaded())
.catch(reject);
}
diff --git a/polygerrit-ui/app/elements/shared/gr-linked-text/gr-linked-text.ts b/polygerrit-ui/app/elements/shared/gr-linked-text/gr-linked-text.ts
index 4df91e70..e2c2d7f 100644
--- a/polygerrit-ui/app/elements/shared/gr-linked-text/gr-linked-text.ts
+++ b/polygerrit-ui/app/elements/shared/gr-linked-text/gr-linked-text.ts
@@ -93,7 +93,8 @@
output.textContent = '';
const parser = new GrLinkTextParser(
config,
- this._handleParseResult.bind(this),
+ (text: string | null, href: string | null, fragment?: DocumentFragment) =>
+ this._handleParseResult(text, href, fragment),
this.removeZeroWidthSpace
);
parser.parse(content);
diff --git a/polygerrit-ui/app/elements/shared/gr-linked-text/link-text-parser.ts b/polygerrit-ui/app/elements/shared/gr-linked-text/link-text-parser.ts
index 451c627..9066911 100644
--- a/polygerrit-ui/app/elements/shared/gr-linked-text/link-text-parser.ts
+++ b/polygerrit-ui/app/elements/shared/gr-linked-text/link-text-parser.ts
@@ -289,7 +289,7 @@
parse(text?: string | null) {
if (text) {
window.linkify(text, {
- callback: this.parseChunk.bind(this),
+ callback: (text: string, href?: string) => this.parseChunk(text, href),
});
}
}
diff --git a/polygerrit-ui/app/services/gr-reporting/gr-reporting.ts b/polygerrit-ui/app/services/gr-reporting/gr-reporting.ts
index 76edae8..743e0f4 100644
--- a/polygerrit-ui/app/services/gr-reporting/gr-reporting.ts
+++ b/polygerrit-ui/app/services/gr-reporting/gr-reporting.ts
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-export type EventValue = string | number | {error: Error};
+export type EventValue = string | number | {error?: Error};
// TODO(dmfilippov): TS-fix-any use more specific type instead if possible
export type EventDetails = any;
diff --git a/polygerrit-ui/app/services/gr-reporting/gr-reporting_impl.ts b/polygerrit-ui/app/services/gr-reporting/gr-reporting_impl.ts
index 1cf4bea..d3b652a 100644
--- a/polygerrit-ui/app/services/gr-reporting/gr-reporting_impl.ts
+++ b/polygerrit-ui/app/services/gr-reporting/gr-reporting_impl.ts
@@ -117,11 +117,11 @@
// TODO(dmfilippo): TS-fix-any oldOnError - define correct type
const onError = function (
oldOnError: Function,
- msg: string,
- url: string,
- line: number,
- column: number,
- error: Error
+ msg: Event | string,
+ url?: string,
+ line?: number,
+ column?: number,
+ error?: Error
) {
if (oldOnError) {
oldOnError(msg, url, line, column, error);
@@ -147,7 +147,7 @@
reportingService.reporter(
ERROR.TYPE,
ERROR.CATEGORY.EXCEPTION,
- msg,
+ `${msg}`,
payload
);
return true;
@@ -155,7 +155,15 @@
// TODO(dmfilippov): TS-fix-any unclear what is context
const catchErrors = function (opt_context?: any) {
const context = opt_context || window;
- context.onerror = onError.bind(null, context.onerror);
+ context.onerror = (
+ event: Event | string,
+ source?: string,
+ lineno?: number,
+ colno?: number,
+ error?: Error
+ ) => {
+ return onError(context.onerror, event, source, lineno, colno, error);
+ };
context.addEventListener(
'unhandledrejection',
(e: PromiseRejectionEvent) => {