Commit 37d3f4bb authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview: Add a type for all CustomEvent parameters

Add type for all CustomEvent parameters and remove unnecessary type
casts.

Bug: 924733
Change-Id: I3b521ab2ca575aa3caf59921d06a2af75361c2fd
Reviewed-on: https://chromium-review.googlesource.com/c/1456695
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629892}
parent ced7c61a
......@@ -21,6 +21,16 @@ cloudprint.CloudPrintInterfaceEventType = {
UPDATE_USERS: 'cloudprint.CloudPrintInterface.UPDATE_USERS',
};
/**
* @typedef {{
* status: number,
* errorCode: number,
* message: string,
* origin: !print_preview.DestinationOrigin,
* }}
*/
cloudprint.CloudPrintInterfaceErrorEventDetail;
/**
* @typedef {{
* user: string,
......
......@@ -288,10 +288,7 @@ cr.define('cloudprint', function() {
* request.
* @param {!cloudprint.CloudPrintRequest} request Request that has been
* completed.
* @return {!{ status: number,
* errorCode: number,
* message: string,
* origin: !print_preview.DestinationOrigin }} Information
* @return {!cloudprint.CloudPrintInterfaceErrorEventDetail} Information
* about the error.
* @private
*/
......
......@@ -1255,13 +1255,12 @@ cr.define('print_preview', function() {
/**
* Called when the /search call completes, either successfully or not.
* In case of success, stores fetched destinations.
* @param {!CustomEvent} event Contains the request result.
* @param {!CustomEvent<!cloudprint.CloudPrintInterfaceSearchDoneDetail>}
* event Contains the request result.
* @private
*/
onCloudPrintSearchDone_(event) {
const payload =
/** @type {!cloudprint.CloudPrintInterfaceSearchDoneDetail} */ (
event.detail);
const payload = event.detail;
if (payload.printers && payload.printers.length > 0) {
this.insertDestinations_(payload.printers);
if (this.selectFirstDestination_) {
......@@ -1344,8 +1343,9 @@ cr.define('print_preview', function() {
/**
* Called when printer sharing invitation was processed successfully.
* @param {!CustomEvent} event Contains detailed information about the
* invite and newly accepted destination (if known).
* @param {!CustomEvent<!cloudprint.CloudPrintInterfaceProcessInviteDetail>}
* event Contains detailed information about the invite and newly
* accepted destination (if known).
* @private
*/
onCloudPrintProcessInviteDone_(event) {
......
......@@ -149,16 +149,14 @@ cr.define('print_preview', function() {
/**
* Called when printer sharing invitations are fetched.
* @param {!CustomEvent} event Contains the list of invitations.
* @param {!CustomEvent<!cloudprint.CloudPrintInterfaceInvitesDoneDetail>}
* event Contains the list of invitations.
* @private
*/
onCloudPrintInvitesDone_(event) {
const invitesDoneDetail =
/** @type {!cloudprint.CloudPrintInterfaceInvitesDoneDetail} */ (
event.detail);
this.loadStatus_[invitesDoneDetail.user] =
this.loadStatus_[event.detail.user] =
print_preview.InvitationStoreLoadStatus.DONE;
this.invitations_[invitesDoneDetail.user] = invitesDoneDetail.invitations;
this.invitations_[event.detail.user] = event.detail.invitations;
this.dispatchEvent(
new CustomEvent(InvitationStore.EventType.INVITATION_SEARCH_DONE));
......@@ -166,25 +164,23 @@ cr.define('print_preview', function() {
/**
* Called when printer sharing invitations fetch has failed.
* @param {!CustomEvent} event
* @param {!CustomEvent<string>} event Contains the user for whom invite
* fetch failed.
* @private
*/
onCloudPrintInvitesFailed_(event) {
this.loadStatus_[/** @type {string} */ (event.detail)] =
this.loadStatus_[event.detail] =
print_preview.InvitationStoreLoadStatus.FAILED;
}
/**
* Called when printer sharing invitation was processed successfully.
* @param {!CustomEvent} event Contains detailed information about the
* invite.
* @param {!CustomEvent<!cloudprint.CloudPrintInterfaceProcessInviteDetail>}
* event Contains detailed information about the invite.
* @private
*/
onCloudPrintProcessInviteDone_(event) {
this.invitationProcessed_(
/** @type {!cloudprint.CloudPrintInterfaceProcessInviteDetail} */ (
event.detail)
.invitation);
this.invitationProcessed_(event.detail.invitation);
this.dispatchEvent(
new CustomEvent(InvitationStore.EventType.INVITATION_PROCESSED));
}
......
......@@ -613,7 +613,8 @@ Polymer({
/**
* Updates the cloud print status to NOT_SIGNED_IN if there is an
* authentication error.
* @param {!CustomEvent<{status: number}>} event Contains the error status
* @param {!CustomEvent<!cloudprint.CloudPrintInterfaceErrorEventDetail>}
* event Contains the error status
* @private
*/
checkCloudPrintStatus_: function(event) {
......@@ -631,7 +632,8 @@ Polymer({
/**
* Called when there was an error communicating with Google Cloud print.
* Displays an error message in the print header.
* @param {!CustomEvent} event Contains the error message.
* @param {!CustomEvent<!cloudprint.CloudPrintInterfaceErrorEventDetail>}
* event Contains the error message.
* @private
*/
onCloudPrintError_: function(event) {
......
......@@ -140,7 +140,7 @@ Polymer({
},
/**
* @param {!CustomEvent} e Contains the new value of the input.
* @param {!CustomEvent<string>} e Contains the new value of the input.
* @private
*/
onInputChange_: function(e) {
......
......@@ -336,8 +336,7 @@ Polymer({
},
/**
* @param {!CustomEvent} e Contains information about what control fired the
* event.
* @param {!Event} e Contains information about what control fired the event.
* @private
*/
onTextFocus_: function(e) {
......@@ -454,8 +453,9 @@ Polymer({
},
/**
* @param {!CustomEvent} e Event fired when a control's text field is blurred.
* Contains information about whether the control is in an invalid state.
* @param {!CustomEvent<boolean>} e Event fired when a control's text field
* is blurred. Contains information about whether the control is in an
* invalid state.
* @private
*/
onTextBlur_: function(e) {
......
......@@ -39,12 +39,14 @@ Polymer({
},
/**
* @param {!CustomEvent} e Event containing the new search.
* @param {!CustomEvent<string>} e Event containing the new search.
* @private
*/
onSearchChanged_: function(e) {
let safeQuery = e.detail.trim().replace(SANITIZE_REGEX, '\\$&');
safeQuery = safeQuery.length > 0 ? new RegExp(`(${safeQuery})`, 'i') : null;
const safeQueryString = e.detail.trim().replace(SANITIZE_REGEX, '\\$&');
const safeQuery = safeQueryString.length > 0 ?
new RegExp(`(${safeQueryString})`, 'i') :
null;
if (this.timeout_) {
clearTimeout(this.timeout_);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment