Add an automatic way to exclude default values from graphs.
This commit is contained in:
parent
243e53c413
commit
3829018f06
|
@ -17,10 +17,19 @@ export abstract class BaseOperation<P> {
|
||||||
this.parameters = parameters;
|
this.parameters = parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public graph(): string[] {
|
public graph(includeDefaults = false): string[] {
|
||||||
|
const defaults = this.default;
|
||||||
const graph: string[] = [this.name];
|
const graph: string[] = [this.name];
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(this.parameters)) {
|
for (const [key, value] of Object.entries(this.parameters)) {
|
||||||
|
if (
|
||||||
|
includeDefaults &&
|
||||||
|
key in defaults &&
|
||||||
|
(defaults as Record<string, any>)[key] === value
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const kebabCasedKey = key.replace(/([A-Z])/g, '-$1').toLowerCase();
|
const kebabCasedKey = key.replace(/([A-Z])/g, '-$1').toLowerCase();
|
||||||
graph.push(`${kebabCasedKey}=${value as string}`);
|
graph.push(`${kebabCasedKey}=${value as string}`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue