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

Allow message_progress_bar to be a function #3201

Merged
merged 8 commits into from
Feb 2, 2024

Conversation

Shaobin-Jiang
Copy link
Contributor

I have encountered this situation many times when I want to update the progress bar message when the progress bar updates, but the only way of doing it before is manually changing the innerHTML in an on_finish function of a trial. Therefore, I think we should allow users to set message_progress_bar as a function that returns the progress, so that the message gets updated automatically.

For example:

const jsPsych = initJsPsych({
    show_progress_bar: true,
    auto_update_progress_bar: true,
    message_progress_bar: (progress) => `Current progress: ${progress * 100}%`
});

Copy link

changeset-bot bot commented Jan 2, 2024

🦋 Changeset detected

Latest commit: 4cb77e8

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

@jodeleeuw
Copy link
Member

Thanks @Shaobin-Jiang! This seems useful to me.

@jspsych/core what do you think about having message_progress_bar be a string or function? Should it just be a function?

@Shaobin-Jiang
Copy link
Contributor Author

I personally think message_progress_bar could either be a string or a function. There must be many who are happy with displaying just an unchanging message along side with the progress bar. Also I believe in this way message_progress_bar can behave like a dynamic parameter.

@jodeleeuw jodeleeuw added this to the 8.0 milestone Jan 3, 2024
@bjoluc
Copy link
Member

bjoluc commented Jan 9, 2024

I tend to agree with @Shaobin-Jiang. Also, supporting both really doesn't add much complexity implementation-wise.

Copy link
Member

@bjoluc bjoluc left a comment

Choose a reason for hiding this comment

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

I've added some review comments – @Shaobin-Jiang let me know if you'd like to address them or if I should quickly do the changes. Also, the function parameter is lacking a unit test 🙃

.changeset/stupid-baboons-wait.md Outdated Show resolved Hide resolved
packages/jspsych/src/ProgressBar.ts Outdated Show resolved Hide resolved
packages/jspsych/src/ProgressBar.ts Outdated Show resolved Hide resolved
- adding a private `updateMessage` method
- using a simpler version of checking function type
@Shaobin-Jiang
Copy link
Contributor Author

Unit test is added as requested @bjoluc

@bjoluc bjoluc merged commit 233deb6 into jspsych:v8 Feb 2, 2024
1 check passed
@Shaobin-Jiang Shaobin-Jiang deleted the message-progress-bar branch February 3, 2024 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants