From 9edfe88caa5626b07d3b23ed79b5e073ea0d1448 Mon Sep 17 00:00:00 2001 From: John Knox Date: Fri, 9 Aug 2019 08:58:19 -0700 Subject: [PATCH] Convert notifications dispatcher to TS Summary: Convert notifications dispatcher to TS Reviewed By: danielbuechele Differential Revision: D16689175 fbshipit-source-id: 7806d5452a57566ea3d6fdfd233a1679435e0103 --- .../{notifications.js => notifications.tsx} | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) rename src/dispatcher/{notifications.js => notifications.tsx} (83%) diff --git a/src/dispatcher/notifications.js b/src/dispatcher/notifications.tsx similarity index 83% rename from src/dispatcher/notifications.js rename to src/dispatcher/notifications.tsx index f9af40e73..b10c47c4e 100644 --- a/src/dispatcher/notifications.js +++ b/src/dispatcher/notifications.tsx @@ -5,20 +5,20 @@ * @format */ -import type {Store} from '../reducers/index.tsx'; -import type {Logger} from '../fb-interfaces/Logger.js'; -import type {PluginNotification} from '../reducers/notifications.tsx'; -import type {FlipperPlugin, FlipperDevicePlugin} from '../plugin.tsx'; +import {Store} from '../reducers/index'; +import {Logger} from '../fb-interfaces/Logger.js'; +import {PluginNotification} from '../reducers/notifications'; +import {FlipperPlugin, FlipperDevicePlugin} from '../plugin'; import isHeadless from '../utils/isHeadless.js'; import {ipcRenderer} from 'electron'; -import {selectPlugin} from '../reducers/connections.tsx'; +import {selectPlugin} from '../reducers/connections'; import { setActiveNotifications, updatePluginBlacklist, updateCategoryBlacklist, -} from '../reducers/notifications.tsx'; +} from '../reducers/notifications'; import {textContent} from '../utils/index'; -import GK from '../fb-stubs/GK.tsx'; +import GK from '../fb-stubs/GK'; type NotificationEvents = 'show' | 'click' | 'close' | 'reply' | 'action'; const NOTIFICATION_THROTTLE = 5 * 1000; // in milliseconds @@ -85,19 +85,21 @@ export default (store: Store, logger: Logger) => { store.subscribe(() => { const {notifications, pluginStates} = store.getState(); - const clientPlugins: Map>> = store.getState() + const clientPlugins: Map = store.getState() .plugins.clientPlugins; const devicePlugins: Map< string, - Class>, + typeof FlipperDevicePlugin > = store.getState().plugins.devicePlugins; const pluginMap: Map< string, - Class | FlipperDevicePlugin<>>, - //$FlowFixMe Flow complains that FlipperPlugin and FlipperDevicePlugin are incompatible, where as we have already mentioned the type of the class it can take in the type - > = new Map([...clientPlugins, ...devicePlugins]); + typeof FlipperPlugin | typeof FlipperDevicePlugin + > = new Map([ + ...clientPlugins, + ...devicePlugins, + ]); Object.keys(pluginStates).forEach(key => { if (knownPluginStates.get(key) !== pluginStates[key]) { @@ -105,9 +107,9 @@ export default (store: Store, logger: Logger) => { const split = key.split('#'); const pluginId = split.pop(); const client = split.join('#'); - const persistingPlugin: ?Class< - FlipperPlugin<> | FlipperDevicePlugin<>, - > = pluginMap.get(pluginId); + const persistingPlugin: + | typeof FlipperPlugin + | typeof FlipperDevicePlugin = pluginMap.get(pluginId); if (persistingPlugin && persistingPlugin.getActiveNotifications) { store.dispatch( setActiveNotifications({ @@ -153,6 +155,7 @@ export default (store: Store, logger: Logger) => { ipcRenderer.send('sendNotification', { payload: { title: n.notification.title, + // @ts-ignore Remove this when textContent is converted to tsx body: textContent(n.notification.message), actions: [ { @@ -165,7 +168,7 @@ export default (store: Store, logger: Logger) => { }, { type: 'button', - text: `Hide all ${pluginMap.get(n.pluginId)?.title || ''}`, + text: `Hide all ${pluginMap.get(n.pluginId).title || ''}`, }, ], closeButtonText: 'Hide',