Skip to content

Commit db6b036

Browse files
authored
feat(lib): raise an event when the switch is done by the FlashPreventionPlugin (#622)
1 parent db16d15 commit db6b036

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

libs/scully-plugin-flash-prevention/src/lib/flash-prevention.plugin.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const AppRootAttrsBlacklist = ['_nghost', 'ng-version'];
1010
const MockRootAttrsBlacklist = [];
1111

1212
registerPlugin('render', FlashPrevention, flashPreventionPlugin);
13-
registerPlugin('router', FlashPrevention, async ur => [{ route: ur }]);
13+
registerPlugin('router', FlashPrevention, async (ur) => [{ route: ur }]);
1414

1515
interface FlashPreventionPluginOptions {
1616
appRootSelector?: string;
@@ -25,7 +25,7 @@ export function getFlashPreventionPlugin({
2525
appLoadedClass,
2626
appRootAttributesBlacklist,
2727
mockAttributesBlacklist,
28-
displayType
28+
displayType,
2929
}: FlashPreventionPluginOptions = {}) {
3030
if (appRootSelector) {
3131
AppRootSelector = appRootSelector;
@@ -88,7 +88,11 @@ async function addBitsToHead(html) {
8888
document.body.classList.add('${LoadedClass}');
8989
const tempAppRoot = document.querySelector('${AppRootSelector}-scully');
9090
tempAppRoot.parentNode.removeChild(tempAppRoot);
91-
window.removeEventListener('AngularReady', scullyDiscountFlashPreventionContentScript);
91+
window.removeEventListener('AngularReady', scullyDiscountFlashPreventionContentScript);
92+
window.dispatchEvent(new Event('FlashPreventionSwitchDone', {
93+
bubbles: true,
94+
cancelable: false
95+
}))
9296
}
9397
</script>
9498
<style type="text/css">
@@ -107,7 +111,7 @@ function pushItemsToArray(src, dest) {
107111
if (src.length && !Array.isArray(src)) {
108112
src = [src];
109113
}
110-
src.forEach(item => dest.push(item));
114+
src.forEach((item) => dest.push(item));
111115
}
112116
}
113117

0 commit comments

Comments
 (0)