Skip to content

Commit

Permalink
Working on fixing debounce not working as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
jcputney committed Oct 25, 2024
1 parent 2791a2b commit 3f52740
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/BaseAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,20 @@ export default abstract class BaseAPI implements IBaseAPI {
this._error_codes.COMMIT_AFTER_TERM,
)
) {
const result = await this.storeData(false);
if (result.errorCode && result.errorCode > 0) {
this.throwSCORMError(result.errorCode);
if (this.settings.asyncCommit) {
debounce(this.storeData, 500, false)(false);

returnValue = APIConstants.global.SCORM_TRUE;
} else {
const result = await this.storeData(false);
if (result.errorCode && result.errorCode > 0) {
this.throwSCORMError(result.errorCode);
}
returnValue =
typeof result !== "undefined" && result.result
? result.result
: APIConstants.global.SCORM_FALSE;
}
returnValue =
typeof result !== "undefined" && result.result
? result.result
: APIConstants.global.SCORM_FALSE;

this.apiLog(
callbackName,
Expand Down Expand Up @@ -1174,17 +1180,7 @@ export default abstract class BaseAPI implements IBaseAPI {
}
};

if (this.settings.asyncCommit) {
const debouncedProcess = debounce(process, 500, immediate);
debouncedProcess(url, params, this.settings);

return {
result: APIConstants.global.SCORM_TRUE,
errorCode: 0,
};
} else {
return await process(url, params, this.settings);
}
return await process(url, params, this.settings);
}

/**
Expand Down

0 comments on commit 3f52740

Please sign in to comment.