Skip to main content

port

@rotorsoft/act-root


@rotorsoft/act-root / act/src / port

Function: port()

port<Port>(injector): (adapter?) => Port

Defined in: libs/act/src/ports.ts:88

Creates a singleton port with optional adapter injection.

The first call initializes the adapter (using the provided adapter or the injector's default). Subsequent calls return the cached singleton. Adapters are disposed in reverse registration order during disposeAndExit.

Type Parametersโ€‹

Portโ€‹

Port extends Disposable

Parametersโ€‹

injectorโ€‹

Injector<Port>

Named function that creates the default adapter

Returnsโ€‹

Port function: call with no args to get the singleton, or pass an adapter on the first call to override the default

(adapter?) => Port

Exampleโ€‹

const store = port(function store(adapter?: Store) {
return adapter || new InMemoryStore();
});
const s = store(); // InMemoryStore