angular/packages/service-worker/worker/src/msg.ts
Maximilian Köller 59225f5586 feat(service-worker): SwUpdate#activeUpdate and SwUpdate#checkForUpdate should have a meaningful outcome (#43668)
Previously `activateUpdate` and `checkForUpdate` returned `Promise<void>`, which did not provide any
information of the actual outcome of the operation. Developers needed to subscribe to a
corresponding observable to obtain the outcome.

With this commit `SwUpdate#activateUpdate` will return `Promise<boolean>` which resolves to `true` if
an update was activated, to `false` if no new version is available and rejects in case of any error.
`SwUpdate#checkForUpdate` also returns a `Promise<boolean>` which resolves to `true` if an update is available, to `false` if no update was found and rejects in case of any error.

Closes #39840

BREAKING CHANGE: The return type of `SwUpdate#activateUpdate` and `SwUpdate#checkForUpdate` changed to `Promise<boolean>`.

Although unlikely, it is possible that this change will cause TypeScript type-checking to fail in
some cases. If necessary, update your types to account for the new
return type.

DEPRECATED: The `SwUpdate#activated` observable is deprecated.

The `SwUpdate#activated` observable only emits values as a direct response to calling
`SwUpdate#activateUpdate()` and was only useful for determining whether the call resulted in an
update or not. Now, the return value of `SwUpdate#activateUpdate()` can be used to determine the
outcome of the operation and therefore using `SwUpdate#activated` does not offer any benefit.

PR Close #43668
2021-10-05 11:00:07 -07:00

38 lines
873 B
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
export interface MsgAny {
action: string;
}
export interface MsgCheckForUpdates {
action: 'CHECK_FOR_UPDATES';
nonce: number;
}
export function isMsgCheckForUpdates(msg: MsgAny): msg is MsgCheckForUpdates {
return msg.action === 'CHECK_FOR_UPDATES';
}
export interface MsgActivateUpdate {
action: 'ACTIVATE_UPDATE';
nonce: number;
}
export function isMsgActivateUpdate(msg: MsgAny): msg is MsgActivateUpdate {
return msg.action === 'ACTIVATE_UPDATE';
}
export interface MsgCheckVersion {
action: 'CHECK_VERSION';
nonce: number;
}
export function isMsgCheckVersion(msg: MsgAny): msg is MsgCheckVersion {
return msg.action === 'CHECK_VERSION';
}