From e3f88e2a7ba6a45fc2795df5ac6c29c231c8d5dc Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Thu, 20 Jun 2019 03:46:26 -0700 Subject: [PATCH] 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 --- src/plugins/fresco/__tests__/index.node.js | 2 ++ src/plugins/fresco/index.js | 40 ++++++++++++---------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/plugins/fresco/__tests__/index.node.js b/src/plugins/fresco/__tests__/index.node.js index 8872efe2c..00e243094 100644 --- a/src/plugins/fresco/__tests__/index.node.js +++ b/src/plugins/fresco/__tests__/index.node.js @@ -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, }; diff --git a/src/plugins/fresco/index.js b/src/plugins/fresco/index.js index a2527892f..641145491 100644 --- a/src/plugins/fresco/index.js +++ b/src/plugins/fresco/index.js @@ -42,6 +42,7 @@ export type PersistedState = { imagesMap: ImagesMap, closeableReferenceLeaks: Array, isLeakTrackingEnabled: boolean, + nextEventId: number, }; type PluginState = { @@ -88,6 +89,7 @@ export default class extends FlipperPlugin { surfaceList: new Set(), closeableReferenceLeaks: [], isLeakTrackingEnabled: false, + nextEventId: 0, }; static exportPersistedState = ( @@ -156,6 +158,26 @@ export default class extends FlipperPlugin { 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 { 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) => {