histoire
Version:
A fast story book powered by Vite
17 lines (16 loc) • 705 B
JavaScript
import { createCatalogService } from './service.js';
/** One service per runtime generation; it dies with the handle (observers detach on the adapter's abort). */
const services = new WeakMap();
/**
* Returns the catalog service of the context's generation, creating it (and its
* state observers) on first use.
* @param context Handler context of the current generation.
*/
export function getCatalogService(context) {
let service = services.get(context.handle);
if (!service) {
service = createCatalogService({ handle: context.handle, catalog: context.catalog, emit: context.emit, signal: context.signal });
services.set(context.handle, service);
}
return service;
}