Make plugin info static

so it can be accessed before a plugin is instantiated
This commit is contained in:
bjoluc 2021-08-12 17:25:26 +02:00
parent 559f60c83e
commit 56d6fd9d0b
4 changed files with 11 additions and 10 deletions

View File

@ -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);

View File

@ -140,13 +140,10 @@ export interface PluginInfo {
}
export interface JsPsychPlugin<I extends PluginInfo> {
info: I;
trial(display_element: HTMLElement, trial: TrialType<I>): void;
}
export type TrialType<I extends PluginInfo> = InferredParameters<I["parameters"]> &
UniversalPluginParameters;
export type PluginParameters<P extends JsPsychPlugin<any>> = InferredParameters<
P["info"]["parameters"]
>;
export type PluginParameters<I extends PluginInfo> = InferredParameters<I["parameters"]>;

View File

@ -166,7 +166,7 @@ describe("nested parameters as functions", () => {
};
class FunctionTestPlugin implements JsPsychPlugin<typeof info> {
info = info;
static info = info;
constructor(private jsPsych: JsPsych) {}

View File

@ -67,7 +67,7 @@ type Info = typeof info;
*
**/
class HtmlKeyboardResponsePlugin implements JsPsychPlugin<Info> {
info = info;
static info = info;
constructor(private jsPsych: JsPsych) {}