Add computeNotifications method to FlipperBasePlugin

Summary:
Method `computeNotifications` added to the base plugin class.
Plugins should implement this to define a mapping from their state+props to the notifications they are emitting.

I've plugged this into componentDidUpdate, because we don't yet have the background plugin infra. When we do, we'll want some other incoming data hook to use so it's not tied to the react component rendering.

Example usage added to network plugin in the next commit.

Reviewed By: passy

Differential Revision: D10127875

fbshipit-source-id: efd4d8cfc0d3d33852a6cf9a290549a5f90d389d
This commit is contained in:
John Knox
2018-10-09 08:22:22 -07:00
committed by Facebook Github Bot
parent 1a5b127d58
commit 6df906ed5f
4 changed files with 148 additions and 2 deletions

View File

@@ -22,6 +22,8 @@ import {
import React from 'react';
import {connect} from 'react-redux';
import {setPluginState} from './reducers/pluginStates.js';
import {setActiveNotifications} from './reducers/notifications.js';
import type {NotificationSet} from './plugin.js';
import {devicePlugins} from './device-plugins/index.js';
import plugins from './plugins/index.js';
import {activateMenuItems} from './MenuBar.js';
@@ -52,6 +54,10 @@ type Props = {
pluginKey: string,
state: Object,
}) => void,
setActiveNotifications: ({
pluginId: string,
notifications: NotificationSet,
}) => void,
};
type State = {
@@ -124,7 +130,7 @@ class PluginContainer extends Component<Props, State> {
};
render() {
const {pluginStates, setPluginState} = this.props;
const {pluginStates, setPluginState, setActiveNotifications} = this.props;
const {activePlugin, pluginKey, target} = this.state;
if (!activePlugin || !target) {
@@ -136,6 +142,11 @@ class PluginContainer extends Component<Props, State> {
logger: this.props.logger,
persistedState: pluginStates[pluginKey] || {},
setPersistedState: state => setPluginState({pluginKey, state}),
setActiveNotifications: notifications =>
setActiveNotifications({
pluginId: pluginKey,
notifications: notifications,
}),
target,
ref: this.refChanged,
};
@@ -171,5 +182,6 @@ export default connect(
}),
{
setPluginState,
setActiveNotifications,
},
)(PluginContainer);