Allow onExport handler to return nothing

Summary:
In many cases, the onExport handler doesn't try to customise the format, but merely fetch some additional information before creating an export.

By allowing the `onExport` handler to also return nothing, and instead merely update existing state, this case will be easier to express now;

Reviewed By: nikoant

Differential Revision: D28026558

fbshipit-source-id: 2b90b3e1ced6a6a5b42938b6f6b74b0eb9ceafc0
This commit is contained in:
Michel Weststrate
2021-04-27 14:52:34 -07:00
committed by Facebook GitHub Bot
parent c2a07e7638
commit d26ea5fa46
3 changed files with 42 additions and 11 deletions

View File

@@ -357,6 +357,27 @@ test('plugins can handle import errors', async () => {
});
test('plugins can have custom export handler', async () => {
const {exportStateAsync} = TestUtils.startPlugin({
plugin(client: PluginClient) {
const field1 = createState(0, {persist: 'field1'});
client.onExport(async () => {
await sleep(10);
return {
b: 3,
};
});
return {field1};
},
Component() {
return null;
},
});
expect(await exportStateAsync()).toEqual({b: 3});
});
test('plugins can have custom export handler that doesnt return', async () => {
const {exportStateAsync} = TestUtils.startPlugin(
{
plugin(client: PluginClient) {
@@ -364,9 +385,7 @@ test('plugins can have custom export handler', async () => {
client.onExport(async () => {
await sleep(10);
return {
b: 3,
};
field1.set(field1.get() + 1);
});
return {field1};
@@ -377,12 +396,11 @@ test('plugins can have custom export handler', async () => {
},
{
initialState: {
a: 1,
b: 2,
field1: 1,
},
},
);
expect(await exportStateAsync()).toEqual({b: 3});
expect(await exportStateAsync()).toEqual({field1: 2});
});
test('plugins can receive deeplinks', async () => {