Cyclic Dependencies
how to tackle a cyclic dependencies.
import diContainer from 'true-di';
type Node = {
child: Node;
parent: Node;
name: string;
}
type Container = {
parentItem: Node;
childItem: Node;
}
const createNode = (name: string): Node => ({ child: null, parent: null, name });
const container = diContainer<Container>({
parentItem: [
() => createNode('Parent'),
(instance, { childItem }) => {
instance.child = childItem
},
],
childItem: [
() => createNode('Child' cxx),
(instance { parentItem }) => {
instance.parent = parentItem;
},
],
});Last updated