Files
flipper/desktop/plugins/public/ui-debugger/index.tsx
Luke De Feo b1bee28f08 Coordinate update event when litho scrolls or is shifted
Summary: See doc comment for explanation

Reviewed By: lblasa

Differential Revision: D40587610

fbshipit-source-id: f0909440c4e6e3cc9f5c7b557198a93ba8809bd9
2022-10-25 07:10:38 -07:00

54 lines
1.6 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('coordinateUpdate', (event) => {
nodesAtom.update((draft) => {
const node = draft.get(event.nodeId);
if (!node) {
console.warn(`Coordinate update for non existing node `, event);
} else {
node.bounds.x = event.coordinate.x;
node.bounds.y = event.coordinate.y;
}
});
});
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);
}
});
});
return {rootId, snapshots: snapshotsAtom, nodes: nodesAtom, perfEvents};
}
export {Component} from './components/main';