From dc55d12a3f7d30ee957843e734968294d2e95efe Mon Sep 17 00:00:00 2001 From: Iku-turso Date: Mon, 21 Feb 2022 13:28:55 +0200 Subject: [PATCH] feat: Make injection tokens display more pretty in dependency graphing --- .../createContainer.dependency-graphing.test.js | 1 + .../src/dependency-injection-container/createContainer.js | 5 ++++- .../extensions/dependency-graphing/dependency-graphing.js | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/injectable/src/dependency-injection-container/createContainer.dependency-graphing.test.js b/packages/injectable/src/dependency-injection-container/createContainer.dependency-graphing.test.js index 3c2bd776..03b73afe 100644 --- a/packages/injectable/src/dependency-injection-container/createContainer.dependency-graphing.test.js +++ b/packages/injectable/src/dependency-injection-container/createContainer.dependency-graphing.test.js @@ -55,6 +55,7 @@ describe('createContainer.dependency-graph', () => { '@startuml', '"Setup(some-setuppable)" ..up* "some-child-injectable" : Setup', '"some-child-injectable" ..up* "some-injection-token" : Setup', + 'class "some-injection-token" << (T,#FF7700) >>', '"some-injection-token" ..up* "some-token-injectable" : Setup', '"Setup(some-setuppable)" ..up* "some-setuppable" : Setup', '"some-parent-injectable" --up* "some-child-injectable"', diff --git a/packages/injectable/src/dependency-injection-container/createContainer.js b/packages/injectable/src/dependency-injection-container/createContainer.js index 88bec6ff..ca002101 100644 --- a/packages/injectable/src/dependency-injection-container/createContainer.js +++ b/packages/injectable/src/dependency-injection-container/createContainer.js @@ -76,7 +76,10 @@ export default (...listOfGetRequireContexts) => { find({ id: injectionToken.id }), ); - const newContext = [...oldContext, { id: injectionToken.id }]; + const newContext = [ + ...oldContext, + { id: injectionToken.id, isInjectionToken: true }, + ]; if (injectableCausingCycle) { throw new Error( diff --git a/packages/injectable/src/dependency-injection-container/extensions/dependency-graphing/dependency-graphing.js b/packages/injectable/src/dependency-injection-container/extensions/dependency-graphing/dependency-graphing.js index 1b43d06a..ba5b2320 100644 --- a/packages/injectable/src/dependency-injection-container/extensions/dependency-graphing/dependency-graphing.js +++ b/packages/injectable/src/dependency-injection-container/extensions/dependency-graphing/dependency-graphing.js @@ -37,6 +37,10 @@ const plantUmlExtractorInjectable = getInjectable({ return ({ context }) => { context.reduce((parent, dependency) => { + if (parent.isInjectionToken) { + plantUmlState.add(`class "${parent.id}" << (T,#FF7700) >>`); + } + if (parent.isChildOfSetup === true) { plantUmlState.add(`"${parent.id}" ..up* "${dependency.id}" : Setup`);