Skip to content

Commit f5dae8b

Browse files
committed
Include statement object in Promise fulfillment
* Start documenting where Promises are returned
1 parent 8ce121d commit f5dae8b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ Cmi5.prototype = {
263263
@param {Function} [events.learnerPrefs] Function to run after retrieving learner preferences
264264
@param {Function} [events.initializeStatement] Function to run after saving initialization statement
265265
@param {Object} [additionalProperties] Optional object param with properties to customize method behavior.
266+
@return {Promise}
266267
*/
267268
start: async function (events = {}, additionalProperties) {
268269
this.log("start");
@@ -303,6 +304,7 @@ Cmi5.prototype = {
303304
`setFetch` has to be called first and is called by the constructor if the launch string was provided to it.
304305
305306
@method postFetch
307+
@return {Promise}
306308
*/
307309
postFetch: async function () {
308310
this.log("postFetch");
@@ -352,6 +354,7 @@ Cmi5.prototype = {
352354
Fetch data has to have already been loaded, in order to have LRS credential.
353355
354356
@method loadLMSLaunchData
357+
@return {Promise}
355358
*/
356359
loadLMSLaunchData: async function () {
357360
this.log("loadLMSLaunchData");
@@ -399,6 +402,7 @@ Cmi5.prototype = {
399402
Method to load learner prefs agent profile document possibly populated by the LMS
400403
401404
@method loadLearnerPrefs
405+
@return {Promise}
402406
*/
403407
loadLearnerPrefs: async function () {
404408
this.log("loadLearnerPrefs");
@@ -456,6 +460,7 @@ Cmi5.prototype = {
456460
Method to save learner prefs to agent profile document in LRS
457461
458462
@method saveLearnerPrefs
463+
@return {Promise}
459464
*/
460465
saveLearnerPrefs: async function () {
461466
this.log("saveLearnerPrefs");
@@ -511,6 +516,7 @@ Cmi5.prototype = {
511516
@method initialize
512517
@param {Object} [additionalProperties] Optional object containing properties to append to the cmi5 statement.
513518
@throws {Error} <ul><li>Learner prefs not loaded</li><li>AU already initialized</li></ul>
519+
@return {Promise<statement>} A promise that contains the statement object that was stored
514520
*/
515521
initialize: async function (additionalProperties = {}) {
516522
this.log("initialize");
@@ -540,6 +546,8 @@ Cmi5.prototype = {
540546
this._initialized = true;
541547
this._isActive = true;
542548
this._durationStart = new Date().getTime();
549+
550+
return st;
543551
},
544552

545553
/**
@@ -548,6 +556,7 @@ Cmi5.prototype = {
548556
@method terminate
549557
@param {Object} [additionalProperties] Optional object containing properties to append to the cmi5 statement.
550558
@throws {Error} <ul><li>AU not initialized</li><li>AU already terminated</li></ul>
559+
@return {Promise<statement>} A promise that contains the statement object that was stored
551560
*/
552561
terminate: async function (additionalProperties = {}) {
553562
this.log("terminate");
@@ -572,6 +581,8 @@ Cmi5.prototype = {
572581

573582
this._terminated = true;
574583
this._isActive = false;
584+
585+
return st;
575586
},
576587

577588
/**
@@ -580,6 +591,7 @@ Cmi5.prototype = {
580591
@method completed
581592
@param {Object} [additionalProperties] Optional object containing properties to append to the cmi5 statement.
582593
@throws {Error} <ul><li>AU not active</li><li>AU not in normal launch mode</li><li>AU already completed</li></ul>
594+
@return {Promise<statement>} A promise that contains the statement object that was stored
583595
*/
584596
completed: async function (additionalProperties = {}) {
585597
this.log("completed");
@@ -607,6 +619,8 @@ Cmi5.prototype = {
607619

608620
this.setProgress(null);
609621
this._completed = true;
622+
623+
return st;
610624
},
611625

612626
/**
@@ -615,6 +629,7 @@ Cmi5.prototype = {
615629
@method passed
616630
@param {Object} [score] Score to be included in statement (see `passedStatement`)
617631
@throws {Error} <ul><li>AU not active,</li><li>AU not in Normal launch mode,</li><li>AU already passed,</li><li>Failed to create passed statement (usually because of malformed score)</li></ul>
632+
@return {Promise<statement>} A promise that contains the statement object that was stored
618633
*/
619634
passed: async function (score) {
620635
this.log("passed");
@@ -646,6 +661,8 @@ Cmi5.prototype = {
646661
}
647662

648663
this._passed = true;
664+
665+
return st;
649666
},
650667

651668
/**
@@ -654,6 +671,7 @@ Cmi5.prototype = {
654671
@method failed
655672
@param {Object} [score] Score to be included in statement (see `failedStatement`)
656673
@throws {Error} <ul><li>AU not active</li><li>AU not in Normal launch mode</li><li>AU already passed/failed</li><li>Failed to create failed statement (usually because of malformed score)</li></ul>
674+
@return {Promise<statement>} A promise that contains the statement object that was stored
657675
*/
658676
failed: async function (score) {
659677
this.log("failed");
@@ -685,6 +703,8 @@ Cmi5.prototype = {
685703
}
686704

687705
this._failed = true;
706+
707+
return st;
688708
},
689709

690710
/**
@@ -1308,6 +1328,7 @@ Cmi5.prototype = {
13081328
13091329
@method sendStatement
13101330
@param {Object} st Statement to be stored
1331+
@return {Promise}
13111332
*/
13121333
sendStatement: async function (st) {
13131334
this.log("sendStatement", st);
@@ -1351,6 +1372,7 @@ Cmi5.prototype = {
13511372
13521373
@method sendStatements
13531374
@param {Array} sts Statements to be stored
1375+
@return {Promise}
13541376
*/
13551377
sendStatements: async function (sts) {
13561378
this.log("sendStatements", sts);

0 commit comments

Comments
 (0)