| 1 | /*
|
|---|
| 2 | Copyright 2019 Google LLC
|
|---|
| 3 |
|
|---|
| 4 | Use of this source code is governed by an MIT-style
|
|---|
| 5 | license that can be found in the LICENSE file or at
|
|---|
| 6 | https://opensource.org/licenses/MIT.
|
|---|
| 7 | */
|
|---|
| 8 |
|
|---|
| 9 | import {WorkboxEventTarget} from './WorkboxEventTarget.js';
|
|---|
| 10 | import '../_version.js';
|
|---|
| 11 |
|
|---|
| 12 | /**
|
|---|
| 13 | * A minimal `Event` subclass shim.
|
|---|
| 14 | * This doesn't *actually* subclass `Event` because not all browsers support
|
|---|
| 15 | * constructable `EventTarget`, and using a real `Event` will error.
|
|---|
| 16 | * @private
|
|---|
| 17 | */
|
|---|
| 18 | export class WorkboxEvent<K extends keyof WorkboxEventMap> {
|
|---|
| 19 | target?: WorkboxEventTarget;
|
|---|
| 20 | sw?: ServiceWorker;
|
|---|
| 21 | originalEvent?: Event;
|
|---|
| 22 | isExternal?: boolean;
|
|---|
| 23 |
|
|---|
| 24 | constructor(
|
|---|
| 25 | public type: K,
|
|---|
| 26 | props: Omit<WorkboxEventMap[K], 'target' | 'type'>,
|
|---|
| 27 | ) {
|
|---|
| 28 | Object.assign(this, props);
|
|---|
| 29 | }
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | export interface WorkboxMessageEvent extends WorkboxEvent<'message'> {
|
|---|
| 33 | data: any;
|
|---|
| 34 | originalEvent: Event;
|
|---|
| 35 | ports: readonly MessagePort[];
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | export interface WorkboxLifecycleEvent
|
|---|
| 39 | extends WorkboxEvent<keyof WorkboxLifecycleEventMap> {
|
|---|
| 40 | isUpdate?: boolean;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | export interface WorkboxLifecycleWaitingEvent extends WorkboxLifecycleEvent {
|
|---|
| 44 | wasWaitingBeforeRegister?: boolean;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | export interface WorkboxLifecycleEventMap {
|
|---|
| 48 | installing: WorkboxLifecycleEvent;
|
|---|
| 49 | installed: WorkboxLifecycleEvent;
|
|---|
| 50 | waiting: WorkboxLifecycleWaitingEvent;
|
|---|
| 51 | activating: WorkboxLifecycleEvent;
|
|---|
| 52 | activated: WorkboxLifecycleEvent;
|
|---|
| 53 | controlling: WorkboxLifecycleEvent;
|
|---|
| 54 | redundant: WorkboxLifecycleEvent;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | export interface WorkboxEventMap extends WorkboxLifecycleEventMap {
|
|---|
| 58 | message: WorkboxMessageEvent;
|
|---|
| 59 | }
|
|---|