Summary: ^ This change allows to take different snapshots for different nodes and render them each on the visualiser. At the moment, more than likely, this is not really used. At the same time, it fixes an issue whereas any subtree update can override and set the only visible snapshot. Reviewed By: LukeDefeo, antonk52 Differential Revision: D39821920 fbshipit-source-id: ab8f6a4a2a5e96801c951a4e3009cc571a617f22
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
import {PluginClient, createState, createDataSource} from 'flipper-plugin';
|
|
import {Events, Id, PerfStatsEvent, Snapshot, UINode} from './types';
|
|
|
|
export function plugin(client: PluginClient<Events>) {
|
|
const rootId = createState<Id | undefined>(undefined);
|
|
client.onMessage('init', (root) => rootId.set(root.rootId));
|
|
|
|
const perfEvents = createDataSource<PerfStatsEvent, 'txId'>([], {
|
|
key: 'txId',
|
|
limit: 10 * 1024,
|
|
});
|
|
client.onMessage('perfStats', (event) => {
|
|
perfEvents.append(event);
|
|
});
|
|
|
|
const nodesAtom = createState<Map<Id, UINode>>(new Map());
|
|
const snapshotsAtom = createState<Map<Id, Snapshot>>(new Map());
|
|
client.onMessage('subtreeUpdate', (event) => {
|
|
snapshotsAtom.update((draft) => {
|
|
draft.set(event.rootId, event.snapshot);
|
|
});
|
|
nodesAtom.update((draft) => {
|
|
for (const node of event.nodes) {
|
|
draft.set(node.id, node);
|
|
}
|
|
});
|
|
});
|
|
|
|
client.onMessage('nativeScan', ({nodes}) => {
|
|
//Native scan is a full update so overwrite everything
|
|
nodesAtom.set(new Map(nodes.map((node) => [node.id, node])));
|
|
});
|
|
|
|
return {rootId, snapshots: snapshotsAtom, nodes: nodesAtom, perfEvents};
|
|
}
|
|
|
|
export {Component} from './components/main';
|