Skip to content

Commit

Permalink
Fixed templates to match v8 version and data parameter standards for …
Browse files Browse the repository at this point in the history
…plugins and extensions
  • Loading branch information
vzhang03 committed Jul 19, 2024
1 parent 03ea042 commit 542e7b2
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 7 deletions.
16 changes: 15 additions & 1 deletion templates/extension-template-js/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { version } from "./package.json";

var _globalName_ = (function (jspsych) {
"use strict";

Expand Down Expand Up @@ -26,12 +28,24 @@ var _globalName_ = (function (jspsych) {

on_finish(params) {
return {
data_property: "data_value",
data_name: 99, // Make sure this type and name matches data_name
data_name2: "hello world!", // Make this this type and name matches data_name2
};
}
}
ExtensionNameExtension.info = {
name: "{name}",
version: version,
data: {
/** This comment will be scraped as metadata for data_name when running the metadata module. */
data_name: {
type: ParameterType.INT,
},
/** This comment will be scraped as metadata for data_name2 when running the metadata module. */
data_name2: {
type: ParameterType.STRING,
},
},
};

return ExtensionNameExtension;
Expand Down
18 changes: 16 additions & 2 deletions templates/extension-template-ts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { JsPsych, JsPsychExtension, JsPsychExtensionInfo } from "jspsych";
import { JsPsych, JsPsychExtension, JsPsychExtensionInfo, ParameterType } from "jspsych";

import { version } from "../package.json";

interface InitializeParameters {}

Expand All @@ -19,6 +21,17 @@ interface OnFinishParameters {}
class ExtensionNameExtension implements JsPsychExtension {
static info: JsPsychExtensionInfo = {
name: "{name}",
version: version,
data: {
/** This comment will be scraped as metadata for data_name when running the metadata module. */
data_name: {
type: ParameterType.INT,
},
/** This comment will be scraped as metadata for data_name2 when running the metadata module. */
data_name2: {
type: ParameterType.STRING,
},
},
};

constructor(private jsPsych: JsPsych) {}
Expand All @@ -35,7 +48,8 @@ class ExtensionNameExtension implements JsPsychExtension {

on_finish = ({}: OnFinishParameters): { [key: string]: any } => {
return {
data_property: "data_value",
data_name: 99, // Make sure this type and name matches data_name
data_name2: "hello world!", // Make this this type and name matches data_name2
};
};
}
Expand Down
3 changes: 2 additions & 1 deletion templates/extension-template-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "@jspsych/config/tsconfig.contrib.json",
"compilerOptions": {
"baseUrl": "."
"baseUrl": ".",
"resolveJsonModule": true
},
"include": ["src"]
}
18 changes: 17 additions & 1 deletion templates/plugin-template-js/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
import { version } from "./package.json";

var _globalName_ = (function (jspsych) {
"use strict";

const info = {
name: "{name}",
version: version,
parameters: {
/** This comment will be scraped as docs for parameter_name when running generating the JsPsych docs. */
parameter_name: {
type: jspsych.ParameterType.INT,
default: undefined,
},
/** This comment will be scraped as docs for parameter_name2 when running generating the JsPsych docs. */
parameter_name2: {
type: jspsych.ParameterType.IMAGE,
default: undefined,
},
},
data: {
/** This comment will be scraped as metadata for data_name when running the metadata module. */
data_name: {
type: jspsych.ParameterType.INT,
},
/** This comment will be scraped as metadata for data_name2 when running the metadata module. */
data_name2: {
type: jspsych.ParameterType.STRING,
},
},
};

/**
Expand All @@ -30,7 +45,8 @@ var _globalName_ = (function (jspsych) {
trial(display_element, trial) {
// data saving
var trial_data = {
parameter_name: "parameter value",
data_name: 99, // Make sure this type and name matches data_name
data_name2: "hello world!", // Make this this type and name matches data_name2
};
// end trial
this.jsPsych.finishTrial(trial_data);
Expand Down
18 changes: 17 additions & 1 deletion templates/plugin-template-ts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";

import { version } from "../package.json";

const info = <const>{
name: "{name}",
version: version,
parameters: {
/** This comment will be scraped as docs for parameter_name when running generating the JsPsych docs. */
parameter_name: {
type: ParameterType.INT, // BOOL, STRING, INT, FLOAT, FUNCTION, KEY, KEYS, SELECT, HTML_STRING, IMAGE, AUDIO, VIDEO, OBJECT, COMPLEX
default: undefined,
},
/** This comment will be scraped as docs for parameter_name when running generating the JsPsych docs. */
parameter_name2: {
type: ParameterType.IMAGE,
default: undefined,
},
},
data: {
/** This comment will be scraped as metadata for data_name when running the metadata module. */
data_name: {
type: ParameterType.INT,
},
/** This comment will be scraped as metadata for data_name2 when running the metadata module. */
data_name2: {
type: ParameterType.STRING,
},
},
};

type Info = typeof info;
Expand All @@ -32,7 +47,8 @@ class PluginNamePlugin implements JsPsychPlugin<Info> {
trial(display_element: HTMLElement, trial: TrialType<Info>) {
// data saving
var trial_data = {
parameter_name: "parameter value",
data_name: 99, // Make sure this type and name matches data_name
data_name2: "hello world!", // Make this this type and name matches data_name2
};

// end trial
Expand Down
3 changes: 2 additions & 1 deletion templates/plugin-template-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "@jspsych/config/tsconfig.contrib.json",
"compilerOptions": {
"baseUrl": "."
"baseUrl": ".",
"resolveJsonModule": true
},
"include": ["src"]
}

0 comments on commit 542e7b2

Please sign in to comment.