Skip to content

Commit

Permalink
feat: Show lifecycle names in dependency graphing
Browse files Browse the repository at this point in the history
  • Loading branch information
Iku-turso committed Feb 21, 2022
1 parent 7e38ac3 commit 9c0cf20
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`createContainer.dependency-graph given dependency graphing, dependencies and injected, creates Plant-UML graph 1`] = `
"@startuml
hide members
hide circle
\\"Setup(some-setuppable)\\" ..up* \\"some-child-injectable\\" : Setup
class \\"Setup(some-setuppable)\\"<Setup>
class \\"some-child-injectable\\"<Singleton>
\\"some-child-injectable\\" ..up* \\"some-injection-token\\" : Setup
\\"some-injection-token\\" ..up* \\"some-token-injectable\\" : Setup
class \\"some-injection-token\\"<Token> #orange
class \\"some-token-injectable\\"<Singleton>
\\"Setup(some-setuppable)\\" ..up* \\"some-setuppable\\" : Setup
class \\"some-setuppable\\"<Singleton>
class \\"some-parent-injectable\\"<Singleton>
\\"some-parent-injectable\\" --up* \\"some-child-injectable\\"
@enduml"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,6 @@ describe('createContainer.dependency-graph', () => {

const graph = di.inject(plantUmlDependencyGraphInjectable);

expect(graph).toBe(
[
'@startuml',
'hide members',
'hide circle',
'"Setup(some-setuppable)" ..up* "some-child-injectable" : Setup',
'"some-child-injectable" ..up* "some-injection-token" : Setup',
'class "some-injection-token" #orange',
'"some-injection-token" ..up* "some-token-injectable" : Setup',
'"Setup(some-setuppable)" ..up* "some-setuppable" : Setup',
'"some-parent-injectable" --up* "some-child-injectable"',
'@enduml',
].join('\n'),
);
expect(graph).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ describe('createContainer.error-monitoring-for-injected-functions', () => {
{
id: 'some-parent-injectable',
instantiationParameter: 'some-instantiation-parameter-for-parent',
lifecycleName: 'Transient',
},

{
id: 'some-child-injectable',
instantiationParameter: 'some-instantiation-parameter-for-child',
lifecycleName: 'Transient',
},
],
});
Expand All @@ -97,11 +99,13 @@ describe('createContainer.error-monitoring-for-injected-functions', () => {
{
id: 'some-parent-injectable',
instantiationParameter: 'some-instantiation-parameter-for-parent',
lifecycleName: 'Transient',
},

{
id: 'some-child-injectable',
instantiationParameter: 'some-instantiation-parameter-for-child',
lifecycleName: 'Transient',
},
],
});
Expand Down Expand Up @@ -171,11 +175,13 @@ describe('createContainer.error-monitoring-for-injected-functions', () => {
{
id: 'some-parent-injectable',
instantiationParameter: 'some-instantiation-parameter-for-parent',
lifecycleName: 'Transient',
},

{
id: 'some-child-injectable',
instantiationParameter: 'some-instantiation-parameter-for-child',
lifecycleName: 'Transient',
},
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ describe('createContainer.error-monitoring-for-instantiation', () => {
{
id: 'some-parent-injectable',
instantiationParameter: 'some-instantiation-parameter-for-parent',
lifecycleName: 'Transient',
},

{
id: 'some-child-injectable',
instantiationParameter: 'some-instantiation-parameter-for-child',
lifecycleName: 'Transient',
},
],
});
Expand Down Expand Up @@ -148,11 +150,13 @@ describe('createContainer.error-monitoring-for-instantiation', () => {
{
id: 'some-parent-injectable',
instantiationParameter: 'some-instantiation-parameter-for-parent',
lifecycleName: 'Transient',
},

{
id: 'some-child-injectable',
instantiationParameter: 'some-instantiation-parameter-for-child',
lifecycleName: 'Transient',
},
],
});
Expand All @@ -178,11 +182,13 @@ describe('createContainer.error-monitoring-for-instantiation', () => {
{
id: 'some-parent-injectable',
instantiationParameter: 'some-instantiation-parameter-for-parent',
lifecycleName: 'Transient',
},

{
id: 'some-child-injectable',
instantiationParameter: 'some-instantiation-parameter-for-child',
lifecycleName: 'Transient',
},
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ export default (...listOfGetRequireContexts) => {
}

return privateDi.inject(alias, parameter, [
{ id: setuppable.id, isSetup: true },
{
id: setuppable.id,
isSetup: true,
lifecycleName: setuppable.lifecycle.name,
},
]);
},
});
Expand Down Expand Up @@ -322,7 +326,11 @@ const getInstance = ({

const newContext = [
...oldContext,
{ id: injectable.id, instantiationParameter },
{
id: injectable.id,
instantiationParameter,
lifecycleName: injectable.lifecycle.name,
},
];

const injectableCausingCycle = pipeline(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ const plantUmlExtractorInjectable = getInjectable({

return ({ context }) => {
context.reduce((parent, dependency) => {
if (parent.isInjectionToken) {
plantUmlState.add(`class "${parent.id}" #orange`);
}

if (parent.isChildOfSetup === true) {
plantUmlState.add(`"${parent.id}" ..up* "${dependency.id}" : Setup`);

Expand All @@ -53,12 +49,25 @@ const plantUmlExtractorInjectable = getInjectable({
plantUmlState.add(
`"Setup(${parent.id})" ..up* "${dependency.id}" : Setup`,
);

return { ...dependency, isChildOfSetup: true };
}

plantUmlState.add(`"${parent.id}" --up* "${dependency.id}"`);
return dependency;
});

context.forEach(contextItem => {
if (contextItem.isInjectionToken) {
plantUmlState.add(`class "${contextItem.id}"<Token> #orange`);
} else if (contextItem.isSetup === true) {
plantUmlState.add(`class "Setup(${contextItem.id})"<Setup>`);
} else {
plantUmlState.add(
`class "${contextItem.id}"<${contextItem.lifecycleName}>`,
);
}
});
};
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ export const nonStoredInstanceKey = Symbol('non-stored-instance-key');

export default {
singleton: {
name: 'Singleton',
getInstanceKey: () => 'singleton',
},

keyedSingleton: ({ getInstanceKey }) => ({ getInstanceKey }),
keyedSingleton: ({ getInstanceKey }) => ({ name: 'Keyed', getInstanceKey }),

transient: {
name: 'Transient',
getInstanceKey: () => nonStoredInstanceKey,
},
};

0 comments on commit 9c0cf20

Please sign in to comment.