FlipperBackgroundPlugin

Summary:
Adds a new type of plugin: `FlipperBackgroundPlugin`
Background plugins are not torn down when the user switches to another plugin so they keep receiving messages in the background.

Background plugins need to use persistedState to keep their data. To handle the messages received in the background they need to implement a static method that merges a message with the current state from redux. The plugin doesn't need to call this method itself, it is called from `client.js`.

```static persistedStateReducer = (
    persistedState: PersistedState,
    data: Object,
  ): PersistedState
```

This method is used to handle messages in both foreground and background.

Reviewed By: danielbuechele

Differential Revision: D10256305

fbshipit-source-id: d86da9caa1b75178841a9a347eb427112141eaa3
This commit is contained in:
Pritesh Nandgaonkar
2018-10-11 15:19:21 -07:00
committed by Facebook Github Bot
parent 5bbfa58909
commit ac7980993c
6 changed files with 53 additions and 61 deletions

View File

@@ -12,13 +12,8 @@ import type Logger from '../fb-stubs/Logger.js';
import type Client from '../Client.js';
export default (store: Store, logger: Logger) => {
const server = new Server(logger);
store.subscribe(() => {
let currentState = store.getState();
currentState.connections.clients.forEach((client: Client) => {
client.selectedPlugin = currentState.connections.selectedPlugin;
});
});
const server = new Server(logger, store);
server.addListener('new-client', (client: Client) => {
store.dispatch({
type: 'NEW_CLIENT',