mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-12 16:48:10 +00:00
Merge pull request #387 from apitiot/master
added fromSnapshot static method to TrialHandler
This commit is contained in:
commit
94264e3e75
@ -211,6 +211,7 @@ export class TrialHandler extends PsychObject
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} Snapshot
|
* @typedef {Object} Snapshot
|
||||||
|
* @property {TrialHandler} handler - the trialHandler
|
||||||
* @property {string} name - the trialHandler name
|
* @property {string} name - the trialHandler name
|
||||||
* @property {number} nStim - the number of stimuli
|
* @property {number} nStim - the number of stimuli
|
||||||
* @property {number} nTotal - the total number of trials that will be run
|
* @property {number} nTotal - the total number of trials that will be run
|
||||||
@ -236,6 +237,7 @@ export class TrialHandler extends PsychObject
|
|||||||
const currentIndex = this.thisIndex;
|
const currentIndex = this.thisIndex;
|
||||||
|
|
||||||
const snapshot = {
|
const snapshot = {
|
||||||
|
handler: this,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
nStim: this.nStim,
|
nStim: this.nStim,
|
||||||
nTotal: this.nTotal,
|
nTotal: this.nTotal,
|
||||||
@ -249,6 +251,8 @@ export class TrialHandler extends PsychObject
|
|||||||
|
|
||||||
getCurrentTrial: () => this.getTrial(currentIndex),
|
getCurrentTrial: () => this.getTrial(currentIndex),
|
||||||
getTrial: (index = 0) => this.getTrial(index),
|
getTrial: (index = 0) => this.getTrial(index),
|
||||||
|
|
||||||
|
addData: (key, value) => this.addData(key, value)
|
||||||
};
|
};
|
||||||
|
|
||||||
this._snapshots.push(snapshot);
|
this._snapshots.push(snapshot);
|
||||||
@ -274,6 +278,33 @@ export class TrialHandler extends PsychObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the internal state of this trial handler from the given snapshot.
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
* @static
|
||||||
|
* @param {Snapshot} snapshot - the snapshot from which to update the current internal state.
|
||||||
|
*/
|
||||||
|
static fromSnapshot(snapshot)
|
||||||
|
{
|
||||||
|
// if snapshot is undefined, do nothing:
|
||||||
|
if (typeof snapshot === 'undefined')
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
snapshot.handler.nStim = snapshot.nStim;
|
||||||
|
snapshot.handler.nTotal = snapshot.nTotal;
|
||||||
|
snapshot.handler.nRemaining = snapshot.nRemaining;
|
||||||
|
snapshot.handler.thisRepN = snapshot.thisRepN;
|
||||||
|
snapshot.handler.thisTrialN = snapshot.thisTrialN;
|
||||||
|
snapshot.handler.thisN = snapshot.thisN;
|
||||||
|
snapshot.handler.thisIndex = snapshot.thisIndex;
|
||||||
|
snapshot.handler.ran = snapshot.ran;
|
||||||
|
snapshot.handler._finished = snapshot._finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setter for the finished attribute.
|
* Setter for the finished attribute.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user