/** * Type of update status can be recorded * An update flag is used here to implement data lazy calculation * @copyright MrKBear 2022 */ abstract class UpdatedRecorder { /** * The flag for recorded update status * @defaultValue `true` */ protected updateFlag: boolean = true; /** * Initialize and set the default update status * @param updateFlag update status */ public constructor(updateFlag: boolean = true) { this.updateFlag = updateFlag; } /** * Return the update status * @returns update status */ public isUpdated(): boolean { return this.updateFlag; } /** * Set update status `false` * @returns update status */ public unsetUpdated(): false { return this.updateFlag = false; } /** * Automatically detect and reset update status * @returns update status */ public testAndUnsetUpdate(): boolean { if (this.updateFlag) { this.updateFlag = false; return true; } else { return false; } } } export { UpdatedRecorder };