Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect dynamically added trial/timeline descriptions #3426

Merged
merged 15 commits into from
Nov 20, 2024

Conversation

bjoluc
Copy link
Member

@bjoluc bjoluc commented Nov 3, 2024

Prior to this, trials (or nested timelines) that were added to a timeline description while the experiment was running would be ignored. This PR makes Timeline objects instantiate their child nodes incrementally before running them, thus accounting for dynamically added/removed trials and timelines.

Closes #3379.


While I'm confident in the implementation, I'm submitting this as a draft for now because it lacks docs updates and a changeset (for which I don't have time ATM). @jspsych/core Feel free to complete this and release it!

I'm also not sure to which extent modifications to a JS array are reflected while iterating over it in a for ... of loop – it would be interesting to toy around with this a bit. Pushing elements to the end obviously works (and is the primary use case anyway), but what about removing elements prior to the current one? Index-based iteration would skip an element then – but maybe for ... of doesn't?

Copy link

changeset-bot bot commented Nov 3, 2024

🦋 Changeset detected

Latest commit: 8665717

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
jspsych Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cherriechang cherriechang marked this pull request as ready for review November 5, 2024 17:16
docs/overview/timeline.md Outdated Show resolved Hide resolved
docs/overview/timeline.md Outdated Show resolved Hide resolved
docs/overview/timeline.md Outdated Show resolved Hide resolved
expect(timeline.children.length).toEqual(2);
});

it("respects dynamically added child node descriptions at the start", async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this test makes sense. I think it will run the same exact trial twice, because of the runtime insertion stuff we looked at before.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I just tested it and you're right. should i just delete it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the additional tests might have been helpful to find out how this behaves, I think they all boil down to testing runtime behavior of the list iteration – and are rather complicated for that. Technically, the "respects dynamically added child node descriptions" case should be all it needs to check that the Timeline class dynamically creates trials one by one – the rest is up to the runtime. I'd prefer to keep the unit tests as slim as possible here (without sacrificing coverage). Sorry for involving into this again 🙊

@jodeleeuw jodeleeuw merged commit bd3ed55 into main Nov 20, 2024
4 checks passed
@jodeleeuw jodeleeuw deleted the feat-dynamic-timeline-descriptions branch November 20, 2024 18:48
@github-actions github-actions bot mentioned this pull request Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[jspsych.org v8 docs] Deprecated function jsPsych.addNodeToEndOfTimeline() listed in the reference
3 participants