MCPcopy Create free account
hub / github.com/facebook/Rapid / saveBackup

Method saveBackup

modules/core/EditSystem.js:1172–1191  ·  view source on GitHub ↗

* saveBackup * Backup the user's edits to a JSON string in localStorage. * This code runs occasionally as the user edits.

()

Source from the content-addressed store, hash-verified

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 /**

Callers 1

initAsyncMethod · 0.95

Calls 4

toJSONMethod · 0.95
_backupKeyMethod · 0.95
lockedMethod · 0.80
setItemMethod · 0.45

Tested by

no test coverage detected