Skip to content

Commit

Permalink
switch cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo committed Dec 10, 2024
1 parent e2a5f18 commit af5cc5d
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 254 deletions.
26 changes: 9 additions & 17 deletions packages/cloud_firestore/cloud_firestore/dartpad/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,15 @@ enum MovieQuery {
extension on Query<Movie> {
/// Create a firebase query from a [MovieQuery]
Query<Movie> queryBy(MovieQuery query) {
switch (query) {
case MovieQuery.fantasy:
return where('genre', arrayContainsAny: ['Fantasy']);

case MovieQuery.sciFi:
return where('genre', arrayContainsAny: ['Sci-Fi']);

case MovieQuery.likesAsc:
case MovieQuery.likesDesc:
return orderBy('likes', descending: query == MovieQuery.likesDesc);

case MovieQuery.year:
return orderBy('year', descending: true);

case MovieQuery.score:
return orderBy('score', descending: true);
}
return switch (query) {
MovieQuery.fantasy => where('genre', arrayContainsAny: ['Fantasy']),
MovieQuery.sciFi => where('genre', arrayContainsAny: ['Sci-Fi']),
MovieQuery.likesAsc ||
MovieQuery.likesDesc =>
orderBy('likes', descending: query == MovieQuery.likesDesc),
MovieQuery.year => orderBy('year', descending: true),
MovieQuery.score => orderBy('score', descending: true)
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,19 @@ class DefaultFirebaseOptions {
if (kIsWeb) {
return web;
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
return android;
case TargetPlatform.iOS:
return ios;
case TargetPlatform.macOS:
return macos;
case TargetPlatform.windows:
return android;
case TargetPlatform.linux:
throw UnsupportedError(
return switch (defaultTargetPlatform) {
TargetPlatform.android => android,
TargetPlatform.iOS => ios,
TargetPlatform.macOS => macos,
TargetPlatform.windows => android,
TargetPlatform.linux => throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for linux - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
default:
throw UnsupportedError(
),
_ => throw UnsupportedError(
'DefaultFirebaseOptions are not supported for this platform.',
);
}
)
};
}

static const FirebaseOptions web = FirebaseOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,15 @@ class DefaultFirebaseOptions {
if (kIsWeb) {
return web;
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
return android;
case TargetPlatform.iOS:
return ios;
case TargetPlatform.macOS:
return macos;
case TargetPlatform.windows:
return android;
default:
throw UnsupportedError(
return switch (defaultTargetPlatform) {
TargetPlatform.android => android,
TargetPlatform.iOS => ios,
TargetPlatform.macOS => macos,
TargetPlatform.windows => android,
_ => throw UnsupportedError(
'DefaultFirebaseOptions are not supported for this platform.',
);
}
)
};
}

static const FirebaseOptions web = FirebaseOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,19 @@ class DefaultFirebaseOptions {
if (kIsWeb) {
return web;
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
return android;
case TargetPlatform.iOS:
return ios;
case TargetPlatform.macOS:
return macos;
case TargetPlatform.windows:
return android;
case TargetPlatform.linux:
throw UnsupportedError(
return switch (defaultTargetPlatform) {
TargetPlatform.android => android,
TargetPlatform.iOS => ios,
TargetPlatform.macOS => macos,
TargetPlatform.windows => android,
TargetPlatform.linux => throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for linux - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
default:
throw UnsupportedError(
),
_ => throw UnsupportedError(
'DefaultFirebaseOptions are not supported for this platform.',
);
}
)
};
}

static const FirebaseOptions web = FirebaseOptions(
Expand Down
26 changes: 9 additions & 17 deletions packages/cloud_firestore/cloud_firestore/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,15 @@ enum MovieQuery {
extension on Query<Movie> {
/// Create a firebase query from a [MovieQuery]
Query<Movie> queryBy(MovieQuery query) {
switch (query) {
case MovieQuery.fantasy:
return where('genre', arrayContainsAny: ['fantasy']);

case MovieQuery.sciFi:
return where('genre', arrayContainsAny: ['sci-fi']);

case MovieQuery.likesAsc:
case MovieQuery.likesDesc:
return orderBy('likes', descending: query == MovieQuery.likesDesc);

case MovieQuery.year:
return orderBy('year', descending: true);

case MovieQuery.rated:
return orderBy('rated', descending: true);
}
return switch (query) {
MovieQuery.fantasy => where('genre', arrayContainsAny: ['fantasy']),
MovieQuery.sciFi => where('genre', arrayContainsAny: ['sci-fi']),
MovieQuery.likesAsc ||
MovieQuery.likesDesc =>
orderBy('likes', descending: query == MovieQuery.likesDesc),
MovieQuery.year => orderBy('year', descending: true),
MovieQuery.rated => orderBy('rated', descending: true)
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@ import '../../pigeon/messages.pigeon.dart';

/// Converts [Source] to [String]
String getSourceString(Source source) {
switch (source) {
case Source.server:
return 'server';
case Source.cache:
return 'cache';
default:
return 'default';
}
return switch (source) {
Source.server => 'server',
Source.cache => 'cache',
_ => 'default'
};
}

/// Converts [AggregateSource] to [String]
String getAggregateSourceString(AggregateSource source) {
switch (source) {
case AggregateSource.server:
return 'server';
}
return switch (source) {
AggregateSource.server => 'server',
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
import 'package:cloud_firestore_platform_interface/cloud_firestore_platform_interface.dart';

LoadBundleTaskState convertToTaskState(String state) {
switch (state) {
case 'running':
return LoadBundleTaskState.running;
case 'success':
return LoadBundleTaskState.success;
case 'error':
return LoadBundleTaskState.error;
default:
throw UnsupportedError('Unknown LoadBundleTaskState value: $state.');
}
return switch (state) {
'running' => LoadBundleTaskState.running,
'success' => LoadBundleTaskState.success,
'error' => LoadBundleTaskState.error,
_ => throw UnsupportedError('Unknown LoadBundleTaskState value: $state.')
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
// ignore_for_file: avoid_relative_lib_imports
import 'dart:async';
import 'dart:typed_data' show Uint8List;

import 'package:cloud_firestore_platform_interface/src/pigeon/messages.pigeon.dart';
import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:cloud_firestore_platform_interface/src/pigeon/messages.pigeon.dart';

class _TestFirebaseFirestoreHostApiCodec extends StandardMessageCodec {
const _TestFirebaseFirestoreHostApiCodec();
@override
Expand Down Expand Up @@ -63,36 +63,22 @@ class _TestFirebaseFirestoreHostApiCodec extends StandardMessageCodec {

@override
Object? readValueOfType(int type, ReadBuffer buffer) {
switch (type) {
case 128:
return AggregateQuery.decode(readValue(buffer)!);
case 129:
return AggregateQueryResponse.decode(readValue(buffer)!);
case 130:
return DocumentReferenceRequest.decode(readValue(buffer)!);
case 131:
return FirestorePigeonFirebaseApp.decode(readValue(buffer)!);
case 132:
return PigeonDocumentChange.decode(readValue(buffer)!);
case 133:
return PigeonDocumentOption.decode(readValue(buffer)!);
case 134:
return PigeonDocumentSnapshot.decode(readValue(buffer)!);
case 135:
return PigeonFirebaseSettings.decode(readValue(buffer)!);
case 136:
return PigeonGetOptions.decode(readValue(buffer)!);
case 137:
return PigeonQueryParameters.decode(readValue(buffer)!);
case 138:
return PigeonQuerySnapshot.decode(readValue(buffer)!);
case 139:
return PigeonSnapshotMetadata.decode(readValue(buffer)!);
case 140:
return PigeonTransactionCommand.decode(readValue(buffer)!);
default:
return super.readValueOfType(type, buffer);
}
return switch (type) {
128 => AggregateQuery.decode(readValue(buffer)!),
129 => AggregateQueryResponse.decode(readValue(buffer)!),
130 => DocumentReferenceRequest.decode(readValue(buffer)!),
131 => FirestorePigeonFirebaseApp.decode(readValue(buffer)!),
132 => PigeonDocumentChange.decode(readValue(buffer)!),
133 => PigeonDocumentOption.decode(readValue(buffer)!),
134 => PigeonDocumentSnapshot.decode(readValue(buffer)!),
135 => PigeonFirebaseSettings.decode(readValue(buffer)!),
136 => PigeonGetOptions.decode(readValue(buffer)!),
137 => PigeonQueryParameters.decode(readValue(buffer)!),
138 => PigeonQuerySnapshot.decode(readValue(buffer)!),
139 => PigeonSnapshotMetadata.decode(readValue(buffer)!),
140 => PigeonTransactionCommand.decode(readValue(buffer)!),
_ => super.readValueOfType(type, buffer)
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ Firestore getFirestoreInstance([
}

JSString convertListenSource(ListenSource source) {
switch (source) {
case ListenSource.defaultSource:
return 'default'.toJS;
case ListenSource.cache:
return 'cache'.toJS;
}
return switch (source) {
ListenSource.defaultSource => 'default'.toJS,
ListenSource.cache => 'cache'.toJS
};
}

/// The Cloud Firestore service interface.
Expand Down Expand Up @@ -199,17 +197,16 @@ class Firestore extends JsObjectWrapper<firestore_interop.FirestoreJsImpl> {
firestore_interop.getPersistentCacheIndexManager(jsObject);

if (indexManager != null) {
switch (request) {
case PersistenceCacheIndexManagerRequest.enableIndexAutoCreation:
return firestore_interop
.enablePersistentCacheIndexAutoCreation(indexManager);
case PersistenceCacheIndexManagerRequest.disableIndexAutoCreation:
return firestore_interop
.disablePersistentCacheIndexAutoCreation(indexManager);
case PersistenceCacheIndexManagerRequest.deleteAllIndexes:
return firestore_interop
.deleteAllPersistentCacheIndexes(indexManager);
}
return switch (request) {
PersistenceCacheIndexManagerRequest.enableIndexAutoCreation =>
firestore_interop
.enablePersistentCacheIndexAutoCreation(indexManager),
PersistenceCacheIndexManagerRequest.disableIndexAutoCreation =>
firestore_interop
.disablePersistentCacheIndexAutoCreation(indexManager),
PersistenceCacheIndexManagerRequest.deleteAllIndexes =>
firestore_interop.deleteAllPersistentCacheIndexes(indexManager)
};
} else {
// ignore: avoid_print
print('Firestore: `PersistentCacheIndexManager` is not available');
Expand Down
Loading

0 comments on commit af5cc5d

Please sign in to comment.