Skip to content

Commit 9fcdd37

Browse files
GoodluckhfKonstantin Bubyakin
authored andcommitted
feat(instance-wrappers): Для посдтановки функций
1 parent 798164c commit 9fcdd37

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { InstanceWrapper, InstanceWrapperArguments } from './instance-wrapper';
2+
import { DependencyInterface } from '../internal-types';
3+
4+
export type FactoryInstanceWrapperArguments = InstanceWrapperArguments & {
5+
factory: () => any;
6+
dependencies: DependencyInterface[];
7+
};
8+
9+
export class FactoryInstanceWrapper extends InstanceWrapper {
10+
private readonly dependencies: DependencyInterface[];
11+
12+
private readonly factory: (...any) => any;
13+
14+
public constructor(
15+
contextModule,
16+
{
17+
dependencies,
18+
factory,
19+
...instanceWrapperArguments
20+
}: FactoryInstanceWrapperArguments,
21+
) {
22+
super(contextModule, instanceWrapperArguments);
23+
this.factory = factory;
24+
this.dependencies = dependencies;
25+
}
26+
27+
public createInstance(
28+
dependencyResolver: (dependency: DependencyInterface) => any,
29+
) {
30+
const resolvedDependencies = this.dependencies.map(dependencyResolver);
31+
this.resolvedValue = this.factory(...resolvedDependencies);
32+
}
33+
}

0 commit comments

Comments
 (0)