From bb3749113d2b60d1dd1b19eeca94871c1075e366 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Mon, 11 Jul 2022 11:08:12 +1000 Subject: [PATCH] Add explanation about composeStepRunners --- code/lib/store/src/csf/stepRunners.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/code/lib/store/src/csf/stepRunners.ts b/code/lib/store/src/csf/stepRunners.ts index 41811c9a4bcf..318b9270ea75 100644 --- a/code/lib/store/src/csf/stepRunners.ts +++ b/code/lib/store/src/csf/stepRunners.ts @@ -1,5 +1,23 @@ import { AnyFramework, StepRunner } from '@storybook/csf'; +/** + * Compose step runners to create a single step runner that applies each step runner in order. + * + * A step runner is a a function that takes a defined step: `step('label', () => { ... })` + * and runs it. The prototypical example is from `@storybook/addon-interactions` where the + * step runner will decorate all instrumented code inside the step with information about the + * label. + * + * In theory it is possible to have more than one addon that wants to run steps; they can be + * composed together in a similar fashion to decorators. In some ways step runners are like + * decorators except it is not intended that they change the context or the play function. + * + * The basic implementation of a step runner is `async (label, play, context) => play(context)` + * -- in fact this is what `composeStepRunners([])` will do. + * + * @param stepRunners an array of StepRunner + * @returns a StepRunner that is the composition of the arguments + */ export function composeStepRunners( stepRunners: StepRunner[] ): StepRunner {