diff --git a/docs/realm.js b/docs/realm.js index 2bd4c314..be25e46b 100644 --- a/docs/realm.js +++ b/docs/realm.js @@ -95,7 +95,7 @@ class Realm { * Open a realm asynchronously with a promise. If the realm is synced, it will be fully * synchronized before it is available. * @param {Realm~Configuration} config - * @returns {Promise} - a promise that will be resolved with the realm instance when it's available. + * @returns {ProgressPromise} - a promise that will be resolved with the realm instance when it's available. */ static open(config) {} @@ -104,9 +104,10 @@ class Realm { * synchronized before it is available. * @param {Realm~Configuration} config * @param {callback(error, realm)} - will be called when the realm is ready. + * @param {callback(transferred, transferable)} [progressCallback] - an optional callback for download progress notifications * @throws {Error} If anything in the provided `config` is invalid. */ - static openAsync(config, callback) {} + static openAsync(config, callback, progressCallback) {} /** * Closes this Realm so it may be re-opened with a newer schema version. diff --git a/lib/extensions.js b/lib/extensions.js index 3ec8f6cf..1bc9c8d0 100644 --- a/lib/extensions.js +++ b/lib/extensions.js @@ -76,13 +76,7 @@ module.exports = function(realmConstructor) { return promise; }, - openAsync(config, progressCallback, callback) { - - if (!callback) { - callback = progressCallback; - progressCallback = null; - } - + openAsync(config, callback, progressCallback) { realmConstructor._waitForDownload(config, (syncSession) => { if (progressCallback) { diff --git a/lib/index.d.ts b/lib/index.d.ts index 22e65558..a49e6e6c 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -448,10 +448,10 @@ declare class Realm { /** * Open a realm asynchronously with a callback. If the realm is synced, it will be fully synchronized before it is available. * @param {Configuration} config - * @param {ProgressNotificationCallback} progressCallback? a progress notification callback for 'download' direction and 'forCurrentlyOutstandingWork' mode * @param {Function} callback will be called when the realm is ready. + * @param {ProgressNotificationCallback} progressCallback? a progress notification callback for 'download' direction and 'forCurrentlyOutstandingWork' mode */ - static openAsync(config: Realm.Configuration, progressCallback?: Realm.Sync.ProgressNotificationCallback, callback: (error: any, realm: Realm) => void): void + static openAsync(config: Realm.Configuration, callback: (error: any, realm: Realm) => void, progressCallback?: Realm.Sync.ProgressNotificationCallback): void /** * Delete the Realm file for the given configuration. diff --git a/tests/js/session-tests.js b/tests/js/session-tests.js index 153bd6e9..46f6c994 100644 --- a/tests/js/session-tests.js +++ b/tests/js/session-tests.js @@ -626,9 +626,6 @@ module.exports = { let progressCalled = false; Realm.openAsync(config, - (transferred, total) => { - progressCalled = true; - }, (error, realm) => { if (error) { reject(error); @@ -637,6 +634,9 @@ module.exports = { TestCase.assertTrue(progressCalled); resolve(); + }, + (transferred, total) => { + progressCalled = true; }); setTimeout(function() {