refactor(service-worker): rename `RegistrationOptions` to `SwRegistrationOptions` (#21842)

This is in preparation of making `RegistrationOptions` part of the
public API (in a subsequent commit).

PR Close #21842
This commit is contained in:
George Kalpakas 2019-04-25 16:51:07 +03:00 committed by Andrew Kushnir
parent 2236ea4359
commit d7887ab4ab
2 changed files with 15 additions and 15 deletions

View File

@ -14,7 +14,7 @@ import {NgswCommChannel} from './low_level';
import {SwPush} from './push'; import {SwPush} from './push';
import {SwUpdate} from './update'; import {SwUpdate} from './update';
export abstract class RegistrationOptions { export abstract class SwRegistrationOptions {
scope?: string; scope?: string;
enabled?: boolean; enabled?: boolean;
} }
@ -22,7 +22,7 @@ export abstract class RegistrationOptions {
export const SCRIPT = new InjectionToken<string>('NGSW_REGISTER_SCRIPT'); export const SCRIPT = new InjectionToken<string>('NGSW_REGISTER_SCRIPT');
export function ngswAppInitializer( export function ngswAppInitializer(
injector: Injector, script: string, options: RegistrationOptions, injector: Injector, script: string, options: SwRegistrationOptions,
platformId: string): Function { platformId: string): Function {
const initializer = () => { const initializer = () => {
const app = injector.get<ApplicationRef>(ApplicationRef); const app = injector.get<ApplicationRef>(ApplicationRef);
@ -50,7 +50,7 @@ export function ngswAppInitializer(
} }
export function ngswCommChannelFactory( export function ngswCommChannelFactory(
opts: RegistrationOptions, platformId: string): NgswCommChannel { opts: SwRegistrationOptions, platformId: string): NgswCommChannel {
return new NgswCommChannel( return new NgswCommChannel(
isPlatformBrowser(platformId) && opts.enabled !== false ? navigator.serviceWorker : isPlatformBrowser(platformId) && opts.enabled !== false ? navigator.serviceWorker :
undefined); undefined);
@ -75,16 +75,16 @@ export class ServiceWorkerModule {
ngModule: ServiceWorkerModule, ngModule: ServiceWorkerModule,
providers: [ providers: [
{provide: SCRIPT, useValue: script}, {provide: SCRIPT, useValue: script},
{provide: RegistrationOptions, useValue: opts}, {provide: SwRegistrationOptions, useValue: opts},
{ {
provide: NgswCommChannel, provide: NgswCommChannel,
useFactory: ngswCommChannelFactory, useFactory: ngswCommChannelFactory,
deps: [RegistrationOptions, PLATFORM_ID] deps: [SwRegistrationOptions, PLATFORM_ID]
}, },
{ {
provide: APP_INITIALIZER, provide: APP_INITIALIZER,
useFactory: ngswAppInitializer, useFactory: ngswAppInitializer,
deps: [Injector, SCRIPT, RegistrationOptions, PLATFORM_ID], deps: [Injector, SCRIPT, SwRegistrationOptions, PLATFORM_ID],
multi: true, multi: true,
}, },
], ],

View File

@ -9,7 +9,7 @@
import {PLATFORM_ID} from '@angular/core'; import {PLATFORM_ID} from '@angular/core';
import {TestBed} from '@angular/core/testing'; import {TestBed} from '@angular/core/testing';
import {NgswCommChannel} from '@angular/service-worker/src/low_level'; import {NgswCommChannel} from '@angular/service-worker/src/low_level';
import {RegistrationOptions, ngswCommChannelFactory} from '@angular/service-worker/src/module'; import {SwRegistrationOptions, ngswCommChannelFactory} from '@angular/service-worker/src/module';
import {SwPush} from '@angular/service-worker/src/push'; import {SwPush} from '@angular/service-worker/src/push';
import {SwUpdate} from '@angular/service-worker/src/update'; import {SwUpdate} from '@angular/service-worker/src/update';
import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockServiceWorkerRegistration, patchDecodeBase64} from '@angular/service-worker/testing/mock'; import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockServiceWorkerRegistration, patchDecodeBase64} from '@angular/service-worker/testing/mock';
@ -52,10 +52,10 @@ import {async_fit, async_it} from './async';
TestBed.configureTestingModule({ TestBed.configureTestingModule({
providers: [ providers: [
{provide: PLATFORM_ID, useValue: 'server'}, {provide: PLATFORM_ID, useValue: 'server'},
{provide: RegistrationOptions, useValue: {enabled: true}}, { {provide: SwRegistrationOptions, useValue: {enabled: true}}, {
provide: NgswCommChannel, provide: NgswCommChannel,
useFactory: ngswCommChannelFactory, useFactory: ngswCommChannelFactory,
deps: [RegistrationOptions, PLATFORM_ID] deps: [SwRegistrationOptions, PLATFORM_ID]
} }
] ]
}); });
@ -66,10 +66,10 @@ import {async_fit, async_it} from './async';
TestBed.configureTestingModule({ TestBed.configureTestingModule({
providers: [ providers: [
{provide: PLATFORM_ID, useValue: 'browser'}, {provide: PLATFORM_ID, useValue: 'browser'},
{provide: RegistrationOptions, useValue: {enabled: false}}, { {provide: SwRegistrationOptions, useValue: {enabled: false}}, {
provide: NgswCommChannel, provide: NgswCommChannel,
useFactory: ngswCommChannelFactory, useFactory: ngswCommChannelFactory,
deps: [RegistrationOptions, PLATFORM_ID] deps: [SwRegistrationOptions, PLATFORM_ID]
} }
] ]
}); });
@ -80,11 +80,11 @@ import {async_fit, async_it} from './async';
TestBed.configureTestingModule({ TestBed.configureTestingModule({
providers: [ providers: [
{provide: PLATFORM_ID, useValue: 'browser'}, {provide: PLATFORM_ID, useValue: 'browser'},
{provide: RegistrationOptions, useValue: {enabled: true}}, {provide: SwRegistrationOptions, useValue: {enabled: true}},
{ {
provide: NgswCommChannel, provide: NgswCommChannel,
useFactory: ngswCommChannelFactory, useFactory: ngswCommChannelFactory,
deps: [RegistrationOptions, PLATFORM_ID], deps: [SwRegistrationOptions, PLATFORM_ID],
}, },
], ],
}); });
@ -110,10 +110,10 @@ import {async_fit, async_it} from './async';
TestBed.configureTestingModule({ TestBed.configureTestingModule({
providers: [ providers: [
{provide: PLATFORM_ID, useValue: 'browser'}, {provide: PLATFORM_ID, useValue: 'browser'},
{provide: RegistrationOptions, useValue: {enabled: true}}, { {provide: SwRegistrationOptions, useValue: {enabled: true}}, {
provide: NgswCommChannel, provide: NgswCommChannel,
useFactory: ngswCommChannelFactory, useFactory: ngswCommChannelFactory,
deps: [RegistrationOptions, PLATFORM_ID] deps: [SwRegistrationOptions, PLATFORM_ID]
} }
] ]
}); });