Skip to content

Commit

Permalink
Change factories on Configuration to static methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed May 16, 2022
1 parent 2736998 commit 08639fc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
46 changes: 34 additions & 12 deletions lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,39 +103,61 @@ abstract class Configuration {
final List<int>? encryptionKey;

/// Constructs a [LocalConfiguration]
factory Configuration.local(
static LocalConfiguration local(
List<SchemaObject> schemaObjects, {
InitialDataCallback? initialDataCallback,
int schemaVersion,
int schemaVersion = 0,
String? fifoFilesFallbackPath,
String? path,
bool disableFormatUpgrade,
bool isReadOnly,
bool disableFormatUpgrade = false,
bool isReadOnly = false,
ShouldCompactCallback? shouldCompactCallback,
}) = LocalConfiguration;
}) =>
LocalConfiguration._(
schemaObjects,
initialDataCallback: initialDataCallback,
schemaVersion: schemaVersion,
fifoFilesFallbackPath: fifoFilesFallbackPath,
path: path,
disableFormatUpgrade: disableFormatUpgrade,
isReadOnly: isReadOnly,
shouldCompactCallback: shouldCompactCallback,
);

/// Constructs a [InMemoryConfiguration]
factory Configuration.inMemory(
static InMemoryConfiguration inMemory(
List<SchemaObject> schemaObjects,
String identifier, {
String? fifoFilesFallbackPath,
String? path,
}) = InMemoryConfiguration;
}) =>
InMemoryConfiguration._(
schemaObjects,
identifier,
fifoFilesFallbackPath: fifoFilesFallbackPath,
path: path,
);

/// Constructs a [FlexibleSyncConfiguration]
factory Configuration.sync(
static FlexibleSyncConfiguration sync(
User user,
List<SchemaObject> schemaObjects, {
String? fifoFilesFallbackPath,
String? path,
}) = FlexibleSyncConfiguration;
}) =>
FlexibleSyncConfiguration._(
user,
schemaObjects,
fifoFilesFallbackPath: fifoFilesFallbackPath,
path: path,
);
}

/// [LocalConfiguration] is used to open local [Realm] instances,
/// that are persisted across runs.
/// {@category Configuration}
class LocalConfiguration extends Configuration {
LocalConfiguration(
LocalConfiguration._(
List<SchemaObject> schemaObjects, {
this.initialDataCallback,
this.schemaVersion = 0,
Expand Down Expand Up @@ -195,7 +217,7 @@ class FlexibleSyncConfiguration extends Configuration {

SessionStopPolicy _sessionStopPolicy = SessionStopPolicy.afterChangesUploaded;

FlexibleSyncConfiguration(
FlexibleSyncConfiguration._(
this.user,
List<SchemaObject> schemaObjects, {
String? fifoFilesFallbackPath,
Expand All @@ -216,7 +238,7 @@ extension FlexibleSyncConfigurationInternal on FlexibleSyncConfiguration {
/// are temporary to running process.
/// {@category Configuration}
class InMemoryConfiguration extends Configuration {
InMemoryConfiguration(
InMemoryConfiguration._(
List<SchemaObject> schemaObjects,
this.identifier, {
String? fifoFilesFallbackPath,
Expand Down
4 changes: 2 additions & 2 deletions test/configuration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ Future<void> main([List<String>? args]) async {
});

test('Configuration get/set schema version', () {
final config = LocalConfiguration([Car.schema]);
final config = Configuration.local([Car.schema]);
expect(config.schemaVersion, equals(0));

final explicitSchemaConfig = LocalConfiguration([Car.schema], schemaVersion: 3);
final explicitSchemaConfig = Configuration.local([Car.schema], schemaVersion: 3);
expect(explicitSchemaConfig.schemaVersion, equals(3));
});

Expand Down
2 changes: 1 addition & 1 deletion test/subscription_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void testSubscriptions(String name, FutureOr<void> Function(Realm) tester) async
final app = App(appConfiguration);
final credentials = Credentials.anonymous();
final user = await app.logIn(credentials);
final configuration = FlexibleSyncConfiguration(user, [Task.schema, Schedule.schema])..sessionStopPolicy = SessionStopPolicy.immediately;
final configuration = Configuration.sync(user, [Task.schema, Schedule.schema])..sessionStopPolicy = SessionStopPolicy.immediately;
final realm = getRealm(configuration);
await tester(realm);
});
Expand Down

0 comments on commit 08639fc

Please sign in to comment.