From cd8418109fd11585050b8196adb019907ffbcf9e Mon Sep 17 00:00:00 2001 From: Ammar Najjar Date: Tue, 22 Nov 2022 15:01:44 +0100 Subject: [PATCH 1/6] fix: show action in graph when it is not involved in any effect --- src/generator.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/generator.ts b/src/generator.ts index 76da987..0e0220f 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -113,7 +113,7 @@ export class Generator { } mapReducersToActions(): ActionsMap { - if (!this.force && this.fromReucers !== undefined) { + if (!this.force && !isEmpty(this.fromReucers)) { return this.fromReucers; } @@ -340,12 +340,15 @@ export class Generator { ]; let content = 'digraph {\n'; for (const [k, v] of Object.entries(fromComponents)) { - const lines = v.map(o => { + content += `${k} [shape="box", color=blue, fillcolor=blue, fontcolor=white, style=filled]\n`; + const lines = v.map(componentAction => { if ( - filterdByAction.some(a => a.input.includes(o) || a.output.includes(o)) + filterdByAction.some(effect => + effect.input.includes(componentAction), + ) || + action === componentAction ) { - return `${k} [shape="box", color=blue, fillcolor=blue, fontcolor=white, style=filled] - ${k} -> ${o}\n`; + return `${k} -> ${componentAction}\n`; } return ''; @@ -354,12 +357,15 @@ export class Generator { } for (const [k, v] of Object.entries(fromReducers)) { - const lines = v.map(o => { + content += `${k} [shape="hexagon", color=purple, fillcolor=purple, fontcolor=white, style=filled]\n`; + const lines = v.map(reducerAction => { if ( - filterdByAction.some(a => a.input.includes(o) || a.output.includes(o)) + filterdByAction.some(effect => + effect.output.includes(reducerAction), + ) || + action === reducerAction ) { - return `${k} [shape="hexagon", color=purple, fillcolor=purple, fontcolor=white, style=filled] - ${o} -> ${k}\n`; + return `${reducerAction} -> ${k}\n`; } return ''; From 5ab640f744a259ce53286a8747233ab08764eabf Mon Sep 17 00:00:00 2001 From: Ammar Najjar Date: Tue, 22 Nov 2022 15:06:32 +0100 Subject: [PATCH 2/6] fix: show only components connected to actions of interest --- src/generator.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/generator.ts b/src/generator.ts index 0e0220f..89a0e5c 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -340,7 +340,6 @@ export class Generator { ]; let content = 'digraph {\n'; for (const [k, v] of Object.entries(fromComponents)) { - content += `${k} [shape="box", color=blue, fillcolor=blue, fontcolor=white, style=filled]\n`; const lines = v.map(componentAction => { if ( filterdByAction.some(effect => @@ -348,7 +347,8 @@ export class Generator { ) || action === componentAction ) { - return `${k} -> ${componentAction}\n`; + return `${k} [shape="box", color=blue, fillcolor=blue, fontcolor=white, style=filled] + ${k} -> ${componentAction}\n`; } return ''; @@ -357,7 +357,6 @@ export class Generator { } for (const [k, v] of Object.entries(fromReducers)) { - content += `${k} [shape="hexagon", color=purple, fillcolor=purple, fontcolor=white, style=filled]\n`; const lines = v.map(reducerAction => { if ( filterdByAction.some(effect => @@ -365,7 +364,8 @@ export class Generator { ) || action === reducerAction ) { - return `${reducerAction} -> ${k}\n`; + return `${k} [shape="hexagon", color=purple, fillcolor=purple, fontcolor=white, style=filled] + ${reducerAction} -> ${k}\n`; } return ''; From 246d54995b4cc4ebd1486831154fe612fde48bcd Mon Sep 17 00:00:00 2001 From: Ammar Najjar Date: Tue, 22 Nov 2022 15:08:16 +0100 Subject: [PATCH 3/6] fix: always overwrite the action.dot file --- src/generator.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/generator.ts b/src/generator.ts index 89a0e5c..b225470 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -327,10 +327,6 @@ export class Generator { ): void { const dotFile = join(this.outputDir, `${action}.dot`); if (fs.existsSync(dotFile)) { - if (!this.force) { - return; - } - fs.unlinkSync(dotFile); } From 4f46228acfa56fd17ed7943e78c9f13bb14122f2 Mon Sep 17 00:00:00 2001 From: Ammar Najjar Date: Tue, 22 Nov 2022 15:10:36 +0100 Subject: [PATCH 4/6] introduce deleteFile function --- src/generator.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/generator.ts b/src/generator.ts index b225470..fa27964 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -306,9 +306,7 @@ export class Generator { return; } - if (fs.existsSync(this.structureFile)) { - fs.unlinkSync(this.structureFile); - } + deleteFile(this.structureFile); const content = JSON.stringify({ allActions: this.allActions, @@ -326,9 +324,7 @@ export class Generator { fromReducers: ActionsMap, ): void { const dotFile = join(this.outputDir, `${action}.dot`); - if (fs.existsSync(dotFile)) { - fs.unlinkSync(dotFile); - } + deleteFile(dotFile); const filterdByAction = [ ...chainActionsByInput(fromEffects, action), @@ -388,9 +384,7 @@ export class Generator { fromReducers: ActionsMap, ): void { const dotFile = join(this.outputDir, 'all.dot'); - if (fs.existsSync(dotFile)) { - fs.unlinkSync(dotFile); - } + deleteFile(dotFile); let content = 'digraph {\n'; for (const [k, v] of Object.entries(fromComponents)) { @@ -490,3 +484,9 @@ export function getChildNodesRecursivly(node: Node): Node[] { ), ]; } + +function deleteFile(filename: string): void { + if (fs.existsSync(filename)) { + fs.unlinkSync(filename); + } +} From 4d155b0a83b59b4d339fead6e61ac59f32a20d91 Mon Sep 17 00:00:00 2001 From: Ammar Najjar Date: Tue, 22 Nov 2022 15:13:54 +0100 Subject: [PATCH 5/6] fix: use isEmpty instead of checking against undefined, it could be an empty object --- src/generator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generator.ts b/src/generator.ts index fa27964..3d0ad09 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -257,7 +257,7 @@ export class Generator { } mapComponentToActions(): ActionsMap { - if (!this.force && this.fromComponents !== undefined) { + if (!this.force && !isEmpty(this.fromComponents)) { return this.fromComponents; } From 9523e0597fa01fa5a5e7274ee9036736c54e35e0 Mon Sep 17 00:00:00 2001 From: Ammar Najjar Date: Tue, 22 Nov 2022 15:14:38 +0100 Subject: [PATCH 6/6] fix: use isEmpty instead of checking against undefined, it could be an empty object --- src/generator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generator.ts b/src/generator.ts index 3d0ad09..f00b39a 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -217,7 +217,7 @@ export class Generator { } mapeffectsToActions(): EffectsStructure { - if (!this.force && this.fromEffects !== undefined) { + if (!this.force && !isEmpty(this.fromEffects)) { console.log('Reading for a previously saved structure'); return this.fromEffects; }