You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte-kit-vice/src/uix/sema/define-engine-semantic.ts

61 lines
2.0 KiB

/**
* Service factory that adapts `EngineSemantic` to the `arts/active-app`
* composition contract. Lives in sema (not in `arts/`) because semantic
* coordination is a UIX-layer concern, not generic app infrastructure
* like cache / auth / perm.
*
* Usage from a layout:
*
* import { createActiveApp } from '$active-app';
* import { defineActiveLangs } from '$active-app/services';
* import { defineEngineSemantic } from '$uix/sema';
*
* const App = createActiveApp({
* services: {
* langs: defineActiveLangs({ schema, defaultLocale: 'es' }),
* events: defineEngineSemantic()
* }
* });
*
* // ActiveUix exposes it as uix.events:
* App.events.emit({ target, name: 'dismiss', family: 'emerge' });
*/
import { EngineSemantic, type EngineSemanticOptions } from './engine';
import type { DomApplier } from '$adom';
import type { EngineSound } from '$sound';
import type { AppServiceFactory } from '$active-app/services';
export function defineEngineSemantic(
options: EngineSemanticOptions = {}
): AppServiceFactory<
'events',
readonly ['logger', 'timers'],
readonly ['dom', 'sound'],
EngineSemantic
> {
return {
name: 'events',
coreDependencies: ['logger', 'timers'],
serviceDependencies: ['dom', 'sound'],
initMode: 'lazy',
create({ core, services }) {
return new EngineSemantic({
...options,
logger: options.logger ?? core.logger,
dom: options.dom ?? (services.dom as DomApplier | undefined),
// The app's shared Web Audio runtime, so the sound channel plays
// through the document's ONE `AudioContext` instead of opening a
// private one. Degrades like `dom`: an app that declares no `sound`
// service gets `undefined` and the channel owns its own engine.
soundEngine: options.soundEngine ?? (services.sound as EngineSound | undefined),
// Perceptual timers run on the app's managed clock.
timers: options.timers ?? core.timers
});
},
dispose(engine) {
engine.dispose();
}
};
}

Powered by TurnKey Linux.