Skip to content

Commit

Permalink
Merge pull request #13 from ammarnajjar/bugfix/actions-from-component…
Browse files Browse the repository at this point in the history
…s-to-reducres

fix: show action in graph when it is not involved in any effect
  • Loading branch information
ammarnajjar authored Nov 22, 2022
2 parents 2ba2010 + 9523e05 commit bfce55a
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class Generator {
}

mapReducersToActions(): ActionsMap {
if (!this.force && this.fromReucers !== undefined) {
if (!this.force && !isEmpty(this.fromReucers)) {
return this.fromReucers;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -257,7 +257,7 @@ export class Generator {
}

mapComponentToActions(): ActionsMap {
if (!this.force && this.fromComponents !== undefined) {
if (!this.force && !isEmpty(this.fromComponents)) {
return this.fromComponents;
}

Expand Down Expand Up @@ -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,
Expand All @@ -326,26 +324,23 @@ export class Generator {
fromReducers: ActionsMap,
): void {
const dotFile = join(this.outputDir, `${action}.dot`);
if (fs.existsSync(dotFile)) {
if (!this.force) {
return;
}

fs.unlinkSync(dotFile);
}
deleteFile(dotFile);

const filterdByAction = [
...chainActionsByInput(fromEffects, action),
...chainActionsByOutput(fromEffects, action),
];
let content = 'digraph {\n';
for (const [k, v] of Object.entries(fromComponents)) {
const lines = v.map(o => {
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`;
${k} -> ${componentAction}\n`;
}

return '';
Expand All @@ -354,12 +349,15 @@ export class Generator {
}

for (const [k, v] of Object.entries(fromReducers)) {
const lines = v.map(o => {
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`;
${reducerAction} -> ${k}\n`;
}

return '';
Expand All @@ -386,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)) {
Expand Down Expand Up @@ -488,3 +484,9 @@ export function getChildNodesRecursivly(node: Node): Node[] {
),
];
}

function deleteFile(filename: string): void {
if (fs.existsSync(filename)) {
fs.unlinkSync(filename);
}
}

0 comments on commit bfce55a

Please sign in to comment.