Skip to content

Commit

Permalink
Update jspsych-pluginAPI.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jodeleeuw committed Oct 16, 2014
1 parent ec5caa3 commit 0d131c2
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions docs/markdown_docs/core_library/jspsych-pluginAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,36 @@ jsPsych.pluginAPI.cancelKeyboardResponse(listener_id);
## jsPsych.pluginAPI.enforceArray

```
jsPsych.pluginAPI.enforceArray
jsPsych.pluginAPI.enforceArray(params, possible_arrays)
```

### Parameters

Parameter | Type | Description
----------|------|------------

params | object | An object of `key: value` pairs.
possible_arrays | array | Array of strings where each string is a key from `params` indicating which `keys` should have arrays as the `value`.

### Return value


Returns a copy of `params` where all of the `keys` in `possible_arrays` are guaranteed to be arrays.

### Description


This function checks if specified parameters are arrays. If they are not arrays, then it converts them to arrays. Practically, this is used for cases where a plugin calls for an array, but a single value is also a reasonable option. An example would be specifying a stimulus for the `single-stim` plugin. Technically, the plugin requires the stimuli to be specified in an array. Each element of the array is then given its own trial. However, a single element array to present one trial is possible. This function means that users can declare the single element array as either an array or just the value that would be the element in the array.

### Examples

```javascript

// a snippet from the text plugin
plugin.create = function(params) {

params = jsPsych.pluginAPI.enforceArray(params, ['text','data']);

// other stuff here ...

};

```

Expand Down Expand Up @@ -174,4 +183,4 @@ plugin.trial = function(display_element, trial) {
// the rest of the trial code...
}

```
```

0 comments on commit 0d131c2

Please sign in to comment.