nrgy
Version:
The library for reactive programming using efficient computing and MVC/MVVM patterns
40 lines (35 loc) • 1.77 kB
text/typescript
import { Token, Container } from 'ditox';
import { B as BaseControllerContext, E as ExtensionFn, i as ExtensionParamsProvider, a as BaseService, c as ControllerDeclaration } from './controller-BeiM0Zjy.cjs';
import './types-CxOJPpKX.cjs';
import './types-Bej5aaZB.cjs';
import './atom-C10tpvQt.cjs';
type DependencyProps = {
[key: string]: unknown;
};
type DependencyTokenProps<Props extends DependencyProps> = {
[K in keyof Props]: Token<Props[K]>;
};
type DependencyContext<Dependencies extends DependencyProps> = BaseControllerContext & {
deps: Dependencies;
};
/**
* This extension provides values from DI container to the controller.
*/
declare function withInjections<TSourceContext extends BaseControllerContext, Dependencies extends DependencyProps>(tokens: DependencyTokenProps<Dependencies>): ExtensionFn<TSourceContext, TSourceContext & {
deps: Dependencies;
}>;
type DependencyContainerContext = BaseControllerContext & {
container: Container;
};
/**
* This extension provides DI container to the controller.
*/
declare function withContainer<TSourceContext extends BaseControllerContext>(): ExtensionFn<TSourceContext, TSourceContext & {
container: Container;
}>;
declare function provideDependencyContainer(container: Container): ExtensionParamsProvider;
/**
* This utility allows to use a controller with injections in DI bindings
*/
declare function applyInjections<TContext extends DependencyContext<any>, TService extends BaseService>(controller: ControllerDeclaration<TContext, TService>): (container: Container) => TService;
export { type DependencyContainerContext, type DependencyContext, type DependencyProps, type DependencyTokenProps, applyInjections, provideDependencyContainer, withContainer, withInjections };