Skip to content

Commit

Permalink
rename getTimelineByName => getActiveTimelineByName
Browse files Browse the repository at this point in the history
  • Loading branch information
jodeleeuw committed Nov 9, 2023
1 parent 7b1ae24 commit 978a4c8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/jspsych/src/JsPsych.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
16 changes: 10 additions & 6 deletions packages/jspsych/src/timeline/Timeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ describe("Timeline", () => {
});
});

describe("getTimelineByName()", () => {
describe("getActiveTimelineByName()", () => {
it("returns the timeline with the given name", async () => {
TestPlugin.setManualFinishTrialMode();

Expand All @@ -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 () => {
Expand All @@ -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
);
});
});
});
4 changes: 2 additions & 2 deletions packages/jspsych/src/timeline/Timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions packages/jspsych/src/timeline/TimelineNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion packages/jspsych/src/timeline/Trial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 978a4c8

Please sign in to comment.