Skip to content

Commit

Permalink
Add method to replace a Scorm API with another
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Bellemare committed Aug 20, 2018
1 parent 1d571d5 commit 00689e3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/scormAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
_self.checkState = checkState;
_self.getLmsErrorMessageDetails = getLmsErrorMessageDetails;
_self.loadFromJSON = loadFromJSON;
_self.replaceWithAnotherScormAPI = replaceWithAnotherScormAPI;

/**
* @returns {string} bool
Expand Down Expand Up @@ -410,6 +411,33 @@
}
}

/**
* Replace the whole API with another
*/
function replaceWithAnotherScormAPI(newAPI) {
// API Signature
_self.LMSInitialize = newAPI.LMSInitialize;
_self.LMSFinish = newAPI.LMSFinish;
_self.LMSGetValue = newAPI.LMSGetValue;
_self.LMSSetValue = newAPI.LMSSetValue;
_self.LMSCommit = newAPI.LMSCommit;
_self.LMSGetLastError = newAPI.LMSGetLastError;
_self.LMSGetErrorString = newAPI.LMSGetErrorString;
_self.LMSGetDiagnostic = newAPI.LMSGetDiagnostic;

// Data Model
_self.cmi = newAPI.cmi;

// Utility Functions
_self.checkState = newAPI.checkState;
_self.getLmsErrorMessageDetails = newAPI.getLmsErrorMessageDetails;
_self.loadFromJSON = newAPI.loadFromJSON;
_self.replaceWithAnotherScormAPI = newAPI.replaceWithAnotherScormAPI;

// API itself
_self = newAPI; // eslint-disable-line consistent-this
}

return _self;
}

Expand Down
28 changes: 28 additions & 0 deletions src/scormAPI2004.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
// Utility Functions
_self.getLmsErrorMessageDetails = getLmsErrorMessageDetails;
_self.loadFromJSON = loadFromJSON;
_self.replaceWithAnotherScormAPI = replaceWithAnotherScormAPI;

/**
* @param Empty String
Expand Down Expand Up @@ -509,6 +510,33 @@
}
}

/**
* Replace the whole API with another
*/
function replaceWithAnotherScormAPI(newAPI) {
// API Signature
_self.Initialize = newAPI.Initialize;
_self.Terminate = newAPI.Terminate;
_self.GetValue = newAPI.GetValue;
_self.SetValue = newAPI.SetValue;
_self.Commit = newAPI.Commit;
_self.GetLastError = newAPI.GetLastError;
_self.GetErrorString = newAPI.GetErrorString;
_self.GetDiagnostic = newAPI.GetDiagnostic;

// Data Model
_self.cmi = newAPI.cmi;
_self.adl = newAPI.adl;

// Utility Functions
_self.getLmsErrorMessageDetails = newAPI.getLmsErrorMessageDetails;
_self.loadFromJSON = newAPI.loadFromJSON;
_self.replaceWithAnotherScormAPI = newAPI.replaceWithAnotherScormAPI;

// API itself
_self = newAPI; // eslint-disable-line consistent-this
}

return _self;
}

Expand Down

0 comments on commit 00689e3

Please sign in to comment.