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 1 commit
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
15 changes: 12 additions & 3 deletions packages/realm/src/ProgressRealmPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,20 @@ type OpenBehavior = {
timeOutBehavior?: OpenRealmTimeOutBehavior;
};

const defaultLocalOpenRealmConfiguration = {
openBehavior: OpenRealmBehaviorType.OpenImmediately,
};

const defaultSyncOpenRealmConfiguration = {
openBehavior: OpenRealmBehaviorType.DownloadBeforeOpen,
timeOut: 30 * 1000,
timeOutBehavior: OpenRealmTimeOutBehavior.ThrowException,
};
takameyer marked this conversation as resolved.
Show resolved Hide resolved

function determineBehavior(config: Configuration, realmExists: boolean): OpenBehavior {
const { sync, openSyncedRealmLocally } = config;
if (!sync || openSyncedRealmLocally) {
return { openBehavior: Realm.App.Sync.defaultLocalOpenRealmConfiguration.type };
return defaultLocalOpenRealmConfiguration;
} else {
const configProperty = realmExists ? "existingRealmFileBehavior" : "newRealmFileBehavior";
const configBehavior = sync[configProperty];
Expand All @@ -52,8 +62,7 @@ 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 defaultSyncOpenRealmConfiguration;
}
}
}
Expand Down
27 changes: 7 additions & 20 deletions packages/realm/src/app-services/Sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
Logger,
MutableSubscriptionSet,
NumericLogLevel,
OpenRealmBehaviorConfiguration,
OpenRealmBehaviorType,
OpenRealmTimeOutBehavior,
PartitionValue,
Expand Down Expand Up @@ -172,33 +171,21 @@ 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 = {
type: OpenRealmBehaviorType.OpenImmediately,
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing Readonly<OpenRealmBehaviorConfiguration> might have been accidental? (Same for static downloadBeforeOpenBehavior)

Also, see earlier comment regarding having this reference what is being used internally as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was accidental.


/**
* 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 = {
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;
}
16 changes: 16 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,27 @@ export type BaseSyncConfiguration = {
user: AnyUser;
/**
* Whether to create a new file and sync in background or wait for the file to be synced.
* The default behavior is:
*```
* {
* type: OpenRealmBehaviorType.DownloadBeforeOpen,
* timeOut: 30 * 1000,
* timeOutBehavior: OpenRealmTimeOutBehavior.ThrowException,
* }
* ```
takameyer marked this conversation as resolved.
Show resolved Hide resolved
*/
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.
* The default behavior is:
*```
* {
* type: OpenRealmBehaviorType.DownloadBeforeOpen,
* timeOut: 30 * 1000,
* timeOutBehavior: OpenRealmTimeOutBehavior.ThrowException,
* }
* ```
takameyer marked this conversation as resolved.
Show resolved Hide resolved
*/
existingRealmFileBehavior?: OpenRealmBehaviorConfiguration;
/**
Expand Down
Loading