17
18
export function debugGetObservableGraph(obs: IObservable<any> | IObserver, options: IOptions): string {
20
>
const info = Info.from(obs, debugNamePostProcessor);
21
>
if (!info) {
22
return '';
23
}
25
>
const alreadyListed = new Set<IObservable<any> | IObserver>();
26
>
27
>
if (options.type === 'observers') {
28
return formatObservableInfoWithObservers(info, 0, alreadyListed, options).trim();
30
>
return formatObservableInfoWithDependencies(info, 0, alreadyListed, options).trim();
31
>
}
32
>
}
33
34
>
function formatObservableInfoWithDependencies(info: Info, indentLevel: number, alreadyListed: Set<IObservable<any> | IObserver>, options: IOptions): string {
debugGetDependencyGraph.ts
35
>
const indent = '\t\t'.repeat(indentLevel);
36
>
const lines: string[] = [];
37
>
38
>
const isAlreadyListed = alreadyListed.has(info.sourceObj);
39
>
if (isAlreadyListed) {
40
>
lines.push(`${indent}* ${info.type} ${info.name} (already listed)`);
41
>
return lines.join('\n');
42
>
}
43
>
44
>
alreadyListed.add(info.sourceObj);
45
>
46
>
lines.push(`${indent}* ${info.type} ${info.name}:`);
47
>
lines.push(`${indent} value: ${formatValue(info.value, 50)}`);
48
>
lines.push(`${indent} state: ${info.state}`);
49
>
50
>
if (info.dependencies.length > 0) {
51
>
lines.push(`${indent} dependencies:`);
52
>
for (const dep of info.dependencies) {
53
>
const info = Info.from(dep, options.debugNamePostProcessor ?? (name => name)) ?? Info.unknown(dep);
54
>
lines.push(formatObservableInfoWithDependencies(info, indentLevel + 1, alreadyListed, options));
55
>
}
56
>
}
57
>
58
>
return lines.join('\n');
59
>
}
60
61
function formatObservableInfoWithObservers(info: Info, indentLevel: number, alreadyListed: Set<IObservable<any> | IObserver>, options: IOptions): string {