Removal of on_data_update event
The on_trial_finish event and the on_data_update event both are only called once, inside the finishTrial method:
// handle callback at whole-experiment level
this.opts.on_trial_finish(trial_data_values);
// after the above callbacks are complete, then the data should be finalized
// for this trial. call the on_data_update handler, passing in the same
// data object that just went through the trial's finish handlers.
this.opts.on_data_update(trial_data_values);
They are called side by side, and have the same data object passed to both, so at least personally, I do not think that the existence of on_data_update is actually necessary in the way it is currently working in, and it might probably be better to simply remove this.
@bjoluc -- thoughts on this as part of 8.0?
Great catch @Shaobin-Jiang, let's remove on_data_update in 8.0 :tada:
Quick thought about that came up working with another project:
Would it make sense to keep this event and have it trigger anytime the jsPsych.data object is updated? In its current form it doesn't do this, but if it did then it would allow people to stick reliable backend data handlers inside the on_data_update event.
and have it trigger anytime the jsPsych.data object is updated?
You mean after on_trial_finish and after jsPsych.data.addToAll or jsPsych.data.addToLast?
have it trigger anytime the jsPsych.data object is updated
I think what @jodeleeuw means here is that we monitor the change of the jsPsych.data object somehow, like adding a callback or something. Instead of triggering after particular events, it triggers whenever the object is updated.
It is tricky, and I might suggest using a proxy for that, but proxies do have their limitations, so I am at a loss as to how this might be done properly.