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:
committed by
Facebook Github Bot
parent
1a5b127d58
commit
6df906ed5f
@@ -24,10 +24,22 @@ export type PluginClient = {|
|
||||
|
||||
type PluginTarget = BaseDevice | Client;
|
||||
|
||||
export type Notification = {|
|
||||
title: string,
|
||||
message: string,
|
||||
severity: 'warning' | 'error',
|
||||
timestamp?: number,
|
||||
category?: string,
|
||||
action?: string,
|
||||
|};
|
||||
|
||||
export type NotificationSet = {[id: string]: Notification};
|
||||
|
||||
export type Props<T> = {
|
||||
logger: Logger,
|
||||
persistedState: T,
|
||||
setPersistedState: (state: $Shape<T>) => void,
|
||||
setActiveNotifications: NotificationSet => void,
|
||||
target: PluginTarget,
|
||||
};
|
||||
|
||||
@@ -63,6 +75,9 @@ export class FlipperBasePlugin<
|
||||
// methods to be overriden by plugins
|
||||
init(): void {}
|
||||
teardown(): void {}
|
||||
computeNotifications(props: Props<*>, state: State): NotificationSet {
|
||||
return {};
|
||||
}
|
||||
// methods to be overridden by subclasses
|
||||
_init(): void {}
|
||||
_teardown(): void {}
|
||||
@@ -82,6 +97,10 @@ export class FlipperBasePlugin<
|
||||
throw new TypeError(`Reducer ${actionData.type} isn't a function`);
|
||||
}
|
||||
}
|
||||
|
||||
componentDidUpdate(props: Props<*>, state: State): void {
|
||||
props.setActiveNotifications(this.computeNotifications(props, state));
|
||||
}
|
||||
}
|
||||
|
||||
export class FlipperDevicePlugin<S = *, A = *, P = *> extends FlipperBasePlugin<
|
||||
|
||||
Reference in New Issue
Block a user