From 56d6fd9d0b83d9e2b64d37a841df392e9e118e0c Mon Sep 17 00:00:00 2001 From: bjoluc Date: Thu, 12 Aug 2021 17:25:26 +0200 Subject: [PATCH] Make plugin info static so it can be accessed before a plugin is instantiated --- packages/jspsych/src/JsPsych.ts | 12 ++++++++---- packages/jspsych/src/modules/plugins.ts | 5 +---- .../tests/core/functions-as-parameters.test.ts | 2 +- packages/plugin-html-keyboard-response/src/index.ts | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/jspsych/src/JsPsych.ts b/packages/jspsych/src/JsPsych.ts index ce6c0855..1aecde0f 100644 --- a/packages/jspsych/src/JsPsych.ts +++ b/packages/jspsych/src/JsPsych.ts @@ -504,13 +504,17 @@ export class JsPsych { this.current_trial = trial; this.current_trial_finished = false; - // instantiate the plugin for this trial - const info = trial.type.info; - trial.type = new trial.type(this); - // process all timeline variables for this trial this.evaluateTimelineVariables(trial); + // instantiate the plugin for this trial + trial.type = { + // this is a hack to internally keep the old plugin object structure and prevent touching more + // of the core jspsych code + ...autoBind(new trial.type(this)), + info: trial.type.info, + }; + // evaluate variables that are functions this.evaluateFunctionParameters(trial); diff --git a/packages/jspsych/src/modules/plugins.ts b/packages/jspsych/src/modules/plugins.ts index c97792a5..434a108e 100644 --- a/packages/jspsych/src/modules/plugins.ts +++ b/packages/jspsych/src/modules/plugins.ts @@ -140,13 +140,10 @@ export interface PluginInfo { } export interface JsPsychPlugin { - info: I; trial(display_element: HTMLElement, trial: TrialType): void; } export type TrialType = InferredParameters & UniversalPluginParameters; -export type PluginParameters

> = InferredParameters< - P["info"]["parameters"] ->; +export type PluginParameters = InferredParameters; diff --git a/packages/jspsych/tests/core/functions-as-parameters.test.ts b/packages/jspsych/tests/core/functions-as-parameters.test.ts index eb5026ef..de5f6382 100644 --- a/packages/jspsych/tests/core/functions-as-parameters.test.ts +++ b/packages/jspsych/tests/core/functions-as-parameters.test.ts @@ -166,7 +166,7 @@ describe("nested parameters as functions", () => { }; class FunctionTestPlugin implements JsPsychPlugin { - info = info; + static info = info; constructor(private jsPsych: JsPsych) {} diff --git a/packages/plugin-html-keyboard-response/src/index.ts b/packages/plugin-html-keyboard-response/src/index.ts index 5810f98c..ef94ccef 100644 --- a/packages/plugin-html-keyboard-response/src/index.ts +++ b/packages/plugin-html-keyboard-response/src/index.ts @@ -67,7 +67,7 @@ type Info = typeof info; * **/ class HtmlKeyboardResponsePlugin implements JsPsychPlugin { - info = info; + static info = info; constructor(private jsPsych: JsPsych) {}