Skip to content

Commit

Permalink
format files
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobaraujo7 committed Jun 3, 2022
1 parent 99c0ffd commit fc406ce
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
3 changes: 2 additions & 1 deletion flutter_modular/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## [5.0.3] - 2022-06-02
## [5.0.3] - 2022-06-03
- Fix [#713](https://github.com/Flutterando/modular/issues/713)
- Fix [#676](https://github.com/Flutterando/modular/issues/676)
- Fix [#632](https://github.com/Flutterando/modular/issues/632)

Expand Down
36 changes: 28 additions & 8 deletions flutter_modular/lib/src/presenter/models/bind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,38 @@ class Bind<T extends Object> extends BindContract<T> {
}

///Bind an already exist 'Instance' of object..
static Bind<T> instance<T extends Object>(T instance, {bool export = false, dynamic Function(T value)? selector}) {
return Bind<T>((i) => instance, isSingleton: false, isLazy: true, export: export, selector: selector);
static Bind<T> instance<T extends Object>(T instance,
{bool export = false, dynamic Function(T value)? selector}) {
return Bind<T>((i) => instance,
isSingleton: false, isLazy: true, export: export, selector: selector);
}

///Bind a 'Singleton' class.
///Built together with the module.
///The instance will always be the same.
static Bind<T> singleton<T extends Object>(T Function(Injector i) inject, {bool export = false, void Function(T value)? onDispose, dynamic Function(T value)? selector}) {
return Bind<T>(inject, isSingleton: true, isLazy: false, export: export, onDispose: onDispose, selector: selector);
static Bind<T> singleton<T extends Object>(T Function(Injector i) inject,
{bool export = false,
void Function(T value)? onDispose,
dynamic Function(T value)? selector}) {
return Bind<T>(inject,
isSingleton: true,
isLazy: false,
export: export,
onDispose: onDispose,
selector: selector);
}

///Create single instance for request.
static Bind<T> lazySingleton<T extends Object>(T Function(Injector i) inject, {bool export = false, void Function(T value)? onDispose, dynamic Function(T value)? selector}) {
return Bind<T>(inject, isSingleton: true, isLazy: true, export: export, onDispose: onDispose, selector: selector);
static Bind<T> lazySingleton<T extends Object>(T Function(Injector i) inject,
{bool export = false,
void Function(T value)? onDispose,
dynamic Function(T value)? selector}) {
return Bind<T>(inject,
isSingleton: true,
isLazy: true,
export: export,
onDispose: onDispose,
selector: selector);
}

///Bind a factory. Always a new constructor when calling Modular.get
Expand Down Expand Up @@ -82,7 +100,8 @@ class Bind<T extends Object> extends BindContract<T> {
}

/// AsyncBind represents an asynchronous Bind that can be resolved before module initialization by calling Modular.isModuleReady() or called with Modular.getAsync()
class AsyncBind<T extends Object> extends Bind<Future<T>> implements AsyncBindContract<T> {
class AsyncBind<T extends Object> extends Bind<Future<T>>
implements AsyncBindContract<T> {
@override
final Future<T> Function(Injector i) asyncInject;

Expand All @@ -104,7 +123,8 @@ class AsyncBind<T extends Object> extends Bind<Future<T>> implements AsyncBindCo
@override
Future<BindContract<T>> convertToBind() async {
final bindValue = await resolveAsyncBind();
return Bind<T>((i) => bindValue, export: export, alwaysSerialized: true, onDispose: _localOnDispose);
return Bind<T>((i) => bindValue,
export: export, alwaysSerialized: true, onDispose: _localOnDispose);
}

@override
Expand Down
6 changes: 6 additions & 0 deletions flutter_modular/test/src/presenter/models/bind_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter_modular/src/presenter/models/bind.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:modular_core/modular_core.dart';

void main() {
test('bind instance', () {
Expand Down Expand Up @@ -42,4 +43,9 @@ void main() {
final bind = BindInject((i) => 'instance');
expect(bind.copyWith(), isA<Bind>());
});

test('copyWith asyncBind', () async {
final asyncBind = AsyncBind((i) async => 'instance');
expect(asyncBind.copyWith(), isA<AsyncBindContract>());
});
}

0 comments on commit fc406ce

Please sign in to comment.