From 7aed64d3a11e8277032c62282751f4513ed1c7eb Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Mon, 2 Apr 2018 14:51:06 +0300 Subject: [PATCH] docs(service-worker): add `UpdateActivated`/`AvailableEvent` to the public API (#23138) PR Close #23138 --- packages/service-worker/src/index.ts | 3 ++- packages/service-worker/src/low_level.ts | 19 +++++++------- .../service-worker/service-worker.d.ts | 26 +++++++++++++++++++ 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/packages/service-worker/src/index.ts b/packages/service-worker/src/index.ts index bd89ce2ff2..a7defed04f 100644 --- a/packages/service-worker/src/index.ts +++ b/packages/service-worker/src/index.ts @@ -14,6 +14,7 @@ * found in the LICENSE file at https://angular.io/license */ +export {UpdateActivatedEvent, UpdateAvailableEvent} from './low_level'; export {ServiceWorkerModule} from './module'; export {SwPush} from './push'; -export {SwUpdate} from './update'; \ No newline at end of file +export {SwUpdate} from './update'; diff --git a/packages/service-worker/src/low_level.ts b/packages/service-worker/src/low_level.ts index 6929c90d22..98fb3437ba 100644 --- a/packages/service-worker/src/low_level.ts +++ b/packages/service-worker/src/low_level.ts @@ -11,27 +11,26 @@ import {filter, map, publish, switchMap, take, tap} from 'rxjs/operators'; export const ERR_SW_NOT_SUPPORTED = 'Service workers are disabled or not supported by this browser'; -export interface Version { - hash: string; - appData?: Object; -} - /** + * An event emitted when a new version of the app is available. + * * @experimental */ export interface UpdateAvailableEvent { type: 'UPDATE_AVAILABLE'; - current: Version; - available: Version; + current: {hash: string, appData?: Object}; + available: {hash: string, appData?: Object}; } /** + * An event emitted when a new version of the app has been downloaded and activated. + * * @experimental */ export interface UpdateActivatedEvent { type: 'UPDATE_ACTIVATED'; - previous?: Version; - current: Version; + previous?: {hash: string, appData?: Object}; + current: {hash: string, appData?: Object}; } export type IncomingEvent = UpdateAvailableEvent | UpdateActivatedEvent; @@ -52,7 +51,7 @@ function errorObservable(message: string): Observable { /** * @experimental -*/ + */ export class NgswCommChannel { /** * @internal diff --git a/tools/public_api_guard/service-worker/service-worker.d.ts b/tools/public_api_guard/service-worker/service-worker.d.ts index ac382b9b98..68738b635d 100644 --- a/tools/public_api_guard/service-worker/service-worker.d.ts +++ b/tools/public_api_guard/service-worker/service-worker.d.ts @@ -27,3 +27,29 @@ export declare class SwUpdate { activateUpdate(): Promise; checkForUpdate(): Promise; } + +/** @experimental */ +export interface UpdateActivatedEvent { + current: { + hash: string; + appData?: Object; + }; + previous?: { + hash: string; + appData?: Object; + }; + type: 'UPDATE_ACTIVATED'; +} + +/** @experimental */ +export interface UpdateAvailableEvent { + available: { + hash: string; + appData?: Object; + }; + current: { + hash: string; + appData?: Object; + }; + type: 'UPDATE_AVAILABLE'; +}