StepWhen class
Represents a conditional step that evaluates a predicate to determine its outcome.
Signature:
typescript
export declare class StepWhen<P = StepBuilder, C = unknown, O = boolean> extends Step<P, C, O>Extends: Step<P, C, O>
Remarks
This step evaluates a predicate, which can be a boolean value or a resolvable that resolves to a boolean. The result of the predicate evaluation is stored in the output.
Example 1
Filter posts by like count:
ts
await Trotsky.init(agent)
.searchPosts({ q: "typescript" })
.take(20)
.each()
.when((step) => step?.context?.likeCount > 10)
.like()
.run()Example 2
Conditional following:
ts
await Trotsky.init(agent)
.actor("myhandle.bsky.social")
.followers()
.each()
.when((step) => !step?.context?.viewer?.following)
.follow()
.wait(2000)
.run()Constructors
Constructor | Modifiers | Description |
|---|---|---|
Creates an instance of |
Methods
Method | Modifiers | Description |
|---|---|---|
Evaluates the predicate and sets the output to its result. | ||
Clones the current step and returns a new instance with the same parameters. |