Support custom data processing during import

Summary: Per title, this allows for pre-processing data after it is deserialized and before it is stored in the plugin

Reviewed By: nikoant

Differential Revision: D26126423

fbshipit-source-id: bc08a6ab205d2a0d551515563cd85a197595ddb2
This commit is contained in:
Michel Weststrate
2021-02-01 11:40:20 -08:00
committed by Facebook GitHub Bot
parent 34c915a739
commit f2ade40239
9 changed files with 340 additions and 21 deletions

View File

@@ -73,16 +73,7 @@ export function createState<T>(
): Atom<T> {
const atom = new AtomValue<T>(initialValue);
if (getCurrentPluginInstance() && options.persist) {
const {initialStates, rootStates} = getCurrentPluginInstance()!;
if (initialStates) {
if (options.persist in initialStates) {
atom.set(initialStates[options.persist]);
} else {
console.warn(
`Tried to initialize plugin with existing data, however data for "${options.persist}" is missing. Was the export created with a different Flipper version?`,
);
}
}
const {rootStates} = getCurrentPluginInstance()!;
if (rootStates[options.persist]) {
throw new Error(
`Some other state is already persisting with key "${options.persist}"`,