Skip to content

Commit

Permalink
Cache result of getXAPIObject (optimization)
Browse files Browse the repository at this point in the history
  • Loading branch information
figureone committed Mar 14, 2018
1 parent 4346b92 commit 6c0dbf9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions scripts/x-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ H5P.VideoXAPI = (function ($) {
var volumeChangedAt = 0;
var sessionID = H5P.createUUID();
var currentTime = 0;
var xAPIObject = null;


/**
Expand Down Expand Up @@ -500,6 +501,10 @@ H5P.VideoXAPI = (function ($) {
* @returns {Object} 'Object' portion of JSON xAPI statement
*/
var getXAPIObject = function () {
if (xAPIObject !== null) {
return xAPIObject;
}

var event = new H5P.XAPIEvent();

if (videoInstance && videoInstance.contentId && H5PIntegration && H5PIntegration.contents && H5PIntegration.contents['cid-' + videoInstance.contentId]) {
Expand Down

0 comments on commit 6c0dbf9

Please sign in to comment.