Skip to content

vue-mvvm / core / WritableGlobalContext

WritableGlobalContext

Provides an interface for accessing the global context

Extends

Methods

getProviders()

ts
getProviders(): Component[];

Return all registered providers

Returns

Component[]

Inherited from

ReadableGlobalContext.getProviders


getService()

Call Signature

ts
getService<T>(key): InstanceType<T>;

Retrieves a service instance corresponding to the provided class or constructor function.

Type Parameters
T

T extends (...args) => any

Parameters
key

T

The class or constructor function that represents the service to retrieve.

Returns

InstanceType<T>

An instance of the service represented by the provided class or constructor function.

Inherited from

ReadableGlobalContext.getService

Call Signature

ts
getService<T>(key): T;

Retrieves a service instance based on the passed ServiceKey

Type Parameters
T

T

Parameters
key

ServiceKey<T>

The ServiceKey connected with the service

Returns

T

Inherited from

ReadableGlobalContext.getService

Call Signature

ts
getService<T>(key): Promise<T>;

Retrieves a service instance based on the passed AsyncServiceKey. The services are resolved async.

Type Parameters
T

T

Parameters
key

AsyncServiceKey<T>

The AsyncServiceKey connected with the service

Returns

Promise<T>

Inherited from

ReadableGlobalContext.getService


mockService()

ts
mockService(key, handler): void;

Mocks a service by providing a custom implementation for the specified key. This allows overriding the default behavior of a service with a custom handler.

Parameters

key

(...args) => any

The constructor of the service class to be mocked.

handler

FactoryFunction<unknown>

A factory function that provides the mocked behavior for the service.

Returns

void


registerProvider()

ts
registerProvider(component): void;

Registers a provider component

Parameters

component

Component

The provider component

Returns

void


registerService()

Call Signature

ts
registerService<T>(key, factory): void;

Registers a service with a specified key and factory function.

Type Parameters
T

T extends (...args) => any

Parameters
key

T

The class or constructor function that serves as the unique identifier for the service.

factory

FactoryFunction<InstanceType<T>>

A factory function that creates an instance of the service associated with the provided key.

Returns

void

Call Signature

ts
registerService<T>(key, factory): void;

Registers a service with a ServiceKey key and factory function.

Type Parameters
T

T

Parameters
key

ServiceKey<T>

The ServiceKey that serves as the unique identifier for the service.

factory

FactoryFunction<T>

A factory function that creates an instance of the service associated with the provided key.

Returns

void

Call Signature

ts
registerService<T>(key, factory): void;

Registers a service with an AsyncServiceKey key and async factory function.

Type Parameters
T

T

Parameters
key

AsyncServiceKey<T>

The AsyncServiceKey that serves as the unique identifier for the service.

factory

AsyncFactoryFunction<T>

An async factory function that creates an instance of the service associated with the provided key.

Returns

void


toReadableGlobalContext()

ts
toReadableGlobalContext(): ReadableGlobalContext;

Creates a ReadableGlobalContext from this WritableGlobalContext reference

Returns

ReadableGlobalContext

A ReadableGlobalContext