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

@@ -149,11 +149,13 @@ Trigger when the users navigates to this plugin using a deeplink, either from an
Usage: `client.onExport(callback: (idler, onStatusMessage) => Promise<state>)`
Overrides the default serialization behavior of this plugin. Should return a promise with persistable state that is to be stored.
Overrides the default serialization behavior of this plugin. Should return a promise with persistable state that is to be stored, or nothing at all.
This process is async, so it is possible to first fetch some additional state from the device.
Serializable is defined as: non-cyclic data, consisting purely of primitive values, plain objects, arrays or Date, Set or Map objects.
If nothing is returned, the handler will be run, and after the handler has finished the `persist` keys of the different states will be used as export basis.
#### `onImport`
Usage: `client.onImport(callback: (snapshot) => void)`