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

Method initAsync

modules/core/EditSystem.js:118–150  ·  view source on GitHub ↗

* initAsync * Called after all core objects have been constructed. * @return {Promise} Promise resolved when this component has completed initialization

()

Source from the content-addressed store, hash-verified

116 * @return {Promise} Promise resolved when this component has completed initialization
117 */
118 initAsync() {
119 if (this._initPromise) return this._initPromise;
120
121 for (const id of this.dependencies) {
122 if (!this.context.systems[id]) {
123 return Promise.reject(`Cannot init: ${this.id} requires ${id}`);
124 }
125 }
126
127 this._reset();
128
129 const storage = this.context.systems.storage;
130 const prerequisites = storage.initAsync();
131
132 return this._initPromise = prerequisites
133 .then(() => {
134 if (window.mocha) return;
135
136 // Setup event handlers..
137 window.addEventListener('beforeunload', e => {
138 if (this._history.length > 1) { // user did something
139 e.preventDefault();
140 this.saveBackup();
141 return (e.returnValue = ''); // show browser prompt
142 }
143 });
144
145 window.addEventListener('unload', () => this._mutex.unlock());
146
147 // changes are restorable if Rapid is not open in another window/tab and a backup exists in localStorage
148 this._canRestoreBackup = this._mutex.lock() && storage.hasItem(this._backupKey());
149 });
150 }
151
152
153 /**

Callers

nothing calls this directly

Calls 4

_resetMethod · 0.95
saveBackupMethod · 0.95
_backupKeyMethod · 0.95
hasItemMethod · 0.45

Tested by

no test coverage detected