API

The programming interface provided by MinnoJS tasks.

Task creation

setName(name)

ArgumentTypeDescription
nameStringThe name of this task. If used as part of miManager, this setting may be overided by the manager task object.

returns:

(Object) this API

example:

API.setName('taskName');

addSettings(name, setting)

ArgumentTypeDescription
nameStringThe name of the setting that you want to change.
setting* or ObjectThe setting value. If this is an object, it will extend the existing setting object instead of overwriting it.

returns:

(Object) this API

example:

API.addSettings('onEnd', function(){
    // something to do at the end of the task    
});

addSequence(sequence)

ArgumentTypeDescription
sequenceArray or ObjectAn array of objects or a single object to add to the sequence (for example, trial or page objects).

returns:

(Object) this API

example:

API.addSequence([
    trial1,
    trial2
]);

addSet(setName, setArray)

Each task API has one or more “addSet” functions. These function take the form add<*SetName*>Set so that, for instance pages use the API.addPagesSet function and tasks use the API.addTaskSet function. They are used in order to register prototypes of objects for the sequencer inheritance system.

ArgumentTypeDescription
setNameStringThe name of the set to be registered.
setArrayArray or ObjectAn array or object to add this this set.

This function has an alternative notation : add<*SetName*>Set(setName, setArray).

ArgumentTypeDescription
setsObjectStringAn object where each property name is a setName and the content is the set content.
TasksetNameFunction Name
miManagertasksaddTasksSet
miQuestpagesaddPagesSet
questionsaddQuestionsSet
miTimetrialaddTrialSet
stimulusaddStimulusSet
mediaaddMediaSet

returns:

‘undefined’

examples:

First notation:

API.addTrialSet('set1', trial1);
API.addTrialSet('set2', [trial2, trial3]);

Second notation. Does the same thing as the first pair:

API.addTrialSet({
    set1: [trial1],
    set2: [trial2,trial3]
});

Environmental variables

addGlobal(obj)

ArgumentTypeDescription
objObjectAn object to merged into the global object

returns:

(Object) global object.

example:

API.addGlobal({myFlag: true});

getGlobal()

returns:

(Object) global object.

example:

var global = API.getGlobal();
global.myFlag = true;

addCurrent(obj)

ArgumentTypeDescription
objObjectAn object to merged into the current object.

returns:

(Object) current object.

example:

API.addCurrent({myFlag: true});

getCurrent()

returns:

(Object) current object.

example:

var current = API.getCurrent();
current.myFlag = true;

Convenience methods

post(url, object)

Posts JSONified data to the server.

ArgumentTypeDescription
urlStringThe url to post to.
objectobjectAn Object to be JSONified then posted.

returns:

(Promise) a promise to be resolved when the post completes.

example:

API.post('my/server/url', {my:'data'});

shuffle(collection)

Returns an array of shuffled values, using a version of the Fisher-Yates shuffle (Uses lodash shuffle).

ArgumentTypeDescription
collectionArray, Object or StringThe collection to shuffle.

returns:

(Array) The new shuffled array.

example:

var shuffled = API.shuffle([1,2,3,4]);
console.log(shuffled); // prints [4, 1, 3, 2] for example

save(object)

This function is available only on the project implicit build. Posts JSONified data to the server.

ArgumentTypeDescription
objectobjectAn Object to be JSONified then posted.

returns:

(Promise) a promise to be resolved when the post completes.

example:

API.save({my:'data'});
Last modified March 11, 2021: setup hugo (11980dc)