aboutsummaryrefslogtreecommitdiff
path: root/src/shared/messages.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-04-30 21:50:46 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2019-05-02 11:14:19 +0900
commit0cffb09e249832291be73be039dc1b9bb38115f9 (patch)
tree3b8783d7a8185ca1524d7b2f9231e43104121204 /src/shared/messages.ts
parent2b8c37e57f1b55dcb562ccf9141ae29bac0e370a (diff)
Types on src/share
Diffstat (limited to 'src/shared/messages.ts')
-rw-r--r--src/shared/messages.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/shared/messages.ts b/src/shared/messages.ts
index ddf3368..2bc12d8 100644
--- a/src/shared/messages.ts
+++ b/src/shared/messages.ts
@@ -1,5 +1,8 @@
-const onWebMessage = (listener) => {
- window.addEventListener('message', (event) => {
+type WebMessageSender = Window | MessagePort | ServiceWorker | null;
+type WebMessageListener = (msg: any, sender: WebMessageSender | null) => void;
+
+const onWebMessage = (listener: WebMessageListener) => {
+ window.addEventListener('message', (event: MessageEvent) => {
let sender = event.source;
let message = null;
try {
@@ -12,11 +15,15 @@ const onWebMessage = (listener) => {
});
};
-const onBackgroundMessage = (listener) => {
+const onBackgroundMessage = (
+ listener: (msg: any, sender: browser.runtime.MessageSender,
+) => void) => {
browser.runtime.onMessage.addListener(listener);
};
-const onMessage = (listener) => {
+const onMessage = (
+ listener: (msg: any, sender: WebMessageSender | browser.runtime.MessageSender,
+) => void) => {
onWebMessage(listener);
onBackgroundMessage(listener);
};