diff --git a/packages/jspsych/src/JsPsych.ts b/packages/jspsych/src/JsPsych.ts index e1587739f2..b9f34911ab 100644 --- a/packages/jspsych/src/JsPsych.ts +++ b/packages/jspsych/src/JsPsych.ts @@ -214,7 +214,7 @@ export class JsPsych { * @param name The name of the timeline to abort. Timelines can be given names by setting the `name` parameter in the description of the timeline. */ abortTimelineByName(name: string): void { - const timeline = this.timeline?.getTimelineByName(name); + const timeline = this.timeline?.getActiveTimelineByName(name); if (timeline) { timeline.abort(); } diff --git a/packages/jspsych/src/timeline/Timeline.spec.ts b/packages/jspsych/src/timeline/Timeline.spec.ts index dd333c84a1..b94f595f98 100644 --- a/packages/jspsych/src/timeline/Timeline.spec.ts +++ b/packages/jspsych/src/timeline/Timeline.spec.ts @@ -865,7 +865,7 @@ describe("Timeline", () => { }); }); - describe("getTimelineByName()", () => { + describe("getActiveTimelineByName()", () => { it("returns the timeline with the given name", async () => { TestPlugin.setManualFinishTrialMode(); @@ -876,8 +876,10 @@ describe("Timeline", () => { timeline.run(); - expect(timeline.getTimelineByName("outerTimeline")).toBe(timeline); - expect(timeline.getTimelineByName("innerTimeline")).toBe(timeline.children[0] as Timeline); + expect(timeline.getActiveTimelineByName("outerTimeline")).toBe(timeline); + expect(timeline.getActiveTimelineByName("innerTimeline")).toBe( + timeline.children[0] as Timeline + ); }); it("returns only active timelines", async () => { @@ -893,12 +895,14 @@ describe("Timeline", () => { timeline.run(); - expect(timeline.getTimelineByName("outerTimeline")).toBe(timeline); - expect(timeline.getTimelineByName("innerTimeline")).toBeUndefined(); + expect(timeline.getActiveTimelineByName("outerTimeline")).toBe(timeline); + expect(timeline.getActiveTimelineByName("innerTimeline")).toBeUndefined(); await TestPlugin.finishTrial(); - expect(timeline.getTimelineByName("innerTimeline")).toBe(timeline.children[1] as Timeline); + expect(timeline.getActiveTimelineByName("innerTimeline")).toBe( + timeline.children[1] as Timeline + ); }); }); }); diff --git a/packages/jspsych/src/timeline/Timeline.ts b/packages/jspsych/src/timeline/Timeline.ts index 216764b256..8628f60324 100644 --- a/packages/jspsych/src/timeline/Timeline.ts +++ b/packages/jspsych/src/timeline/Timeline.ts @@ -332,11 +332,11 @@ export class Timeline extends TimelineNode { return this.currentChild?.getLatestNode() ?? this; } - public getTimelineByName(name: string) { + public getActiveTimelineByName(name: string) { if (this.description.name === name) { return this; } - return this.currentChild?.getTimelineByName(name); + return this.currentChild?.getActiveTimelineByName(name); } } diff --git a/packages/jspsych/src/timeline/TimelineNode.ts b/packages/jspsych/src/timeline/TimelineNode.ts index 6f73552c08..ee24e8e94c 100644 --- a/packages/jspsych/src/timeline/TimelineNode.ts +++ b/packages/jspsych/src/timeline/TimelineNode.ts @@ -70,9 +70,9 @@ export abstract class TimelineNode { abstract getLatestNode(): TimelineNode; /** - * Returns a child timeline (or itself) that matches the given name, or `undefined` if no such child exists. + * Returns an active child timeline (or itself) that matches the given name, or `undefined` if no such child exists. */ - abstract getTimelineByName(name: string): Timeline | undefined; + abstract getActiveTimelineByName(name: string): Timeline | undefined; protected status = TimelineNodeStatus.PENDING; diff --git a/packages/jspsych/src/timeline/Trial.ts b/packages/jspsych/src/timeline/Trial.ts index 866f6fc90d..74892e1354 100644 --- a/packages/jspsych/src/timeline/Trial.ts +++ b/packages/jspsych/src/timeline/Trial.ts @@ -379,7 +379,7 @@ export class Trial extends TimelineNode { return this; } - public getTimelineByName(name: string): Timeline | undefined { + public getActiveTimelineByName(name: string): Timeline | undefined { // This returns undefined because the function is looking // for a timeline. If we get to this point, then none // of the parent nodes match the name.