Inlining the ScheduledCommit class
This commit is contained in:
99
dist/scorm-again.js
vendored
99
dist/scorm-again.js
vendored
File diff suppressed because one or more lines are too long
2
dist/scorm-again.js.map
vendored
2
dist/scorm-again.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/scorm-again.min.js
vendored
2
dist/scorm-again.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -11,6 +11,7 @@ import {unflatten} from './utilities';
|
|||||||
*/
|
*/
|
||||||
export default class BaseAPI {
|
export default class BaseAPI {
|
||||||
#timeout;
|
#timeout;
|
||||||
|
#scheduleCancelled = false;
|
||||||
#error_codes;
|
#error_codes;
|
||||||
#settings = {
|
#settings = {
|
||||||
autocommit: false,
|
autocommit: false,
|
||||||
@@ -905,8 +906,8 @@ export default class BaseAPI {
|
|||||||
* @param {number} when - the number of milliseconds to wait before committing
|
* @param {number} when - the number of milliseconds to wait before committing
|
||||||
*/
|
*/
|
||||||
scheduleCommit(when: number) {
|
scheduleCommit(when: number) {
|
||||||
this.#timeout = new ScheduledCommit(this, when);
|
this.#timeout = setTimeout(this.scheduledCallback, when);
|
||||||
this.apiLog('scheduleCommit', null, null, global_constants.LOG_LEVEL_DEBUG);
|
this.apiLog('scheduleCommit', '', 'scheduled', global_constants.LOG_LEVEL_DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -914,48 +915,19 @@ export default class BaseAPI {
|
|||||||
*/
|
*/
|
||||||
clearScheduledCommit() {
|
clearScheduledCommit() {
|
||||||
if (this.#timeout) {
|
if (this.#timeout) {
|
||||||
this.#timeout.cancel();
|
this.#scheduleCancelled = true;
|
||||||
this.#timeout = null;
|
clearTimeout(this.#timeout);
|
||||||
this.apiLog('clearScheduledCommit', null, null,
|
this.apiLog('clearScheduledCommit', '', 'cleared',
|
||||||
global_constants.LOG_LEVEL_DEBUG);
|
global_constants.LOG_LEVEL_DEBUG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private class that wraps a timeout call to the commit() function
|
* Callback for scheduled commit timeout
|
||||||
*/
|
*/
|
||||||
class ScheduledCommit {
|
scheduledCallback() {
|
||||||
#API;
|
if (!this.#scheduleCancelled) {
|
||||||
#cancelled = false;
|
this.commit('Commit', false);
|
||||||
#timeout;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for ScheduledCommit
|
|
||||||
* @param {BaseAPI} API
|
|
||||||
* @param {number} when
|
|
||||||
*/
|
|
||||||
constructor(API: any, when: number) {
|
|
||||||
this.#API = API;
|
|
||||||
this.#timeout = setTimeout(this.wrapper, when);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancel any currently scheduled commit
|
|
||||||
*/
|
|
||||||
cancel() {
|
|
||||||
this.#cancelled = true;
|
|
||||||
if (this.#timeout) {
|
|
||||||
clearTimeout(this.#timeout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrap the API commit call to check if the call has already been cancelled
|
|
||||||
*/
|
|
||||||
wrapper() {
|
|
||||||
if (!this.#cancelled) {
|
|
||||||
this.#API.commit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user