diff --git a/docs/extending/client-plugin-lifecycle.mdx b/docs/extending/client-plugin-lifecycle.mdx index aaf6c7681..4cdee5285 100644 --- a/docs/extending/client-plugin-lifecycle.mdx +++ b/docs/extending/client-plugin-lifecycle.mdx @@ -4,20 +4,25 @@ title: Client Plugin Lifecycle --- import useBaseUrl from '@docusaurus/useBaseUrl'; -There are two types of client plugin: Regular and Background plugins. We recommend starting off as a regular plugin and switching it to a background plugin if necessary. +There are two types of client plugin: [Regular](#regular-plugin-lifecycle) and [Background](#background-plugin-lifecycle). It's recommended you start off with a regular plugin and switch to a background plugin if necessary. -For both types of plugin, we recommend starting work after `onConnect` is called and terminating it after `onDisconnect`, when possible. This prevents wasted computation when Flipper isn't connected. If the plugin needs to keep track of events that occur before it gets connected (such as initial network requests on app startup), you should do so in the plugin constructor (or ideally in a separate class). +For both types of plugin, it's recommended you start work after the `onConnect` is called then terminate work after `onDisconnect`, when possible. This prevents wasted computation when Flipper isn't connected. If the plugin needs to keep track of events that occur before it gets connected (such as initial network requests on app startup), you should do so in the plugin constructor (or ideally in a separate class). + +## Regular plugin Lifecycle -## Regular Plugin Lifecycle For regular plugins, `onConnect` and `onDisconnect` are triggered when the user opens the plugin in the Flipper UI, and when they switch to another plugin, respectively. +The process is illustrated in the following diagram. + Regular Plugin Lifecycle diagram ## Background Plugin Lifecycle + For background plugins, `onConnect` is called when Flipper first connects, and `onDisconnect` when it disconnects. The user does not need to be viewing the plugin for it to send messages; they will be queued up until the next time the user opens the plugin where they will be processed. -Even for background plugins, `onDisconnect` and `onConnect` may be called on a plugin (e.g., if the user restarts Flipper). Plugins should handle this accordingly by making sure to resend any important data to the reconnected instance. -
+Even for background plugins, `onDisconnect` and `onConnect` may be called on a plugin (such as if the user restarts Flipper). Plugins should handle this accordingly by making sure to resend any important data to the reconnected instance. The process is illustrated in the following diagram. + +:::warning Note that a plugin must be enabled by the user for its messages to be queued up. -
+::: Background Plugin Lifecycle diagram diff --git a/website/static/img/bg-plugin-lifecycle.bak b/website/static/img/bg-plugin-lifecycle.bak new file mode 100644 index 000000000..9151fa78d Binary files /dev/null and b/website/static/img/bg-plugin-lifecycle.bak differ diff --git a/website/static/img/bg-plugin-lifecycle.png b/website/static/img/bg-plugin-lifecycle.png index 9151fa78d..dad63bbd3 100644 Binary files a/website/static/img/bg-plugin-lifecycle.png and b/website/static/img/bg-plugin-lifecycle.png differ diff --git a/website/static/img/regular-plugin-lifecycle.bak b/website/static/img/regular-plugin-lifecycle.bak new file mode 100644 index 000000000..44aac2a43 Binary files /dev/null and b/website/static/img/regular-plugin-lifecycle.bak differ diff --git a/website/static/img/regular-plugin-lifecycle.png b/website/static/img/regular-plugin-lifecycle.png index 44aac2a43..a8a58ce0f 100644 Binary files a/website/static/img/regular-plugin-lifecycle.png and b/website/static/img/regular-plugin-lifecycle.png differ