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

ref: Check config at trial level #357

Merged
merged 104 commits into from
Dec 13, 2023
Merged

Conversation

RobertGemmaJr
Copy link
Member

@RobertGemmaJr RobertGemmaJr commented Dec 12, 2023

What's Changed

  • The config checks are done at the trial level, not inside photodiodeGhostBox and pdSpotEncode
  • Tasks that are functions are made constants wherever possible
  • Tasks that must be function are renamed as build___Trial
  • Tasks that are constants are renamed as ___Trial
  • Fixes the parameters to pdSpotZEncode when it's being called
  • Removes export default from trial files

Reasoning

config Responsibility

This is one that I'm not entire sure which is better. I've chosen to have the trials check the config object rather than internal lib functions - photodiodeGhostBox and pdSpotEncode.

Part of the purpose/magic of HC is that it takes away from the developers need to worry about which environment the code is running in, which is why I do think having the config checks hidden inside the functions may be better. But ultimately a lot of this code is changing soon (because the event markers and photodiode will be available in both the browser AND native app) and I think expecting the caller to chose what they do/don't want to execute is best. This code is moving in that direction.

Variables vs Functions

JsPsych expects all trials as an object. There are certain instances where we need to build a trial and must use a function (e.g. when we pass jsPsych around. However, in most cases, it's simpler to leave as a const variable.

Note that some keys to the trial (e.g. stimulus, prompt, etc.) can be written as callback functions that return the required type! This closer matches the jsPsych documentation and generally seems to be best practice, rather than functions that create the entire trial object. This PR covers a lot of those cases but doesn't cover 100%. I'll keep making changes as I progress.

Naming

  1. I think the build___Trial is a bit more idiomatic of the difference between the variables and functions. Code that is a function is NOT a trial, it's building the trial object
  2. The ___Trial variable naming is a bit pedantic but I think it better communicates exactly what the objects are in a way that pure JS is not the greatest at. I think it's a useful naming scheme, especially considering HC will be most lab members first time writing code

Removal of export default

This is just to keep consistency between files. I'm not 100% sure if I want one trial per file but I'll think about that for another PR. For now it makes it so the trials are imported in the same way across all trials

function buildHoneycombBlock(jsPsych) {
const { honeycomb: honeycombSettings } = taskSettings;
const honeycombSettings = taskSettings.honeycomb;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicky but it might be easier to read if config variables are in caps?

Copy link
Member Author

Choose a reason for hiding this comment

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

Definitely on my nice to haves but I'm not sure where to draw the line. Maybe just SETTINGS, LANGUAGE, and ENV? At the very least I think env isa much better name than config

@@ -35,7 +43,7 @@ function buildHoneycombBlock(jsPsych) {
},
// Conditionally flashes the photodiode when the trial first loads
on_load: () => {
if (config.USE_PHOTODIODE) pdSpotEncode(eventCodes.honeycomb, 1, config);
if (config.USE_PHOTODIODE) pdSpotEncode(eventCodes.honeycomb);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm I guess that would make this look weird, so maybe never mind.

Comment on lines +8 to +10
/** Builds the blocks of trials needed to start and setup the experiment */
function buildPreambleBlock() {
const timeline = [nameTrial, enterFullscreenTrial, welcomeTrial];
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this pattern a lot! You're basically moving things from the top level into functions, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. And there's a HUGE difference between code that's inside a function and code that's inside a trial's callback function. Hoping to be a little more clear about that.

Base automatically changed from feat-photodiodeGhostBox to hold-cleaning December 13, 2023 20:10
@RobertGemmaJr RobertGemmaJr merged commit 7afd2ce into hold-cleaning Dec 13, 2023
7 checks passed
@RobertGemmaJr RobertGemmaJr deleted the ref-check-at-trial branch December 13, 2023 20:19
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.

Conditional check for photodiodeGhostSpot and pdSpotEncode for should be at the task level
2 participants