Skip to content

Commit 33bb34b

Browse files
vyom1611AndrewKushnir
authored andcommitted
refactor(service-worker): refactored code to remove useless code (angular#47255)
- Removes useless code in `generator.ts` and `module.ts` in service-workers - Uses inline variables to return values from functions PR Close angular#47255
1 parent 0d13cc7 commit 33bb34b

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

packages/service-worker/config/src/generator.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,13 @@ function globListToMatcher(globs: string[]): (file: string) => boolean {
144144
}
145145

146146
function matches(file: string, patterns: {positive: boolean, regex: RegExp}[]): boolean {
147-
const res = patterns.reduce((isMatch, pattern) => {
147+
return patterns.reduce((isMatch, pattern) => {
148148
if (pattern.positive) {
149149
return isMatch || pattern.regex.test(file);
150150
} else {
151151
return isMatch && !pattern.regex.test(file);
152152
}
153153
}, false);
154-
return res;
155154
}
156155

157156
function urlToRegex(url: string, baseHref: string, literalQuestionMark?: boolean): string {

packages/service-worker/src/module.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const SCRIPT = new InjectionToken<string>('NGSW_REGISTER_SCRIPT');
8080
export function ngswAppInitializer(
8181
injector: Injector, script: string, options: SwRegistrationOptions,
8282
platformId: string): Function {
83-
const initializer = () => {
83+
return () => {
8484
if (!(isPlatformBrowser(platformId) && ('serviceWorker' in navigator) &&
8585
options.enabled !== false)) {
8686
return;
@@ -132,7 +132,6 @@ export function ngswAppInitializer(
132132
navigator.serviceWorker.register(script, {scope: options.scope})
133133
.catch(err => console.error('Service worker registration failed with:', err))));
134134
};
135-
return initializer;
136135
}
137136

138137
function delayWithTimeout(timeout: number): Observable<unknown> {

0 commit comments

Comments
 (0)