Summary: ^ TODO: the snapshot corresponds to the referring subtree update. However, the snapshot is getting applied as if it was the current top view of the running app. This is true in most cases but it doesn't for some. To solve this, we need to use the rootId for the subtree and apply the snapshot only if appropriate. Having said that, is good enough for the current submission as we keep iterating on it. Reviewed By: LukeDefeo Differential Revision: D39813307 fbshipit-source-id: 33b6aff6e9dd085934150ebd2f247062447a59ff
45 lines
1.3 KiB
TypeScript
45 lines
1.3 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, 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 snapshotAtom = createState<String | undefined>(undefined);
|
|
client.onMessage('subtreeUpdate', ({nodes, snapshot}) => {
|
|
snapshotAtom.set(snapshot);
|
|
nodesAtom.update((draft) => {
|
|
for (const node of 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, snapshot: snapshotAtom, nodes: nodesAtom, perfEvents};
|
|
}
|
|
|
|
export {Component} from './components/main';
|