Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/devtools/src/__tests__/signal-resources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ describe('groupResources', () => {
]);
});

it('keeps an unnamed resource whose params read another unnamed resource apart from it', () => {
const nodes = [
node('1', 'computed', 'Resource.value', 'Ada'),
node('2', 'linkedSignal', 'Resource.state'),
node('3', 'linkedSignal', 'Resource.extRequest'),
node('4', 'computed', 'Resource.value', ['Ada post']),
node('5', 'linkedSignal', 'Resource.state'),
node('6', 'linkedSignal', 'Resource.extRequest'),
];
const edges: SignalGraphEdge[] = [
{ consumer: 0, producer: 1 },
{ consumer: 1, producer: 2 },
{ consumer: 3, producer: 4 },
{ consumer: 4, producer: 5 },
// The second resource's params read the first resource's value.
{ consumer: 5, producer: 0 },
];
const resources = groupResources(nodes, edges, [], serialize);
expect(resources.map((r) => [r.name, r.value, r.nodeIds])).toEqual([
['resource 1', 'Ada', ['1', '2', '3']],
['resource 2', ['Ada post'], ['4', '5', '6']],
]);
});

it('derives status from the graph when no instance holds the resource', () => {
const nodes = [
node('1', 'computed', 'Resource#trips.value', '(threw an error)'),
Expand Down
3 changes: 2 additions & 1 deletion packages/devtools/src/signal-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ function groupsOf(nodes: SignalGraphNode[], edges: SignalGraphEdge[]): Group[] {
if (!valid(e)) continue;
const a = parsed[e.consumer];
const b = parsed[e.producer];
if (a && b && a.name === b.name) union(e.consumer, e.producer);
// extRequest reads the user's params, which may read another resource.
if (a && b && a.name === b.name && a.part !== 'extRequest') union(e.consumer, e.producer);
}
// httpResource signals have plain names: `_statusCode` and friends read the
// resource's own signals, and its `stream` is read by the resource value.
Expand Down
Loading