Add static attributes from reduction trace

Summary:
In order to support this the stream inceptor transform nodes now is able to return a list of new meta enties, since these are new attributes we try to mimic what would have happened if they were generated on the client. This makes the rest of the logic downstream simpler

Introduced metadata register, same idea as on the clients.
The attributes available are a mixed bag, will work with blok server to imporove

Reviewed By: antonk52

Differential Revision: D45177781

fbshipit-source-id: 9d761b2f682e7e0fd4710f5b2e9d9d6ff26741fc
This commit is contained in:
Luke De Feo
2023-04-27 07:28:41 -07:00
committed by Facebook GitHub Bot
parent 42963b16ab
commit 7ce19f4359
3 changed files with 17 additions and 6 deletions

View File

@@ -18,8 +18,10 @@ class NoOpStreamInterceptor implements StreamInterceptor {
return null;
}
async transformNodes(nodes: Map<Id, UINode>): Promise<Map<Id, UINode>> {
return nodes;
async transformNodes(
nodes: Map<Id, UINode>,
): Promise<[Map<Id, UINode>, Metadata[]]> {
return [nodes, []];
}
async transformMetadata(metadata: Metadata): Promise<Metadata> {

View File

@@ -238,9 +238,16 @@ export function plugin(client: PluginClient<Events>) {
const seenNodes = new Set<Id>();
const processFrame = async (frameScan: FrameScanEvent) => {
try {
const processedNodes = await streamInterceptor.transformNodes(
new Map(frameScan.nodes.map((node) => [node.id, {...node}])),
);
const [processedNodes, additionalMetadata] =
await streamInterceptor.transformNodes(
new Map(frameScan.nodes.map((node) => [node.id, {...node}])),
);
metadata.update((draft) => {
for (const metadata of additionalMetadata) {
draft.set(metadata.id, metadata);
}
});
applyFrameData(processedNodes, frameScan.snapshot);

View File

@@ -284,7 +284,9 @@ export type InspectableUnknown = {
};
export interface StreamInterceptor {
transformNodes(nodes: Map<Id, UINode>): Promise<Map<Id, UINode>>;
transformNodes(
nodes: Map<Id, UINode>,
): Promise<[Map<Id, UINode>, Metadata[]]>;
transformMetadata(metadata: Metadata): Promise<Metadata>;
}