Shared functions between client and service worker
npm i sw-shared-functions
import { share } from 'sw-shared-functions';
export class HelloService {
sayHello(name: string): string {
return `Hello, ${name}`;
}
}
share(new HelloService());
import { load } from 'sw-shared-functions';
import type { HelloService } from '../services/hello.service';
const helloServ = await load<HelloService>();
console.log(await helloServ.sayHello('World!'));
MIT. Copyright (c) Kyaw Swar Thwin <myanmarunicorn@gmail.com>