From 622d3ee3f08ceffad4a5f73187db6a56972a8102 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Thu, 2 Jan 2020 07:12:06 -0800 Subject: [PATCH] Fix plugin state serialization Summary: Because the recordSourceUpdates where stored in Map instances, they were never serialized when exporting the data to flipper. (JSON.stringify doesn't support Map's). Although Flipper's own serializer does support maps (which is what you get when not overriding these static methods), the Flipper serializer is really slow, which made the export unusable. ~~The reason this became a problem is that in the new message architecture plugin snapshots serialize the events and apply them only when the plugin is opened, rather than doing it immediately when they are received. However, to be able to apply the events, the recordSource should be available. Before this change, this would throw exceptions when viewing the plugin in an imported flipper trace, as this recordSourceUpdates aren't available anymore.~~ The events are processed *before* the export now, so this is no longer a deal breaker, but it is still an improvement, as it will make the data available in the Flipper exports / imports, and fixed the following error that would occur when opening the store page in an flipper import: {F225365428} Reviewed By: jonathoma Differential Revision: D19178158 fbshipit-source-id: f2bc0a05b02dd2fbd1029d472beeb614dded2dd3 --- src/plugin.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/plugin.tsx b/src/plugin.tsx index 8b4ce0f2d..2b3395ad3 100644 --- a/src/plugin.tsx +++ b/src/plugin.tsx @@ -138,6 +138,7 @@ export abstract class FlipperBasePlugin< // methods to be overriden by plugins init(): void {} + static serializePersistedState: ( persistedState: StaticPersistedState, statusUpdate?: (msg: string) => void, @@ -156,20 +157,25 @@ export abstract class FlipperBasePlugin< pluginName != null ? `Serializing ${pluginName}` : undefined, ); }; + static deserializePersistedState: ( serializedString: string, ) => StaticPersistedState = (serializedString: string) => { return deserialize(serializedString); }; + teardown(): void {} + computeNotifications( _props: Props, _state: State, ): Array { return []; } + // methods to be overridden by subclasses _init(): void {} + _teardown(): void {} dispatchAction(actionData: Actions) {