-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provides minor adjustments to the "getWorkerByRegistration" refactoring
- Loading branch information
1 parent
050eafe
commit 00eac3a
Showing
2 changed files
with
20 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
/** | ||
* Attempts to resolve a Service Worker instance from any of its states: | ||
* active, installing, or waiting. | ||
* Attempts to resolve a Service Worker instance from a given registration, | ||
* regardless of its state (active, installing, waiting). | ||
*/ | ||
export const getWorkerByRegistration = ( | ||
registration: ServiceWorkerRegistration, | ||
absoluteWorkerUrl: string, | ||
): ServiceWorker | null => { | ||
return ( | ||
[registration.active, registration.installing, registration.waiting].find( | ||
(worker) => worker?.scriptURL === absoluteWorkerUrl, | ||
) || null | ||
) | ||
const allStates = [ | ||
registration.active, | ||
registration.installing, | ||
registration.waiting, | ||
] | ||
const existingStates = allStates.filter(Boolean) as ServiceWorker[] | ||
const mockWorker = existingStates.find((worker) => { | ||
return worker.scriptURL === absoluteWorkerUrl | ||
}) | ||
|
||
return mockWorker || null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters