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 = { ...@@ -21,6 +21,16 @@ cloudprint.CloudPrintInterfaceEventType = {
UPDATE_USERS: 'cloudprint.CloudPrintInterface.UPDATE_USERS', UPDATE_USERS: 'cloudprint.CloudPrintInterface.UPDATE_USERS',
}; };
/**
* @typedef {{
* status: number,
* errorCode: number,
* message: string,
* origin: !print_preview.DestinationOrigin,
* }}
*/
cloudprint.CloudPrintInterfaceErrorEventDetail;
/** /**
* @typedef {{ * @typedef {{
* user: string, * user: string,
......
...@@ -288,10 +288,7 @@ cr.define('cloudprint', function() { ...@@ -288,10 +288,7 @@ cr.define('cloudprint', function() {
* request. * request.
* @param {!cloudprint.CloudPrintRequest} request Request that has been * @param {!cloudprint.CloudPrintRequest} request Request that has been
* completed. * completed.
* @return {!{ status: number, * @return {!cloudprint.CloudPrintInterfaceErrorEventDetail} Information
* errorCode: number,
* message: string,
* origin: !print_preview.DestinationOrigin }} Information
* about the error. * about the error.
* @private * @private
*/ */
......
...@@ -1255,13 +1255,12 @@ cr.define('print_preview', function() { ...@@ -1255,13 +1255,12 @@ cr.define('print_preview', function() {
/** /**
* Called when the /search call completes, either successfully or not. * Called when the /search call completes, either successfully or not.
* In case of success, stores fetched destinations. * In case of success, stores fetched destinations.
* @param {!CustomEvent} event Contains the request result. * @param {!CustomEvent<!cloudprint.CloudPrintInterfaceSearchDoneDetail>}
* event Contains the request result.
* @private * @private
*/ */
onCloudPrintSearchDone_(event) { onCloudPrintSearchDone_(event) {
const payload = const payload = event.detail;
/** @type {!cloudprint.CloudPrintInterfaceSearchDoneDetail} */ (
event.detail);
if (payload.printers && payload.printers.length > 0) { if (payload.printers && payload.printers.length > 0) {
this.insertDestinations_(payload.printers); this.insertDestinations_(payload.printers);
if (this.selectFirstDestination_) { if (this.selectFirstDestination_) {
...@@ -1344,8 +1343,9 @@ cr.define('print_preview', function() { ...@@ -1344,8 +1343,9 @@ cr.define('print_preview', function() {
/** /**
* Called when printer sharing invitation was processed successfully. * Called when printer sharing invitation was processed successfully.
* @param {!CustomEvent} event Contains detailed information about the * @param {!CustomEvent<!cloudprint.CloudPrintInterfaceProcessInviteDetail>}
* invite and newly accepted destination (if known). * event Contains detailed information about the invite and newly
* accepted destination (if known).
* @private * @private
*/ */
onCloudPrintProcessInviteDone_(event) { onCloudPrintProcessInviteDone_(event) {
......
...@@ -149,16 +149,14 @@ cr.define('print_preview', function() { ...@@ -149,16 +149,14 @@ cr.define('print_preview', function() {
/** /**
* Called when printer sharing invitations are fetched. * 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 * @private
*/ */
onCloudPrintInvitesDone_(event) { onCloudPrintInvitesDone_(event) {
const invitesDoneDetail = this.loadStatus_[event.detail.user] =
/** @type {!cloudprint.CloudPrintInterfaceInvitesDoneDetail} */ (
event.detail);
this.loadStatus_[invitesDoneDetail.user] =
print_preview.InvitationStoreLoadStatus.DONE; print_preview.InvitationStoreLoadStatus.DONE;
this.invitations_[invitesDoneDetail.user] = invitesDoneDetail.invitations; this.invitations_[event.detail.user] = event.detail.invitations;
this.dispatchEvent( this.dispatchEvent(
new CustomEvent(InvitationStore.EventType.INVITATION_SEARCH_DONE)); new CustomEvent(InvitationStore.EventType.INVITATION_SEARCH_DONE));
...@@ -166,25 +164,23 @@ cr.define('print_preview', function() { ...@@ -166,25 +164,23 @@ cr.define('print_preview', function() {
/** /**
* Called when printer sharing invitations fetch has failed. * Called when printer sharing invitations fetch has failed.
* @param {!CustomEvent} event * @param {!CustomEvent<string>} event Contains the user for whom invite
* fetch failed.
* @private * @private
*/ */
onCloudPrintInvitesFailed_(event) { onCloudPrintInvitesFailed_(event) {
this.loadStatus_[/** @type {string} */ (event.detail)] = this.loadStatus_[event.detail] =
print_preview.InvitationStoreLoadStatus.FAILED; print_preview.InvitationStoreLoadStatus.FAILED;
} }
/** /**
* Called when printer sharing invitation was processed successfully. * Called when printer sharing invitation was processed successfully.
* @param {!CustomEvent} event Contains detailed information about the * @param {!CustomEvent<!cloudprint.CloudPrintInterfaceProcessInviteDetail>}
* invite. * event Contains detailed information about the invite.
* @private * @private
*/ */
onCloudPrintProcessInviteDone_(event) { onCloudPrintProcessInviteDone_(event) {
this.invitationProcessed_( this.invitationProcessed_(event.detail.invitation);
/** @type {!cloudprint.CloudPrintInterfaceProcessInviteDetail} */ (
event.detail)
.invitation);
this.dispatchEvent( this.dispatchEvent(
new CustomEvent(InvitationStore.EventType.INVITATION_PROCESSED)); new CustomEvent(InvitationStore.EventType.INVITATION_PROCESSED));
} }
......
...@@ -613,7 +613,8 @@ Polymer({ ...@@ -613,7 +613,8 @@ Polymer({
/** /**
* Updates the cloud print status to NOT_SIGNED_IN if there is an * Updates the cloud print status to NOT_SIGNED_IN if there is an
* authentication error. * authentication error.
* @param {!CustomEvent<{status: number}>} event Contains the error status * @param {!CustomEvent<!cloudprint.CloudPrintInterfaceErrorEventDetail>}
* event Contains the error status
* @private * @private
*/ */
checkCloudPrintStatus_: function(event) { checkCloudPrintStatus_: function(event) {
...@@ -631,7 +632,8 @@ Polymer({ ...@@ -631,7 +632,8 @@ Polymer({
/** /**
* Called when there was an error communicating with Google Cloud print. * Called when there was an error communicating with Google Cloud print.
* Displays an error message in the print header. * 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 * @private
*/ */
onCloudPrintError_: function(event) { onCloudPrintError_: function(event) {
......
...@@ -140,7 +140,7 @@ Polymer({ ...@@ -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 * @private
*/ */
onInputChange_: function(e) { onInputChange_: function(e) {
......
...@@ -336,8 +336,7 @@ Polymer({ ...@@ -336,8 +336,7 @@ Polymer({
}, },
/** /**
* @param {!CustomEvent} e Contains information about what control fired the * @param {!Event} e Contains information about what control fired the event.
* event.
* @private * @private
*/ */
onTextFocus_: function(e) { onTextFocus_: function(e) {
...@@ -454,8 +453,9 @@ Polymer({ ...@@ -454,8 +453,9 @@ Polymer({
}, },
/** /**
* @param {!CustomEvent} e Event fired when a control's text field is blurred. * @param {!CustomEvent<boolean>} e Event fired when a control's text field
* Contains information about whether the control is in an invalid state. * is blurred. Contains information about whether the control is in an
* invalid state.
* @private * @private
*/ */
onTextBlur_: function(e) { onTextBlur_: function(e) {
......
...@@ -39,12 +39,14 @@ Polymer({ ...@@ -39,12 +39,14 @@ Polymer({
}, },
/** /**
* @param {!CustomEvent} e Event containing the new search. * @param {!CustomEvent<string>} e Event containing the new search.
* @private * @private
*/ */
onSearchChanged_: function(e) { onSearchChanged_: function(e) {
let safeQuery = e.detail.trim().replace(SANITIZE_REGEX, '\\$&'); const safeQueryString = e.detail.trim().replace(SANITIZE_REGEX, '\\$&');
safeQuery = safeQuery.length > 0 ? new RegExp(`(${safeQuery})`, 'i') : null; const safeQuery = safeQueryString.length > 0 ?
new RegExp(`(${safeQueryString})`, 'i') :
null;
if (this.timeout_) { if (this.timeout_) {
clearTimeout(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