|
| 1 | +import Events from "@storybook/core-events"; |
| 2 | +import { addons } from "@storybook/addons"; |
1 | 3 | import { instrument } from "@storybook/instrumenter"; |
2 | | -import { addInteractionWrapper, globals, setInteractorScope } from "@interactors/globals"; |
| 4 | +import { addInteractionWrapper } from "@interactors/globals"; |
3 | 5 |
|
4 | 6 | // NOTE: Dummy call to initialize instrumenter. See: https://github.com/storybookjs/storybook/blob/next/lib/instrumenter/src/instrumenter.ts#L512 |
5 | 7 | instrument({}); |
6 | 8 |
|
7 | 9 | let isRoot = true; |
8 | 10 |
|
9 | | -addInteractionWrapper((interaction, next) => { |
| 11 | +addInteractionWrapper((perform, interaction) => { |
10 | 12 | if (!isRoot) { |
11 | | - return next; |
| 13 | + return perform; |
12 | 14 | } |
13 | 15 | return async () => { |
| 16 | + const channel = addons.getChannel(); |
14 | 17 | const cancel = (event) => { |
15 | 18 | if (!event.newPhase || event.newPhase == "aborted" || event.newPhase == "errored") { |
16 | | - __STORYBOOK_ADDONS_CHANNEL__.off("forceRemount", cancel); |
17 | | - __STORYBOOK_ADDONS_CHANNEL__.off("storyRenderPhaseChanged", cancel); |
18 | | - interaction.catchHalt(); |
| 19 | + channel.off(Events.FORCE_REMOUNT, cancel); |
| 20 | + channel.off(Events.STORY_RENDER_PHASE_CHANGED, cancel); |
19 | 21 | interaction.halt(); |
20 | 22 | isRoot = true; |
21 | 23 | } |
22 | 24 | }; |
23 | | - __STORYBOOK_ADDONS_CHANNEL__.on("forceRemount", cancel); |
24 | | - __STORYBOOK_ADDONS_CHANNEL__.on("storyRenderPhaseChanged", cancel); |
| 25 | + channel.on(Events.FORCE_REMOUNT, cancel); |
| 26 | + channel.on(Events.STORY_RENDER_PHASE_CHANGED, cancel); |
25 | 27 | try { |
26 | 28 | return await global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__.track( |
27 | | - interaction.options.code(), |
28 | | - next, |
| 29 | + interaction.code(), |
| 30 | + perform, |
29 | 31 | [], |
30 | | - { |
31 | | - intercept: () => !(isRoot = false), |
32 | | - } |
| 32 | + { intercept: () => !(isRoot = false) } |
33 | 33 | ); |
34 | 34 | } finally { |
35 | 35 | isRoot = true; |
36 | | - __STORYBOOK_ADDONS_CHANNEL__.off("forceRemount", cancel); |
37 | | - __STORYBOOK_ADDONS_CHANNEL__.off("storyRenderPhaseChanged", cancel); |
| 36 | + channel.off(Events.FORCE_REMOUNT, cancel); |
| 37 | + channel.off(Events.STORY_RENDER_PHASE_CHANGED, cancel); |
38 | 38 | } |
39 | 39 | }; |
40 | 40 | }); |
0 commit comments