Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for default open behavior #5967

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/realm/src/ProgressRealmPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type OpenBehavior = {
function determineBehavior(config: Configuration, realmExists: boolean): OpenBehavior {
const { sync, openSyncedRealmLocally } = config;
if (!sync || openSyncedRealmLocally) {
return { openBehavior: Realm.App.Sync.defaultLocalOpenRealmConfiguration.type };
return { openBehavior: OpenRealmBehaviorType.OpenImmediately };
} else {
const configProperty = realmExists ? "existingRealmFileBehavior" : "newRealmFileBehavior";
const configBehavior = sync[configProperty];
Expand All @@ -52,8 +52,11 @@ function determineBehavior(config: Configuration, realmExists: boolean): OpenBeh
}
return { openBehavior: type, timeOut, timeOutBehavior };
} else {
const { type, timeOut, timeOutBehavior } = Realm.App.Sync.defaultSyncOpenRealmConfiguration;
return { openBehavior: type, timeOut, timeOutBehavior };
return {
openBehavior: OpenRealmBehaviorType.DownloadBeforeOpen,
timeOut: 30 * 1000,
timeOutBehavior: OpenRealmTimeOutBehavior.ThrowException,
};
}
}
}
Expand Down
27 changes: 8 additions & 19 deletions packages/realm/src/app-services/Sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,33 +172,22 @@ export class Sync {
}

/**
* The default OpenRealmBehaviorConfiguration used for local realms.
* This is used if the behavior is not specified by the developer when opening the realm.
* @internal
* The default behavior settings if you want to open a synchronized Realm immediately and start working on it.
* If this is the first time you open the Realm, it will be empty while the server data is being downloaded in the background.
* @deprecated since v12
*/
static defaultLocalOpenRealmConfiguration: Readonly<OpenRealmBehaviorConfiguration> = {

static openLocalRealmBehavior: Readonly<OpenRealmBehaviorConfiguration> = {
type: OpenRealmBehaviorType.OpenImmediately,
};

/**
* The default OpenRealmBehaviorConfiguration used for synced realms.
* This is used if the behavior is not specified by the developer when opening the realm.
* @internal
* The default behavior settings if you want to wait for downloading a synchronized Realm to complete before opening it.
* @deprecated since v12
*/
static defaultSyncOpenRealmConfiguration: Readonly<OpenRealmBehaviorConfiguration> = {
static downloadBeforeOpenBehavior: Readonly<OpenRealmBehaviorConfiguration> = {
type: OpenRealmBehaviorType.DownloadBeforeOpen,
timeOut: 30 * 1000,
timeOutBehavior: OpenRealmTimeOutBehavior.ThrowException,
};

/**
* The default behavior settings if you want to open a synchronized Realm immediately and start working on it.
* If this is the first time you open the Realm, it will be empty while the server data is being downloaded in the background.
*/
static openLocalRealmBehavior = Sync.defaultLocalOpenRealmConfiguration;

/**
* The default behavior settings if you want to wait for downloading a synchronized Realm to complete before opening it.
*/
static downloadBeforeOpenBehavior = Sync.defaultSyncOpenRealmConfiguration;
}
12 changes: 12 additions & 0 deletions packages/realm/src/app-services/SyncConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,23 @@ export type BaseSyncConfiguration = {
user: AnyUser;
/**
* Whether to create a new file and sync in background or wait for the file to be synced.
* @default
* {
* type: OpenRealmBehaviorType.DownloadBeforeOpen,
* timeOut: 30 * 1000,
* timeOutBehavior: OpenRealmTimeOutBehavior.ThrowException,
* }
*/
newRealmFileBehavior?: OpenRealmBehaviorConfiguration;
/**
* Whether to open existing file and sync in background or wait for the sync of the file to complete and then open.
* If not set, the Realm will be downloaded before opened.
* @default
* {
* type: OpenRealmBehaviorType.DownloadBeforeOpen,
* timeOut: 30 * 1000,
* timeOutBehavior: OpenRealmTimeOutBehavior.ThrowException,
* }
*/
existingRealmFileBehavior?: OpenRealmBehaviorConfiguration;
/**
Expand Down
Loading