* saveBackup * Backup the user's edits to a JSON string in localStorage. * This code runs occasionally as the user edits.
()
| 1170 | * This code runs occasionally as the user edits. |
| 1171 | */ |
| 1172 | saveBackup() { |
| 1173 | const context = this.context; |
| 1174 | if (context.inIntro) return; // Don't backup edits made in the walkthrough |
| 1175 | if (context.mode?.id === 'save') return; // Edits made in save mode may be conflict resolutions |
| 1176 | if (this._canRestoreBackup) return; // Wait to see if the user wants to restore other edits |
| 1177 | if (this._inTransition) return; // Don't backup edits mid-transition |
| 1178 | if (this._inTransaction) return; // Don't backup edits mid-transaction |
| 1179 | if (!this._mutex.locked()) return; // Another browser tab owns the history |
| 1180 | |
| 1181 | const storage = context.systems.storage; |
| 1182 | const json = this.toJSON(); |
| 1183 | if (json) { |
| 1184 | // status will be `true` if the backup succeeded |
| 1185 | const status = storage.setItem(this._backupKey(), json); |
| 1186 | if (status !== this._backupStatus) { |
| 1187 | this._backupStatus = status; |
| 1188 | this.emit('backupstatuschange', this._backupStatus); |
| 1189 | } |
| 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | |
| 1194 | /** |
no test coverage detected