diff --git a/docs/developers/extension-development.md b/docs/developers/extension-development.md index 5495b69107..cdfec7245f 100644 --- a/docs/developers/extension-development.md +++ b/docs/developers/extension-development.md @@ -4,12 +4,12 @@ As of version 7.0, extensions are [JavaScript Classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes). An extension must implement: -* [A `constructor()`](#constructor) that accepts an instance of jsPsych. -* [An `initialize()` function](#initialize) to handle the initialize event of the extension. -* [An `on_start()` function](#on_start) to handle the on_start event of the extension. -* [An `on_load()` function](#on_load) to handle the on_load event of the extension. -* [An `on_finish()` function](#on_finish) to handle the on_finish event of the extension and store data that the extension collects. -* [A static `info`](#static-info) property containing a unique name, version parameter and data property for the extension. +- [A `constructor()`](#constructor) that accepts an instance of jsPsych. +- [An `initialize()` function](#initialize) to handle the initialize event of the extension. +- [An `on_start()` function](#on_start) to handle the on_start event of the extension. +- [An `on_load()` function](#on_load) to handle the on_load event of the extension. +- [An `on_finish()` function](#on_finish) to handle the on_finish event of the extension and store data that the extension collects. +- [A static `info`](#static-info) property containing a unique name, version parameter, and data property for the extension. ### Templates @@ -31,7 +31,7 @@ class MyAwesomeExtension { ### initialize() -The `initialize()` function is called when an instance of jsPsych is first initialized, either through `initJsPsych()` or `new JsPsych()`. This is where setup code for the extension should be run. This event will happen once per experiment, unlike the other events which occur with each trial. The `params` object can include whatever parameters are necessary to configure the extension. The `params` object is passed from the call to `initJsPsych()` to `initialize()` method. `initialize()` must return a `Promise` that resolves when the extension is finished initializing. +The `initialize()` function is called when an instance of jsPsych is first initialized, either through `initJsPsych()` or `new JsPsych()`. This is where setup code for the extension should be run. This event will happen once per experiment, unlike the other events which occur with each trial. The `params` object can include whatever parameters are necessary to configure the extension. The `params` object is passed from the call to `initJsPsych()` to `initialize()` method. `initialize()` must return a `Promise` that resolves when the extension is finished initializing. ```js //... experiment code ...// @@ -79,7 +79,6 @@ class MyAwesomeExtension { } ``` - ### on_load() `on_load()` is called after the `on_load` event for the plugin has completed, which is typically when the plugin has finished executing initial DOM-modifying code and has set up various event listeners. This is where the extension can begin actively interacting with the DOM and recording data. The `params` object is passed from the declaration of the extension in the trial object. You can use `params` to customize the behavior of the extension for each trial. @@ -110,7 +109,7 @@ class MyAwesomeExtension { ### on_finish() -`on_finish()` is called after the plugin invokes `jsPsych.finishTrial()`. This can be used for any teardown at the end of the trial. This method should return an object of data to append to the plugin's data. Note that this event fires *before* the `on_finish` event for the plugin, so data added by the extension is accessible in any trial `on_finish` event handlers. The `params` object is passed from the declaration of the extension in the trial object. You can use `params` to customize the behavior of the extension for each trial. +`on_finish()` is called after the plugin invokes `jsPsych.finishTrial()`. This can be used for any teardown at the end of the trial. This method should return an object of data to append to the plugin's data. Note that this event fires _before_ the `on_finish` event for the plugin, so data added by the extension is accessible in any trial `on_finish` event handlers. The `params` object is passed from the declaration of the extension in the trial object. You can use `params` to customize the behavior of the extension for each trial. ```js //... experiment code ...// @@ -155,9 +154,9 @@ class MyAwesomeExtension { MyAwesomeExtension.info = { name: 'awesome', - version: version, // can also be hardcoded as `version: "1.0.1"` + version: version, // Should be hardcoded as `version: "1.0.1"` if not using build tools. data: { - /** This will be scraped as metadata describing tracking_data. */ + /** This will be scraped as metadata describing tracking_data and used to create the JsPsych docs */ tracking_data: { type: ParameterType.STRING, } @@ -167,14 +166,14 @@ MyAwesomeExtension.info = { The `version` field describes the version of the extension used and then durin the experiment will be part of the generated data. This is used generate metadata and help maintain the Psych-DS standard. It should imported from the package.json file by including an import statement in the top of the index.ts file. This allows the `version` field be automatically updated with each changeset. If you are not using a build environment and instead writing a plain JS file, you can manually enter the `version` as a string as done in the comment. -The `data` field is an object containing all of the `data` generated for the plugin. Each 'data' object has a `type` and `default` property. Additionally, this should be only used for data you choose to generate. Any javadoc you include will be scraped as metadata if you are choosing to generate metadata. +The `data` field is an object containing all of the `data` generated for the plugin. Each 'data' object has a `type` and `default` property. Additionally, this should be only used for data you choose to generate. Any jsdoc (comments included in the /** */ tags) you include will be scraped as metadata if you are choosing to generate metadata. This scraped metadata will also be used to create the JsPsych documentation. ### Optional methods The extension can also include any additional methods that are necessary for interacting with it. See the [webgazer extension](../extensions/webgazer.md) for an example. -## Advice for writing extensions +## Advice for writing extensions -If you are developing an extension with the aim of including it in the main jsPsych repository we encourage you to follow the [contribution guidelines](contributing.md#contributing-to-the-codebase). +If you are developing an extension with the aim of including it in the main jsPsych repository we encourage you to follow the [contribution guidelines](contributing.md#contributing-to-the-codebase). -In general, extensions should be able to work with any plugin. They should make very few assumptions about what the DOM will contain beyond the container elements generated by jsPsych. If you are making an extension targeted at one or a small number of specific plugins, consider modifying the plugin code instead. \ No newline at end of file +In general, extensions should be able to work with any plugin. They should make very few assumptions about what the DOM will contain beyond the container elements generated by jsPsych. If you are making an extension targeted at one or a small number of specific plugins, consider modifying the plugin code instead. diff --git a/packages/jspsych/src/timeline/Trial.ts b/packages/jspsych/src/timeline/Trial.ts index 1ab7721b27..fd111ef862 100644 --- a/packages/jspsych/src/timeline/Trial.ts +++ b/packages/jspsych/src/timeline/Trial.ts @@ -40,17 +40,17 @@ export class Trial extends TimelineNode { if (!("version" in this.pluginInfo) && !("data" in this.pluginInfo)) { console.warn( this.pluginInfo["name"], - "is missing the 'version' and 'data' fields. Please update plugin as 'version' and 'data' will be required in v9." + "is missing the 'version' and 'data' fields. Please update plugin as 'version' and 'data' will be required in v9. See https://www.jspsych.org/latest/developers/plugin-development/ for more details." ); } else if (!("version" in this.pluginInfo)) { console.warn( this.pluginInfo["name"], - "is missing the 'version' field. Please update plugin as 'version' will be required in v9." + "is missing the 'version' field. Please update plugin as 'version' will be required in v9. See https://www.jspsych.org/latest/developers/plugin-development/ for more details." ); } else if (!("data" in this.pluginInfo)) { console.warn( this.pluginInfo["name"], - "is missing the 'data' field. Please update plugin as 'data' will be required in v9." + "is missing the 'data' field. Please update plugin as 'data' will be required in v9. See https://www.jspsych.org/latest/developers/plugin-development/ for more details." ); } }