mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-14 10:35:11 +00:00
- registration is moved from top-level index to app/sagas. - mock implementation is provided for tests - actions are renamed to include "app" prefix - actions are changed to not use non-serializable arguments - reducers are changed to not use non-serializable state
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
// SPDX-License-Identifier: MIT
|
|
// Copyright (c) 2022 The Pybricks Authors
|
|
|
|
// mock implementation of serviceWorkerRegistration for testing
|
|
|
|
type Config = {
|
|
onSuccess?: (r: ServiceWorkerRegistration) => void;
|
|
onUpdate?: (r: ServiceWorkerRegistration) => void;
|
|
};
|
|
|
|
/** The config that was registered, if any. */
|
|
let globalConfig: Config | undefined;
|
|
|
|
/**
|
|
* Mocks the register() function.
|
|
*
|
|
* This just saves the config for later use.
|
|
*
|
|
* @param config The config.
|
|
*/
|
|
export function register(config?: Config): void {
|
|
globalConfig = config;
|
|
}
|
|
|
|
/**
|
|
* Fires the onSuccess callback that was registered, if any.
|
|
*
|
|
* @param registration The registration to pass to the callback.
|
|
*/
|
|
export function _fireOnSuccess(registration: ServiceWorkerRegistration): void {
|
|
if (globalConfig && globalConfig.onSuccess) {
|
|
globalConfig.onSuccess(registration);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Fires the onUpdate callback that was registered, if any.
|
|
*
|
|
* @param registration The registration to pass to the callback.
|
|
*/
|
|
export function _fireOnUpdate(registration: ServiceWorkerRegistration): void {
|
|
if (globalConfig && globalConfig.onUpdate) {
|
|
globalConfig.onUpdate(registration);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Mocks the unregister() function.
|
|
*/
|
|
export function unregister(): void {
|
|
// nothing to do for now
|
|
}
|