From 4b13ad64fdddbbadaafaf24381e738ad1299d4ea Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Thu, 11 Jul 2024 16:21:11 -0400 Subject: [PATCH 1/5] adding `trialCleanup` method --- package-lock.json | 1 - packages/jspsych/src/JsPsych.ts | 2 ++ packages/jspsych/src/timeline/Trial.ts | 11 +++++++++++ packages/jspsych/src/timeline/index.ts | 5 +++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 3b141cbec4..288e9744d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,7 +4,6 @@ "requires": true, "packages": { "": { - "name": "jsPsych", "workspaces": [ "packages/*" ], diff --git a/packages/jspsych/src/JsPsych.ts b/packages/jspsych/src/JsPsych.ts index e6b69d7b7c..c6e63013ac 100644 --- a/packages/jspsych/src/JsPsych.ts +++ b/packages/jspsych/src/JsPsych.ts @@ -396,6 +396,8 @@ export class JsPsych { getDefaultIti: () => this.getInitSettings().default_iti, finishTrialPromise: this.finishTrialPromise, + + clearAllTimeouts: () => this.pluginAPI.clearAllTimeouts(), }; private extensionManagerDependencies: ExtensionManagerDependencies = { diff --git a/packages/jspsych/src/timeline/Trial.ts b/packages/jspsych/src/timeline/Trial.ts index fd111ef862..bfc300ff47 100644 --- a/packages/jspsych/src/timeline/Trial.ts +++ b/packages/jspsych/src/timeline/Trial.ts @@ -112,6 +112,9 @@ export class Trial extends TimelineNode { result = await trialPromise; } + // The trial has finished, time to clean up. + this.cleanupTrial(); + return result; } @@ -147,6 +150,14 @@ export class Trial extends TimelineNode { }; } + /** + * Cleanup the trial by removing the display element and removing event listeners + */ + private cleanupTrial() { + this.dependencies.clearAllTimeouts(); + this.dependencies.getDisplayElement().innerHTML = ""; + } + /** * Add the CSS classes from the `css_classes` parameter to the display element */ diff --git a/packages/jspsych/src/timeline/index.ts b/packages/jspsych/src/timeline/index.ts index abf13c11be..f929e00ccd 100644 --- a/packages/jspsych/src/timeline/index.ts +++ b/packages/jspsych/src/timeline/index.ts @@ -221,6 +221,11 @@ export interface TimelineNodeDependencies { * is called. */ finishTrialPromise: PromiseWrapper; + + /** + * Clear all of the timeouts + */ + clearAllTimeouts: () => void; } export type TrialResult = Record; From 06b082a97764ea5a5dd7d046081e400d9d4c3b97 Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Thu, 11 Jul 2024 16:25:39 -0400 Subject: [PATCH 2/5] remove unnecessary timeout clear and display clear --- packages/plugin-html-keyboard-response/src/index.spec.ts | 1 + packages/plugin-html-keyboard-response/src/index.ts | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/plugin-html-keyboard-response/src/index.spec.ts b/packages/plugin-html-keyboard-response/src/index.spec.ts index 876a4f4bf6..ce7608a3df 100644 --- a/packages/plugin-html-keyboard-response/src/index.spec.ts +++ b/packages/plugin-html-keyboard-response/src/index.spec.ts @@ -31,6 +31,7 @@ describe("html-keyboard-response", () => { ); await pressKey("f"); + expect(getHTML()).toBe(""); await expectFinished(); }); diff --git a/packages/plugin-html-keyboard-response/src/index.ts b/packages/plugin-html-keyboard-response/src/index.ts index bebc307a20..093fa821e8 100644 --- a/packages/plugin-html-keyboard-response/src/index.ts +++ b/packages/plugin-html-keyboard-response/src/index.ts @@ -115,9 +115,6 @@ class HtmlKeyboardResponsePlugin implements JsPsychPlugin { // function to end trial when it is time const end_trial = () => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // kill keyboard listeners if (typeof keyboardListener !== "undefined") { this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener); @@ -130,9 +127,6 @@ class HtmlKeyboardResponsePlugin implements JsPsychPlugin { response: response.key, }; - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); }; From 313edc2af5c275ba26b5c9fc65385810192607f8 Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Thu, 11 Jul 2024 17:17:55 -0400 Subject: [PATCH 3/5] adjust tests to work with cleanup --- packages/jspsych/tests/core/abortexperiment.test.ts | 2 +- packages/jspsych/tests/test-utils.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/jspsych/tests/core/abortexperiment.test.ts b/packages/jspsych/tests/core/abortexperiment.test.ts index abb086c773..775601595b 100644 --- a/packages/jspsych/tests/core/abortexperiment.test.ts +++ b/packages/jspsych/tests/core/abortexperiment.test.ts @@ -76,7 +76,7 @@ test("if on_finish returns a Promise, wait for resolve before showing end messag const { getHTML, expectFinished, expectRunning } = await startTimeline(timeline, jsPsych); expect(getHTML()).toMatch("foo"); - pressKey("a"); + await pressKey("a"); expect(getHTML()).not.toMatch("foo"); expect(getHTML()).not.toMatch("bar"); diff --git a/packages/jspsych/tests/test-utils.ts b/packages/jspsych/tests/test-utils.ts index de2057c098..3b0cbcbcad 100644 --- a/packages/jspsych/tests/test-utils.ts +++ b/packages/jspsych/tests/test-utils.ts @@ -38,6 +38,8 @@ export class TimelineNodeDependenciesMock implements TimelineNodeDependencies { getDefaultIti = jest.fn(() => 0); finishTrialPromise = new PromiseWrapper(); + + clearAllTimeouts = jest.fn(); } /** From d520b70fbf6c36ffd605b406b6b2e17ecf867bdf Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Thu, 11 Jul 2024 18:06:30 -0400 Subject: [PATCH 4/5] remove now unnecessary timeout clears and display clears --- packages/plugin-audio-button-response/src/index.ts | 6 ------ packages/plugin-audio-keyboard-response/src/index.ts | 6 ------ packages/plugin-audio-slider-response/src/index.ts | 5 ----- packages/plugin-browser-check/src/index.ts | 2 -- packages/plugin-canvas-button-response/src/index.ts | 6 ------ packages/plugin-canvas-keyboard-response/src/index.ts | 6 ------ packages/plugin-canvas-slider-response/src/index.ts | 4 ---- packages/plugin-categorize-animation/src/index.ts | 1 - packages/plugin-categorize-html/src/index.ts | 6 ------ packages/plugin-categorize-image/src/index.ts | 6 ------ packages/plugin-cloze/src/index.ts | 1 - packages/plugin-external-html/src/index.ts | 1 - packages/plugin-free-sort/src/index.ts | 2 -- packages/plugin-html-audio-response/src/index.ts | 6 ------ packages/plugin-html-button-response/src/index.ts | 6 ------ packages/plugin-html-slider-response/src/index.ts | 4 ---- packages/plugin-html-video-response/src/index.ts | 6 ------ packages/plugin-iat-html/src/index.ts | 6 ------ packages/plugin-iat-image/src/index.ts | 6 ------ packages/plugin-image-button-response/src/index.ts | 6 ------ packages/plugin-image-keyboard-response/src/index.ts | 6 ------ packages/plugin-image-slider-response/src/index.ts | 4 ---- packages/plugin-initialize-camera/src/index.ts | 1 - packages/plugin-instructions/src/index.ts | 2 -- packages/plugin-maxdiff/src/index.ts | 3 --- packages/plugin-mirror-camera/src/index.ts | 1 - packages/plugin-preload/src/index.ts | 5 +---- packages/plugin-reconstruction/src/index.ts | 2 -- packages/plugin-resize/src/index.ts | 3 --- packages/plugin-same-different-html/src/index.ts | 5 ----- packages/plugin-same-different-image/src/index.ts | 5 ----- packages/plugin-serial-reaction-time-mouse/src/index.ts | 6 ------ packages/plugin-serial-reaction-time/src/index.ts | 6 ------ packages/plugin-sketchpad/src/index.ts | 3 --- packages/plugin-survey-html-form/src/index.ts | 2 -- packages/plugin-survey-likert/src/index.ts | 2 -- packages/plugin-survey-multi-choice/src/index.ts | 1 - packages/plugin-survey-multi-select/src/index.ts | 1 - packages/plugin-survey-text/src/index.ts | 2 -- packages/plugin-survey/src/index.ts | 1 - packages/plugin-video-button-response/src/index.ts | 8 -------- packages/plugin-video-keyboard-response/src/index.ts | 6 ------ packages/plugin-video-slider-response/src/index.ts | 6 ------ packages/plugin-virtual-chinrest/src/index.ts | 3 --- packages/plugin-visual-search-circle/src/index.ts | 3 --- packages/plugin-webgazer-calibrate/src/index.ts | 6 ------ packages/plugin-webgazer-init-camera/src/index.ts | 6 ------ packages/plugin-webgazer-validate/src/index.ts | 6 ------ 48 files changed, 1 insertion(+), 196 deletions(-) diff --git a/packages/plugin-audio-button-response/src/index.ts b/packages/plugin-audio-button-response/src/index.ts index 9bae5bf4f1..735258aadd 100644 --- a/packages/plugin-audio-button-response/src/index.ts +++ b/packages/plugin-audio-button-response/src/index.ts @@ -278,9 +278,6 @@ class AudioButtonResponsePlugin implements JsPsychPlugin { // function to end trial when it is time const end_trial = () => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // stop the audio file if it is playing // remove end event listeners if they exist if (context !== null) { @@ -299,9 +296,6 @@ class AudioButtonResponsePlugin implements JsPsychPlugin { response: response.button, }; - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); diff --git a/packages/plugin-audio-keyboard-response/src/index.ts b/packages/plugin-audio-keyboard-response/src/index.ts index 0f23ba4c4f..4de7911707 100644 --- a/packages/plugin-audio-keyboard-response/src/index.ts +++ b/packages/plugin-audio-keyboard-response/src/index.ts @@ -182,9 +182,6 @@ class AudioKeyboardResponsePlugin implements JsPsychPlugin { // function to end trial when it is time const end_trial = () => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // stop the audio file if it is playing // remove end event listeners if they exist if (context !== null) { @@ -206,9 +203,6 @@ class AudioKeyboardResponsePlugin implements JsPsychPlugin { response: response.key, }; - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); diff --git a/packages/plugin-audio-slider-response/src/index.ts b/packages/plugin-audio-slider-response/src/index.ts index 497d613cf9..0240312cf6 100644 --- a/packages/plugin-audio-slider-response/src/index.ts +++ b/packages/plugin-audio-slider-response/src/index.ts @@ -340,9 +340,6 @@ class AudioSliderResponsePlugin implements JsPsychPlugin { } const end_trial = () => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // stop the audio file if it is playing // remove end event listeners if they exist if (context !== null) { @@ -362,8 +359,6 @@ class AudioSliderResponsePlugin implements JsPsychPlugin { response: response.response, }; - display_element.innerHTML = ""; - // next trial this.jsPsych.finishTrial(trialdata); diff --git a/packages/plugin-browser-check/src/index.ts b/packages/plugin-browser-check/src/index.ts index 8bae0d8e9d..1613fe3a5a 100644 --- a/packages/plugin-browser-check/src/index.ts +++ b/packages/plugin-browser-check/src/index.ts @@ -447,8 +447,6 @@ class BrowserCheckPlugin implements JsPsychPlugin { } private end_trial(feature_data) { - this.jsPsych.getDisplayElement().innerHTML = ""; - const trial_data = { ...Object.fromEntries(feature_data) }; this.jsPsych.finishTrial(trial_data); diff --git a/packages/plugin-canvas-button-response/src/index.ts b/packages/plugin-canvas-button-response/src/index.ts index b00caf0b7a..08ac9f7fc1 100644 --- a/packages/plugin-canvas-button-response/src/index.ts +++ b/packages/plugin-canvas-button-response/src/index.ts @@ -200,18 +200,12 @@ class CanvasButtonResponsePlugin implements JsPsychPlugin { // function to end trial when it is time const end_trial = () => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // gather the data to store for the trial var trial_data = { rt: response.rt, response: response.button, }; - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-canvas-keyboard-response/src/index.ts b/packages/plugin-canvas-keyboard-response/src/index.ts index 66549194c9..1fe592d425 100644 --- a/packages/plugin-canvas-keyboard-response/src/index.ts +++ b/packages/plugin-canvas-keyboard-response/src/index.ts @@ -123,9 +123,6 @@ class CanvasKeyboardResponsePlugin implements JsPsychPlugin { // function to end trial when it is time const end_trial = () => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // kill keyboard listeners if (typeof keyboardListener !== "undefined") { this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener); @@ -137,9 +134,6 @@ class CanvasKeyboardResponsePlugin implements JsPsychPlugin { response: response.key, }; - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-canvas-slider-response/src/index.ts b/packages/plugin-canvas-slider-response/src/index.ts index 6212c3d5a8..83f7f5ed20 100644 --- a/packages/plugin-canvas-slider-response/src/index.ts +++ b/packages/plugin-canvas-slider-response/src/index.ts @@ -174,8 +174,6 @@ class CanvasSliderResponsePlugin implements JsPsychPlugin { }; const end_trial = () => { - this.jsPsych.pluginAPI.clearAllTimeouts(); - // save data var trialdata = { rt: response.rt, @@ -183,8 +181,6 @@ class CanvasSliderResponsePlugin implements JsPsychPlugin { slider_start: trial.slider_start, }; - display_element.innerHTML = ""; - // next trial this.jsPsych.finishTrial(trialdata); }; diff --git a/packages/plugin-categorize-animation/src/index.ts b/packages/plugin-categorize-animation/src/index.ts index 3af9fd21b0..2abfc45148 100644 --- a/packages/plugin-categorize-animation/src/index.ts +++ b/packages/plugin-categorize-animation/src/index.ts @@ -240,7 +240,6 @@ class CategorizeAnimationPlugin implements JsPsychPlugin { const endTrial = () => { clearInterval(animate_interval); // stop animation! - display_element.innerHTML = ""; // clear everything this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-categorize-html/src/index.ts b/packages/plugin-categorize-html/src/index.ts index 96f9b03803..e3092d5d95 100644 --- a/packages/plugin-categorize-html/src/index.ts +++ b/packages/plugin-categorize-html/src/index.ts @@ -134,9 +134,6 @@ class CategorizeHtmlPlugin implements JsPsychPlugin { // create response function const after_response = (info: { key: string; rt: number }) => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // clear keyboard listener this.jsPsych.pluginAPI.cancelAllKeyboardResponses(); @@ -153,8 +150,6 @@ class CategorizeHtmlPlugin implements JsPsychPlugin { response: info.key, }; - display_element.innerHTML = ""; - var timeout = info.rt == null; doFeedback(correct, timeout); }; @@ -177,7 +172,6 @@ class CategorizeHtmlPlugin implements JsPsychPlugin { } const endTrial = () => { - display_element.innerHTML = ""; this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-categorize-image/src/index.ts b/packages/plugin-categorize-image/src/index.ts index 810a6fcba3..e6b36c9371 100644 --- a/packages/plugin-categorize-image/src/index.ts +++ b/packages/plugin-categorize-image/src/index.ts @@ -135,9 +135,6 @@ class CategorizeImagePlugin implements JsPsychPlugin { // create response function const after_response = (info: { key: string; rt: number }) => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // clear keyboard listener this.jsPsych.pluginAPI.cancelAllKeyboardResponses(); @@ -154,8 +151,6 @@ class CategorizeImagePlugin implements JsPsychPlugin { response: info.key, }; - display_element.innerHTML = ""; - var timeout = info.rt == null; doFeedback(correct, timeout); }; @@ -178,7 +173,6 @@ class CategorizeImagePlugin implements JsPsychPlugin { } const endTrial = () => { - display_element.innerHTML = ""; this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-cloze/src/index.ts b/packages/plugin-cloze/src/index.ts index 5fc439de94..28c2023564 100644 --- a/packages/plugin-cloze/src/index.ts +++ b/packages/plugin-cloze/src/index.ts @@ -105,7 +105,6 @@ class ClozePlugin implements JsPsychPlugin { response: answers, }; - display_element.innerHTML = ""; this.jsPsych.finishTrial(trial_data); } }; diff --git a/packages/plugin-external-html/src/index.ts b/packages/plugin-external-html/src/index.ts index 0627def8ee..87879c2461 100644 --- a/packages/plugin-external-html/src/index.ts +++ b/packages/plugin-external-html/src/index.ts @@ -98,7 +98,6 @@ class ExternalHtmlPlugin implements JsPsychPlugin { rt: Math.round(performance.now() - t0), url: trial.url, }; - display_element.innerHTML = ""; this.jsPsych.finishTrial(trial_data); trial_complete(); }; diff --git a/packages/plugin-free-sort/src/index.ts b/packages/plugin-free-sort/src/index.ts index 9c7aaf6c8d..a736bba808 100644 --- a/packages/plugin-free-sort/src/index.ts +++ b/packages/plugin-free-sort/src/index.ts @@ -474,8 +474,6 @@ class FreeSortPlugin implements JsPsychPlugin { rt: rt, }; - // advance to next part - display_element.innerHTML = ""; this.jsPsych.finishTrial(trial_data); } }); diff --git a/packages/plugin-html-audio-response/src/index.ts b/packages/plugin-html-audio-response/src/index.ts index 0a0de8bb16..dc56b782bf 100644 --- a/packages/plugin-html-audio-response/src/index.ts +++ b/packages/plugin-html-audio-response/src/index.ts @@ -269,9 +269,6 @@ class HtmlAudioResponsePlugin implements JsPsychPlugin { this.recorder.removeEventListener("start", this.start_event_handler); this.recorder.removeEventListener("stop", this.stop_event_handler); - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // gather the data to store for the trial var trial_data: any = { rt: this.rt, @@ -286,9 +283,6 @@ class HtmlAudioResponsePlugin implements JsPsychPlugin { URL.revokeObjectURL(this.audio_url); } - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); } diff --git a/packages/plugin-html-button-response/src/index.ts b/packages/plugin-html-button-response/src/index.ts index 29740c28cd..81b3dda8fb 100644 --- a/packages/plugin-html-button-response/src/index.ts +++ b/packages/plugin-html-button-response/src/index.ts @@ -159,9 +159,6 @@ class HtmlButtonResponsePlugin implements JsPsychPlugin { // function to end trial when it is time const end_trial = () => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // gather the data to store for the trial var trial_data = { rt: response.rt, @@ -169,9 +166,6 @@ class HtmlButtonResponsePlugin implements JsPsychPlugin { response: response.button, }; - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-html-slider-response/src/index.ts b/packages/plugin-html-slider-response/src/index.ts index 392ed6040b..1351cb25ff 100644 --- a/packages/plugin-html-slider-response/src/index.ts +++ b/packages/plugin-html-slider-response/src/index.ts @@ -194,8 +194,6 @@ class HtmlSliderResponsePlugin implements JsPsychPlugin { } const end_trial = () => { - this.jsPsych.pluginAPI.clearAllTimeouts(); - // save data var trialdata = { rt: response.rt, @@ -204,8 +202,6 @@ class HtmlSliderResponsePlugin implements JsPsychPlugin { response: response.response, }; - display_element.innerHTML = ""; - // next trial this.jsPsych.finishTrial(trialdata); }; diff --git a/packages/plugin-html-video-response/src/index.ts b/packages/plugin-html-video-response/src/index.ts index de5a58a00b..0c0b0acad3 100644 --- a/packages/plugin-html-video-response/src/index.ts +++ b/packages/plugin-html-video-response/src/index.ts @@ -270,9 +270,6 @@ class HtmlVideoResponsePlugin implements JsPsychPlugin { this.recorder.removeEventListener("start", this.start_event_handler); this.recorder.removeEventListener("stop", this.stop_event_handler); - // clear any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // gather the data to store for the trial var trial_data: any = { rt: this.rt, @@ -286,9 +283,6 @@ class HtmlVideoResponsePlugin implements JsPsychPlugin { URL.revokeObjectURL(this.video_url); } - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); } diff --git a/packages/plugin-iat-html/src/index.ts b/packages/plugin-iat-html/src/index.ts index acac7a2ada..b6d5946c27 100644 --- a/packages/plugin-iat-html/src/index.ts +++ b/packages/plugin-iat-html/src/index.ts @@ -202,9 +202,6 @@ class IatHtmlPlugin implements JsPsychPlugin { // function to end trial when it is time const end_trial = () => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // kill keyboard listeners if (typeof keyboardListener !== "undefined") { this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener); @@ -218,9 +215,6 @@ class IatHtmlPlugin implements JsPsychPlugin { correct: response.correct, }; - // clears the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-iat-image/src/index.ts b/packages/plugin-iat-image/src/index.ts index f50ecc90b5..b67dcb63d0 100644 --- a/packages/plugin-iat-image/src/index.ts +++ b/packages/plugin-iat-image/src/index.ts @@ -202,9 +202,6 @@ class IatImagePlugin implements JsPsychPlugin { // function to end trial when it is time const end_trial = () => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // kill keyboard listeners if (typeof keyboardListener !== "undefined") { this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener); @@ -218,9 +215,6 @@ class IatImagePlugin implements JsPsychPlugin { correct: response.correct, }; - // clears the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-image-button-response/src/index.ts b/packages/plugin-image-button-response/src/index.ts index 46d7fd622f..02481de7fc 100644 --- a/packages/plugin-image-button-response/src/index.ts +++ b/packages/plugin-image-button-response/src/index.ts @@ -270,9 +270,6 @@ class ImageButtonResponsePlugin implements JsPsychPlugin { // function to end trial when it is time const end_trial = () => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // gather the data to store for the trial var trial_data = { rt: response.rt, @@ -280,9 +277,6 @@ class ImageButtonResponsePlugin implements JsPsychPlugin { response: response.button, }; - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-image-keyboard-response/src/index.ts b/packages/plugin-image-keyboard-response/src/index.ts index 5afceb7a67..4e879abf49 100644 --- a/packages/plugin-image-keyboard-response/src/index.ts +++ b/packages/plugin-image-keyboard-response/src/index.ts @@ -215,9 +215,6 @@ class ImageKeyboardResponsePlugin implements JsPsychPlugin { // function to end trial when it is time const end_trial = () => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // kill keyboard listeners if (typeof keyboardListener !== "undefined") { this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener); @@ -230,9 +227,6 @@ class ImageKeyboardResponsePlugin implements JsPsychPlugin { response: response.key, }; - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-image-slider-response/src/index.ts b/packages/plugin-image-slider-response/src/index.ts index 2dc63da9d6..2e5c77aecd 100644 --- a/packages/plugin-image-slider-response/src/index.ts +++ b/packages/plugin-image-slider-response/src/index.ts @@ -391,8 +391,6 @@ class ImageSliderResponsePlugin implements JsPsychPlugin { } const end_trial = () => { - this.jsPsych.pluginAPI.clearAllTimeouts(); - // save data var trialdata = { rt: response.rt, @@ -401,8 +399,6 @@ class ImageSliderResponsePlugin implements JsPsychPlugin { response: response.response, }; - display_element.innerHTML = ""; - // next trial this.jsPsych.finishTrial(trialdata); }; diff --git a/packages/plugin-initialize-camera/src/index.ts b/packages/plugin-initialize-camera/src/index.ts index 06b79aac22..f1ba6637d5 100644 --- a/packages/plugin-initialize-camera/src/index.ts +++ b/packages/plugin-initialize-camera/src/index.ts @@ -76,7 +76,6 @@ class InitializeCameraPlugin implements JsPsychPlugin { trial(display_element: HTMLElement, trial: TrialType) { this.run_trial(display_element, trial).then((id) => { - display_element.innerHTML = ""; this.jsPsych.finishTrial({ device_id: id, }); diff --git a/packages/plugin-instructions/src/index.ts b/packages/plugin-instructions/src/index.ts index 3cd647b427..248ea53789 100644 --- a/packages/plugin-instructions/src/index.ts +++ b/packages/plugin-instructions/src/index.ts @@ -225,8 +225,6 @@ class InstructionsPlugin implements JsPsychPlugin { this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboard_listener); } - display_element.innerHTML = ""; - var trial_data = { view_history: view_history, rt: Math.round(performance.now() - start_time), diff --git a/packages/plugin-maxdiff/src/index.ts b/packages/plugin-maxdiff/src/index.ts index ac4fe0c860..c7b822a281 100644 --- a/packages/plugin-maxdiff/src/index.ts +++ b/packages/plugin-maxdiff/src/index.ts @@ -229,9 +229,6 @@ class MaxdiffPlugin implements JsPsychPlugin { response: { left: get_response("left"), right: get_response("right") }, }; - // clear the display - display_element.innerHTML = ""; - // next trial this.jsPsych.finishTrial(trial_data); }); diff --git a/packages/plugin-mirror-camera/src/index.ts b/packages/plugin-mirror-camera/src/index.ts index 9543914e9d..bc169f5f4f 100644 --- a/packages/plugin-mirror-camera/src/index.ts +++ b/packages/plugin-mirror-camera/src/index.ts @@ -85,7 +85,6 @@ class MirrorCameraPlugin implements JsPsychPlugin { } finish(display_element: HTMLElement) { - display_element.innerHTML = ""; this.jsPsych.finishTrial({ rt: performance.now() - this.start_time, }); diff --git a/packages/plugin-preload/src/index.ts b/packages/plugin-preload/src/index.ts index dec3e34863..8f3f271f83 100644 --- a/packages/plugin-preload/src/index.ts +++ b/packages/plugin-preload/src/index.ts @@ -280,8 +280,6 @@ class PreloadPlugin implements JsPsychPlugin { }; const end_trial = () => { - // clear timeout again when end_trial is called, to handle race condition with max_load_time - this.jsPsych.pluginAPI.clearAllTimeouts(); var trial_data = { success: success, timeout: timeout, @@ -289,8 +287,7 @@ class PreloadPlugin implements JsPsychPlugin { failed_audio: failed_audio, failed_video: failed_video, }; - // clear the display - display_element.innerHTML = ""; + this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-reconstruction/src/index.ts b/packages/plugin-reconstruction/src/index.ts index ff572f1af1..4ac16efd84 100644 --- a/packages/plugin-reconstruction/src/index.ts +++ b/packages/plugin-reconstruction/src/index.ts @@ -91,8 +91,6 @@ class ReconstructionPlugin implements JsPsychPlugin { start_value: trial.starting_value, }; - display_element.innerHTML = ""; - // next trial this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-resize/src/index.ts b/packages/plugin-resize/src/index.ts index 12a35ee018..b29b0a17bf 100644 --- a/packages/plugin-resize/src/index.ts +++ b/packages/plugin-resize/src/index.ts @@ -104,9 +104,6 @@ class ResizePlugin implements JsPsychPlugin { document.removeEventListener("mousemove", resizeevent); document.removeEventListener("mouseup", mouseupevent); - // clear the screen - display_element.innerHTML = ""; - // finishes trial var trial_data = { diff --git a/packages/plugin-same-different-html/src/index.ts b/packages/plugin-same-different-html/src/index.ts index 1e73b56095..94a0653447 100644 --- a/packages/plugin-same-different-html/src/index.ts +++ b/packages/plugin-same-different-html/src/index.ts @@ -139,9 +139,6 @@ class SameDifferentHtmlPlugin implements JsPsychPlugin { } const after_response = (info: { key: string; rt: number }) => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - var correct = false; var skey = trial.same_key; @@ -167,8 +164,6 @@ class SameDifferentHtmlPlugin implements JsPsychPlugin { trial_data["response_stim1"] = first_stim_info.key; } - display_element.innerHTML = ""; - this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-same-different-image/src/index.ts b/packages/plugin-same-different-image/src/index.ts index 9a37cb10f5..b1f621b45b 100644 --- a/packages/plugin-same-different-image/src/index.ts +++ b/packages/plugin-same-different-image/src/index.ts @@ -142,9 +142,6 @@ class SameDifferentImagePlugin implements JsPsychPlugin { } const after_response = (info: { key: string; rt: number }) => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - var correct = false; var skey = trial.same_key; @@ -170,8 +167,6 @@ class SameDifferentImagePlugin implements JsPsychPlugin { trial_data["response_stim1"] = first_stim_info.key; } - display_element.innerHTML = ""; - this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-serial-reaction-time-mouse/src/index.ts b/packages/plugin-serial-reaction-time-mouse/src/index.ts index 505e7b252a..4cec040509 100644 --- a/packages/plugin-serial-reaction-time-mouse/src/index.ts +++ b/packages/plugin-serial-reaction-time-mouse/src/index.ts @@ -177,9 +177,6 @@ class SerialReactionTimeMousePlugin implements JsPsychPlugin { } const endTrial = () => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // gather the data to store for the trial var trial_data = { rt: response.rt, @@ -189,9 +186,6 @@ class SerialReactionTimeMousePlugin implements JsPsychPlugin { correct: response.row == trial.target[0] && response.column == trial.target[1], }; - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-serial-reaction-time/src/index.ts b/packages/plugin-serial-reaction-time/src/index.ts index d8f72076ae..8b87ef75a7 100644 --- a/packages/plugin-serial-reaction-time/src/index.ts +++ b/packages/plugin-serial-reaction-time/src/index.ts @@ -133,9 +133,6 @@ class SerialReactionTimePlugin implements JsPsychPlugin { }; const endTrial = () => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // kill keyboard listeners this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener); @@ -148,9 +145,6 @@ class SerialReactionTimePlugin implements JsPsychPlugin { target: trial.target, }; - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-sketchpad/src/index.ts b/packages/plugin-sketchpad/src/index.ts index 73e59953d1..98dde01c96 100644 --- a/packages/plugin-sketchpad/src/index.ts +++ b/packages/plugin-sketchpad/src/index.ts @@ -709,7 +709,6 @@ class SketchpadPlugin implements JsPsychPlugin { } private end_trial(response = null) { - this.jsPsych.pluginAPI.clearAllTimeouts(); this.jsPsych.pluginAPI.cancelAllKeyboardResponses(); clearInterval(this.timer_interval); @@ -726,8 +725,6 @@ class SketchpadPlugin implements JsPsychPlugin { trial_data.strokes = this.strokes; } - this.display.innerHTML = ""; - document.querySelector("#sketchpad-styles").remove(); this.jsPsych.finishTrial(trial_data); diff --git a/packages/plugin-survey-html-form/src/index.ts b/packages/plugin-survey-html-form/src/index.ts index e5c0d9d932..72871d0156 100644 --- a/packages/plugin-survey-html-form/src/index.ts +++ b/packages/plugin-survey-html-form/src/index.ts @@ -141,8 +141,6 @@ class SurveyHtmlFormPlugin implements JsPsychPlugin { response: question_data, }; - display_element.innerHTML = ""; - // next trial this.jsPsych.finishTrial(trialdata); }); diff --git a/packages/plugin-survey-likert/src/index.ts b/packages/plugin-survey-likert/src/index.ts index cb18b35546..b5c7551433 100644 --- a/packages/plugin-survey-likert/src/index.ts +++ b/packages/plugin-survey-likert/src/index.ts @@ -229,8 +229,6 @@ class SurveyLikertPlugin implements JsPsychPlugin { question_order: question_order, }; - display_element.innerHTML = ""; - // next trial this.jsPsych.finishTrial(trial_data); }); diff --git a/packages/plugin-survey-multi-choice/src/index.ts b/packages/plugin-survey-multi-choice/src/index.ts index 502b38a194..69c35f99b2 100644 --- a/packages/plugin-survey-multi-choice/src/index.ts +++ b/packages/plugin-survey-multi-choice/src/index.ts @@ -264,7 +264,6 @@ class SurveyMultiChoicePlugin implements JsPsychPlugin { response: question_data, question_order: question_order, }; - display_element.innerHTML = ""; // next trial this.jsPsych.finishTrial(trial_data); diff --git a/packages/plugin-survey-multi-select/src/index.ts b/packages/plugin-survey-multi-select/src/index.ts index 00423fec16..b327543cbe 100644 --- a/packages/plugin-survey-multi-select/src/index.ts +++ b/packages/plugin-survey-multi-select/src/index.ts @@ -299,7 +299,6 @@ class SurveyMultiSelectPlugin implements JsPsychPlugin { response: question_data, question_order: question_order, }; - display_element.innerHTML = ""; // next trial this.jsPsych.finishTrial(trial_data); diff --git a/packages/plugin-survey-text/src/index.ts b/packages/plugin-survey-text/src/index.ts index 151336ced8..112dd0945e 100644 --- a/packages/plugin-survey-text/src/index.ts +++ b/packages/plugin-survey-text/src/index.ts @@ -256,8 +256,6 @@ class SurveyTextPlugin implements JsPsychPlugin { response: question_data, }; - display_element.innerHTML = ""; - // next trial this.jsPsych.finishTrial(trialdata); }); diff --git a/packages/plugin-survey/src/index.ts b/packages/plugin-survey/src/index.ts index a068d7ff6f..9b724ae6c7 100644 --- a/packages/plugin-survey/src/index.ts +++ b/packages/plugin-survey/src/index.ts @@ -194,7 +194,6 @@ class SurveyPlugin implements JsPsychPlugin { } // clear display and reset flex on jspsych-content-wrapper - display_element.innerHTML = ""; document.querySelector(".jspsych-content-wrapper").style.display = "flex"; // finish trial and save data diff --git a/packages/plugin-video-button-response/src/index.ts b/packages/plugin-video-button-response/src/index.ts index afcd29a2dd..07997d907a 100644 --- a/packages/plugin-video-button-response/src/index.ts +++ b/packages/plugin-video-button-response/src/index.ts @@ -187,8 +187,6 @@ class VideoButtonResponsePlugin implements JsPsychPlugin { constructor(private jsPsych: JsPsych) {} trial(display_element: HTMLElement, trial: TrialType) { - display_element.innerHTML = ""; - // Setup stimulus const stimulusWrapper = document.createElement("div"); display_element.appendChild(stimulusWrapper); @@ -361,9 +359,6 @@ class VideoButtonResponsePlugin implements JsPsychPlugin { // function to end trial when it is time const end_trial = () => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // stop the video file if it is playing // remove any remaining end event handlers videoElement.pause(); @@ -376,9 +371,6 @@ class VideoButtonResponsePlugin implements JsPsychPlugin { response: response.button, }; - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-video-keyboard-response/src/index.ts b/packages/plugin-video-keyboard-response/src/index.ts index 65e9df4dcf..d98156e928 100644 --- a/packages/plugin-video-keyboard-response/src/index.ts +++ b/packages/plugin-video-keyboard-response/src/index.ts @@ -278,9 +278,6 @@ class VideoKeyboardResponsePlugin implements JsPsychPlugin { // function to end trial when it is time const end_trial = () => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // kill keyboard listeners this.jsPsych.pluginAPI.cancelAllKeyboardResponses(); @@ -300,9 +297,6 @@ class VideoKeyboardResponsePlugin implements JsPsychPlugin { response: response.key, }; - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-video-slider-response/src/index.ts b/packages/plugin-video-slider-response/src/index.ts index ee3d052335..1e8466b050 100644 --- a/packages/plugin-video-slider-response/src/index.ts +++ b/packages/plugin-video-slider-response/src/index.ts @@ -400,9 +400,6 @@ class VideoSliderResponsePlugin implements JsPsychPlugin { // function to end trial when it is time const end_trial = () => { - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // stop the video file if it is playing // remove any remaining end event handlers display_element @@ -421,9 +418,6 @@ class VideoSliderResponsePlugin implements JsPsychPlugin { response: response.response, }; - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-virtual-chinrest/src/index.ts b/packages/plugin-virtual-chinrest/src/index.ts index 2af5f4c795..44bfab4a83 100644 --- a/packages/plugin-virtual-chinrest/src/index.ts +++ b/packages/plugin-virtual-chinrest/src/index.ts @@ -498,9 +498,6 @@ class VirtualChinrestPlugin implements JsPsychPlugin { // compute final data computeTransformation(); - // clear the display - display_element.innerHTML = ""; - // finish the trial this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-visual-search-circle/src/index.ts b/packages/plugin-visual-search-circle/src/index.ts index d23ca685d8..0024e8178b 100644 --- a/packages/plugin-visual-search-circle/src/index.ts +++ b/packages/plugin-visual-search-circle/src/index.ts @@ -201,9 +201,6 @@ class VisualSearchCirclePlugin implements JsPsychPlugin { }; const end_trial = () => { - display_element.innerHTML = ""; - - this.jsPsych.pluginAPI.clearAllTimeouts(); this.jsPsych.pluginAPI.cancelAllKeyboardResponses(); // data saving diff --git a/packages/plugin-webgazer-calibrate/src/index.ts b/packages/plugin-webgazer-calibrate/src/index.ts index f8c4a99971..1718a48b59 100644 --- a/packages/plugin-webgazer-calibrate/src/index.ts +++ b/packages/plugin-webgazer-calibrate/src/index.ts @@ -178,15 +178,9 @@ class WebgazerCalibratePlugin implements JsPsychPlugin { extension.hidePredictions(); extension.hideVideo(); - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // gather the data to store for the trial var trial_data = {}; - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); }; diff --git a/packages/plugin-webgazer-init-camera/src/index.ts b/packages/plugin-webgazer-init-camera/src/index.ts index b9db18cca7..d9c0c56341 100644 --- a/packages/plugin-webgazer-init-camera/src/index.ts +++ b/packages/plugin-webgazer-init-camera/src/index.ts @@ -61,17 +61,11 @@ class WebgazerInitCameraPlugin implements JsPsychPlugin { extension.pause(); extension.hideVideo(); - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - // gather the data to store for the trial var trial_data = { load_time: load_time, }; - // clear the display - display_element.innerHTML = ""; - document.querySelector("#webgazer-center-style").remove(); // move on to the next trial diff --git a/packages/plugin-webgazer-validate/src/index.ts b/packages/plugin-webgazer-validate/src/index.ts index 7a7da29d15..78a1f26874 100644 --- a/packages/plugin-webgazer-validate/src/index.ts +++ b/packages/plugin-webgazer-validate/src/index.ts @@ -146,12 +146,6 @@ class WebgazerValidatePlugin implements JsPsychPlugin { const end_trial = () => { extension.stopSampleInterval(); - // kill any remaining setTimeout handlers - this.jsPsych.pluginAPI.clearAllTimeouts(); - - // clear the display - display_element.innerHTML = ""; - // move on to the next trial this.jsPsych.finishTrial(trial_data); }; From 74b4adc702747a62a201575a6aa95770eeddb1bb Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Thu, 11 Jul 2024 18:11:58 -0400 Subject: [PATCH 5/5] add changeset --- .changeset/rotten-mails-collect.md | 58 ++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .changeset/rotten-mails-collect.md diff --git a/.changeset/rotten-mails-collect.md b/.changeset/rotten-mails-collect.md new file mode 100644 index 0000000000..3bb6c199f9 --- /dev/null +++ b/.changeset/rotten-mails-collect.md @@ -0,0 +1,58 @@ +--- +"jspsych": major +"@jspsych/plugin-animation": major +"@jspsych/plugin-audio-button-response": major +"@jspsych/plugin-audio-keyboard-response": major +"@jspsych/plugin-audio-slider-response": major +"@jspsych/plugin-browser-check": major +"@jspsych/plugin-call-function": major +"@jspsych/plugin-canvas-button-response": major +"@jspsych/plugin-canvas-keyboard-response": major +"@jspsych/plugin-canvas-slider-response": major +"@jspsych/plugin-categorize-animation": major +"@jspsych/plugin-categorize-html": major +"@jspsych/plugin-categorize-image": major +"@jspsych/plugin-cloze": major +"@jspsych/plugin-external-html": major +"@jspsych/plugin-free-sort": major +"@jspsych/plugin-fullscreen": major +"@jspsych/plugin-html-audio-response": major +"@jspsych/plugin-html-button-response": major +"@jspsych/plugin-html-keyboard-response": major +"@jspsych/plugin-html-slider-response": major +"@jspsych/plugin-html-video-response": major +"@jspsych/plugin-iat-html": major +"@jspsych/plugin-iat-image": major +"@jspsych/plugin-image-button-response": major +"@jspsych/plugin-image-keyboard-response": major +"@jspsych/plugin-image-slider-response": major +"@jspsych/plugin-initialize-camera": major +"@jspsych/plugin-initialize-microphone": major +"@jspsych/plugin-instructions": major +"@jspsych/plugin-maxdiff": major +"@jspsych/plugin-mirror-camera": major +"@jspsych/plugin-preload": major +"@jspsych/plugin-reconstruction": major +"@jspsych/plugin-resize": major +"@jspsych/plugin-same-different-html": major +"@jspsych/plugin-same-different-image": major +"@jspsych/plugin-serial-reaction-time": major +"@jspsych/plugin-serial-reaction-time-mouse": major +"@jspsych/plugin-sketchpad": major +"@jspsych/plugin-survey": major +"@jspsych/plugin-survey-html-form": major +"@jspsych/plugin-survey-likert": major +"@jspsych/plugin-survey-multi-choice": major +"@jspsych/plugin-survey-multi-select": major +"@jspsych/plugin-survey-text": major +"@jspsych/plugin-video-button-response": major +"@jspsych/plugin-video-keyboard-response": major +"@jspsych/plugin-video-slider-response": major +"@jspsych/plugin-virtual-chinrest": major +"@jspsych/plugin-visual-search-circle": major +"@jspsych/plugin-webgazer-calibrate": major +"@jspsych/plugin-webgazer-init-camera": major +"@jspsych/plugin-webgazer-validate": major +--- + +`finishTrial()` now clears the display and any timeouts set with `pluginApi.setTimeout()`