Files
flipper/docs/background-plugin-jsside.md
Pritesh Nandgaonkar 9c96ab1565 Documentation for background plugin
Summary: Documentation for background plugin

Reviewed By: passy

Differential Revision: D10378898

fbshipit-source-id: 42f23b9464c41ee2f329301233c1e01d0ae05e95
2018-10-15 11:37:29 -07:00

1.2 KiB

id, title, sidebar_label
id title sidebar_label
background-plugin-jsside Background Plugin Setup Background Plugin

A Flipper Plugin can run in the background too. With this capability, the plugin running in the background can send messages even when the plugin is not active (i.e. the user is using some other plugin in Flipper). To prepare a Flipper plugin for running in the background, its JavaScript side should implement persistedStateReducer.

persistedStateReducer will be called whenever the JavaScript side receives data from the client. It gets two arguments: one is the current Redux store of the plugin and the second is the data received from client. The function returns the state with which the plugin should get updated. For more info follow the network plugin

export default class extends FlipperPlugin {
  static persistedStateReducer = (
    persistedState: PersistedState,
    data: Data,
  ): PersistedState => {
    // Logic to merge current state with new data
  };
}

You will also have to make the plugin opt in to run in the background from native side too. For more info around this, read the mobile setup.