Support export data

Summary:
Made Sandy plugins part of the export / import logic

Note that in the export format there is now a `pluginStates2` field. It could have been put in `pluginStates` as well, but I started with that and it felt very weird, as the `pluginStates` are supposed to reflect what is living in the Redux stores, where sandy state doesn't live in the Redux store (not directly at least). Trying to store it in the same field made things overcomplicated and confusing.

Reviewed By: jknoxville

Differential Revision: D22432769

fbshipit-source-id: d9858e561fad4fadbf0f90858874ed444e3a836c
This commit is contained in:
Michel Weststrate
2020-07-14 09:04:59 -07:00
committed by Facebook GitHub Bot
parent 0e4a6d659b
commit 44f99eb304
8 changed files with 315 additions and 93 deletions

View File

@@ -291,6 +291,20 @@ export default class Client extends EventEmitter {
});
}
initFromImport(initialStates: Record<string, Record<string, any>>): this {
this.plugins.forEach((pluginId) => {
const plugin = this.getPlugin(pluginId);
if (isSandyPlugin(plugin)) {
// TODO: needs to be wrapped in error tracking T68955280
this.sandyPluginStates.set(
plugin.id,
new SandyPluginInstance(this, plugin, initialStates[pluginId]),
);
}
});
return this;
}
// get the supported plugins
async loadPlugins(): Promise<Plugins> {
const plugins = await this.rawCall<{plugins: Plugins}>(
@@ -327,7 +341,6 @@ export default class Client extends EventEmitter {
!this.sandyPluginStates.has(plugin.id)
) {
// TODO: needs to be wrapped in error tracking T68955280
// TODO: pick up any existing persisted state T68683449
this.sandyPluginStates.set(
plugin.id,
new SandyPluginInstance(this, plugin),
@@ -345,7 +358,6 @@ export default class Client extends EventEmitter {
const instance = this.sandyPluginStates.get(pluginId);
if (instance) {
instance.destroy();
// TODO: make sure persisted state is writtenT68683449
this.sandyPluginStates.delete(pluginId);
}
}