refactor: remove unnecessary arrow function wrap

- add installed handler
This commit is contained in:
DecentM 2018-02-03 23:17:24 +01:00
parent 90399c53a8
commit 6853158790
No known key found for this signature in database
GPG Key ID: 6BDA2D2BC5EA5B10

View File

@ -30,8 +30,7 @@
}); });
}; };
const attachInstalledListeners = () => { const installedHandler = event => {
window.addEventListener('message', event => {
if ( if (
event.data event.data
&& event.data.type === 'ouc-is-installed' && event.data.type === 'ouc-is-installed'
@ -53,7 +52,10 @@
sendInstalledCallback(callbackObject); sendInstalledCallback(callbackObject);
}); });
} }
}); };
const attachInstalledListeners = () => {
window.addEventListener('message', installedHandler);
}; };
const doHandshake = () => { const doHandshake = () => {
@ -102,9 +104,7 @@
}); });
}; };
const attachHandshakeListeners = () => { const handshakeHandler = event => {
// Wait for the handshake request, then start it
window.addEventListener('message', event => {
if ( if (
event.data event.data
&& event.data.type === 'ouc-handshake-question' && event.data.type === 'ouc-handshake-question'
@ -112,7 +112,11 @@
) { ) {
doHandshake(); doHandshake();
} }
}); };
const attachHandshakeListeners = () => {
// Wait for the handshake request, then start it
window.addEventListener('message', handshakeHandler);
}; };
const sendInstallCallback = data => { const sendInstallCallback = data => {
@ -124,9 +128,7 @@
}); });
}; };
const attachInstallListeners = () => { const installHandler = event => {
// Wait for an install event, then save the theme
window.addEventListener('message', event => {
if ( if (
event.data event.data
&& event.data.type === 'ouc-install-usercss' && event.data.type === 'ouc-install-usercss'
@ -144,13 +146,19 @@
}); });
}); });
} }
});
}; };
(() => { const attachInstallListeners = () => {
// Wait for an install event, then save the theme
window.addEventListener('message', installHandler);
};
window.removeEventListener('message', installHandler);
window.removeEventListener('message', handshakeHandler);
window.removeEventListener('message', installedHandler);
attachHandshakeListeners(); attachHandshakeListeners();
attachInstallListeners(); attachInstallListeners();
attachInstalledListeners(); attachInstalledListeners();
askHandshake(); askHandshake();
})();
})(); })();