Move events processing to PSR

Summary: Means that attribution is now part of the export, too.

Reviewed By: oprisnik

Differential Revision: D15877937

fbshipit-source-id: e089597269b8977320d06284179f72d40d01ebf2
This commit is contained in:
Pascal Hartig
2019-06-20 03:46:26 -07:00
committed by Facebook Github Bot
parent 5c497d3eea
commit e3f88e2a7b
2 changed files with 24 additions and 18 deletions

View File

@@ -54,6 +54,7 @@ function mockPersistedState(
imagesMap,
closeableReferenceLeaks: [],
isLeakTrackingEnabled: false,
nextEventId: 0,
};
}
@@ -238,6 +239,7 @@ test('the metric reducer with the multiple events', () => {
const persistedState = {
surfaceList: new Set(),
images: [],
nextEventId: 0,
events,
imagesMap,
};

View File

@@ -42,6 +42,7 @@ export type PersistedState = {
imagesMap: ImagesMap,
closeableReferenceLeaks: Array<AndroidCloseableReferenceLeakEvent>,
isLeakTrackingEnabled: boolean,
nextEventId: number,
};
type PluginState = {
@@ -88,6 +89,7 @@ export default class extends FlipperPlugin<PluginState, *, PersistedState> {
surfaceList: new Set(),
closeableReferenceLeaks: [],
isLeakTrackingEnabled: false,
nextEventId: 0,
};
static exportPersistedState = (
@@ -156,6 +158,26 @@ export default class extends FlipperPlugin<PluginState, *, PersistedState> {
event,
),
};
} else if (method == 'events') {
const event: ImageEvent = data;
debugLog('Received events', event);
const {surfaceList} = persistedState;
const {attribution} = event;
if (attribution instanceof Array && attribution.length > 0) {
const surface = attribution[0].trim();
if (surface.length > 0) {
surfaceList.add(surface);
}
}
return {
...persistedState,
events: [
{eventId: persistedState.nextEventId, ...event},
...persistedState.events,
],
nextEventId: persistedState.nextEventId + 1,
};
}
return persistedState;
@@ -270,24 +292,6 @@ export default class extends FlipperPlugin<PluginState, *, PersistedState> {
init() {
debugLog('init()');
this.updateCaches('init');
this.client.subscribe('events', (event: ImageEvent) => {
debugLog('Received events', event);
const {surfaceList} = this.props.persistedState;
const {attribution} = event;
if (attribution instanceof Array && attribution.length > 0) {
const surface = attribution[0].trim();
if (surface.length > 0) {
surfaceList.add(surface);
}
}
this.props.setPersistedState({
events: [
{eventId: this.nextEventId, ...event},
...this.props.persistedState.events,
],
});
this.nextEventId++;
});
this.client.subscribe(
'debug_overlay_event',
(event: FrescoDebugOverlayEvent) => {