Skip to content

Commit

Permalink
feat: add app and service to all firebase app product
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Sep 4, 2024
1 parent 2db47c3 commit bb1a66a
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ doc/api/

# local files
local.*
.local/
.local/
pubspec_overrides.yaml
17 changes: 5 additions & 12 deletions firebase/lib/firebase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import 'dart:async';

import 'firebase_mixin.dart';
import 'src/app_options.dart';
import 'src/firebase_product_service.dart';
export 'package:tekartik_firebase/src/app_options.dart'
show AppOptions, FirebaseAppOptions, FirebaseAppOptionsMixin;

export 'package:tekartik_firebase/src/firebase.dart'
show firebaseAppNameDefault, FirebaseAppProductService, FirebaseAppProduct;
show firebaseAppNameDefault;
export 'package:tekartik_firebase/src/firebase_app_product.dart'
show FirebaseAppProductService, FirebaseAppProduct;
export 'package:tekartik_firebase/src/firebase_mixin.dart'
show FirebaseProductServiceMixin;
export 'src/firebase_product_service.dart' show FirebaseProductService;

/// Async interface, needed for flutter.
abstract class FirebaseAsync {
Expand Down Expand Up @@ -63,14 +67,3 @@ abstract class FirebaseApp {
static FirebaseApp get instance =>
FirebaseMixin.latestFirebaseInstanceOrNull!;
}

/// Attached firebase service.
///
/// Init is called
abstract class FirebaseProductService {
/// Called when [App.addService] is called
Future<void> init(App app);

/// Called when [App.delete] is called
Future<void> close(App app);
}
12 changes: 0 additions & 12 deletions firebase/lib/src/firebase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,3 @@ import 'package:tekartik_firebase/firebase.dart';

/// The default [FirebaseApp] name.
const firebaseAppNameDefault = '[DEFAULT]';

/// Interface for a firebase service (auth, firestore, storage...)
class FirebaseAppProductService {}

/// Interface for a firebase app service (auth, firestore, storage...)
abstract class FirebaseAppProduct<T> {
/// The type of the product
Type get type;

/// Close the service
void dispose();
}
16 changes: 16 additions & 0 deletions firebase/lib/src/firebase_app_product.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:tekartik_firebase/firebase.dart';

/// Interface for a firebase service (auth, firestore, storage...)
class FirebaseAppProductService {}

/// Interface for a firebase app service (auth, firestore, storage...)
abstract class FirebaseAppProduct<T> {
/// The app
FirebaseApp get app;

/// The type of the product
Type get type;

/// Close the service
void dispose();
}
2 changes: 1 addition & 1 deletion firebase/lib/src/firebase_mixin.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file is use by the implementation, should be considerd like a public api
// although not exposed.
import 'package:tekartik_common_utils/common_utils_import.dart';
import '../firebase.dart';
import 'package:tekartik_firebase/firebase.dart';

/// Firebase mixin
mixin FirebaseMixin implements Firebase {
Expand Down
12 changes: 12 additions & 0 deletions firebase/lib/src/firebase_product_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:tekartik_firebase/firebase.dart';

/// Attached firebase service.
///
/// Init is called
abstract class FirebaseProductService {
/// Called when [App.addService] is called
Future<void> init(App app);

/// Called when [App.delete] is called
Future<void> close(App app);
}
17 changes: 14 additions & 3 deletions firebase/test/firebase_mixin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ class FirebaseAppMock with FirebaseAppMixin {
}

// ignore: unused_element
class _FirebaseAppProductTest with FirebaseAppProductMixin {}
class _FirebaseAppProductTest with FirebaseAppProductMixin {
@override
final FirebaseApp app;

_FirebaseAppProductTest(this.app);
}

// ignore: unused_element
class _FirebaseProductServiceTest with FirebaseProductServiceMixin {}
Expand All @@ -55,7 +60,8 @@ class FirebaseProductServiceMock
int initCount = 0;

FirebaseAppProductMock product(App app) =>
getInstance<FirebaseAppProductMock>(app, FirebaseAppProductMock.new);
getInstance<FirebaseAppProductMock>(
app, () => FirebaseAppProductMock(app));

@override
Future<void> close(App app) async {
Expand All @@ -78,7 +84,12 @@ abstract class FirebaseAppProductMockBase {}

class FirebaseAppProductMock
with FirebaseAppProductMixin<FirebaseAppProductMockBase>
implements FirebaseAppProductMockBase {}
implements FirebaseAppProductMockBase {
@override
final FirebaseApp app;

FirebaseAppProductMock(this.app);
}

void main() {
group('firebase', () {
Expand Down

0 comments on commit bb1a66a

Please sign in to comment.