Restore computeNotifications

Summary:
Restore the logic for setting and computing notifications that was
partially removed with D10300838.

Reviewed By: jknoxville

Differential Revision: D10361547

fbshipit-source-id: 4d229d5f4dbeda3139463e1c348909b9c5dba66f
This commit is contained in:
Pascal Hartig
2018-10-13 04:16:12 -07:00
committed by Facebook Github Bot
parent 4889f5dc6a
commit 01020edbf2
4 changed files with 37 additions and 17 deletions

View File

@@ -24,10 +24,21 @@ export type PluginClient = {|
type PluginTarget = BaseDevice | Client;
export type Notification = {|
id: string,
title: string,
message: string,
severity: 'warning' | 'error',
timestamp?: number,
category?: string,
action?: string,
|};
export type Props<T> = {
logger: Logger,
persistedState: T,
setPersistedState: (state: $Shape<T>) => void,
setActiveNotifications: (Array<Notification>) => void,
target: PluginTarget,
deepLinkPayload: ?string,
};
@@ -64,6 +75,9 @@ export class FlipperBasePlugin<
// methods to be overriden by plugins
init(): void {}
teardown(): void {}
computeNotifications(props: Props<*>, state: State): Array<Notification> {
return [];
}
// methods to be overridden by subclasses
_init(): void {}
_teardown(): void {}
@@ -83,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<