Skip to content

Commit

Permalink
wip refactoring some old code
Browse files Browse the repository at this point in the history
fix importing issue for bin/test folders
support injectables in register module custom initializr
  • Loading branch information
Milad Alakarie committed May 11, 2020
1 parent 1630827 commit 8fba365
Show file tree
Hide file tree
Showing 25 changed files with 308 additions and 398 deletions.
7 changes: 1 addition & 6 deletions example/.packages
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by pub on 2020-04-28 23:59:20.333515.
# Generated by pub on 2020-05-11 23:01:07.204920.
_fe_analyzer_shared:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/_fe_analyzer_shared-1.0.3/lib/
analyzer:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-0.39.4/lib/
args:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/args-1.5.3/lib/
Expand All @@ -21,15 +21,13 @@ crypto:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/cr
csslib:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/csslib-0.16.1/lib/
dart_style:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/dart_style-1.3.3/lib/
fixnum:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/fixnum-0.10.11/lib/
flutter:file:///Users/milad/dev/sdk/flutter/packages/flutter/lib/
get_it:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/get_it-4.0.0/lib/
glob:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/glob-1.2.0/lib/
graphs:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/graphs-0.2.0/lib/
html:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/html-0.14.0+3/lib/
http:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.0+4/lib/
http_multi_server:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/http_multi_server-2.2.0/lib/
http_parser:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/http_parser-3.1.3/lib/
i18n_extension:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/i18n_extension-1.3.5/lib/
injectable:../injectable/lib/
injectable_generator:../injectable_generator/lib/
io:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/io-0.3.3/lib/
Expand All @@ -52,10 +50,8 @@ pubspec_parse:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang
quiver:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/quiver-2.1.3/lib/
shelf:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shelf-0.7.5/lib/
shelf_web_socket:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shelf_web_socket-0.2.3/lib/
sky_engine:file:///Users/milad/dev/sdk/flutter/bin/cache/pkg/sky_engine/lib/
source_gen:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/source_gen-0.9.5/lib/
source_span:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/source_span-1.6.0/lib/
sprintf:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/sprintf-4.0.2/lib/
stack_trace:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.9.3/lib/
stream_channel:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/stream_channel-2.0.0/lib/
stream_transform:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/stream_transform-1.2.0/lib/
Expand All @@ -64,7 +60,6 @@ term_glyph:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.or
test_api:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/test_api-0.2.15/lib/
timing:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/timing-0.1.1+2/lib/
typed_data:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/typed_data-1.1.6/lib/
vector_math:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/
watcher:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/watcher-0.9.7+13/lib/
web_socket_channel:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/web_socket_channel-1.1.0/lib/
yaml:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/yaml-2.2.0/lib/
Expand Down
3 changes: 1 addition & 2 deletions example/bin/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:example/injector.dart';

void main(List<String> arguments) {
configure();
print('x');
configureDependecies();
}
4 changes: 1 addition & 3 deletions example/lib/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ import 'injector.iconfig.dart';
final getIt = GetIt.instance;

@injectableInit
Future<void> configure() async {
return $initGetIt(getIt);
}
void configureDependecies() => $initGetIt(getIt);
29 changes: 8 additions & 21 deletions example/lib/injector.iconfig.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 18 additions & 47 deletions example/lib/register_module.dart
Original file line number Diff line number Diff line change
@@ -1,55 +1,26 @@
import 'package:example/user.dart';
import 'package:injectable/injectable.dart';
import 'package:i18n_extension/default.i18n.dart';

import 'generic.dart';

@registerModule
@module
abstract class RegisterModule {
// AbsService get absS;
// Future<ServiceX> genIml(String x, int y) async => ServiceX();
// @singleton
// ServiceX ser();
// @singleton
// TestClass get testClass;
// TestSingleton2 get testSing33;

BackendService testSing(User<Generic> x, int y) =>
BackendService("Title".i18n);

// BackendService getService(String url) => BackendService(url);
// @preResolve
// @Singleton(dependsOn: [TestClass])
// Future<TestSingleton> get futureSing => TestSingleton.create();

// TestSingleton2 get test;
@preResolve
Future<ApiClient> get apiClient => ApiClient.create();
}
// @Singleton(as: LocalStorage)
LocalStorage apiClient(
@factoryParam String url,
LocalStorage localStorage,
@factoryParam int x,
) =>
ApiClient.named(url);

// // @Named("class")
// // @injectable
// class TestSingleton2 {
// TestSingleton2(AbsService service);
// }

// abstract class AbsService<T> {}

// @injectable
class BackendService {
final String title;

BackendService(this.title);
// @singleton
// ApiClient api(String x) => ApiClient.named(x);
}

// @RegisterAs(BackendService, env: 'test')
// @injectable
// class BackendServiceMock extends Mock implements BackendService {}

// @injectable
class ApiClient {
// @singleton
// @RegisterAs(LocalStorage)
// @test
@Injectable(as: LocalStorage)
class ApiClient extends LocalStorage {
@factoryMethod
static Future<ApiClient> create() async {
return ApiClient();
}
ApiClient.named(String url);
}

abstract class LocalStorage {}
72 changes: 0 additions & 72 deletions example/lib/services.dart

This file was deleted.

33 changes: 1 addition & 32 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.11"
flutter:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
get_it:
dependency: "direct main"
description:
Expand Down Expand Up @@ -209,13 +204,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.3"
i18n_extension:
dependency: "direct main"
description:
name: i18n_extension
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.5"
injectable:
dependency: "direct main"
description:
Expand All @@ -229,7 +217,7 @@ packages:
path: "../injectable_generator"
relative: true
source: path
version: "0.3.4"
version: "0.3.5"
io:
dependency: transitive
description:
Expand Down Expand Up @@ -370,11 +358,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.3"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_gen:
dependency: transitive
description:
Expand All @@ -389,13 +372,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
sprintf:
dependency: transitive
description:
name: sprintf
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.2"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -452,13 +428,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
watcher:
dependency: transitive
description:
Expand Down
1 change: 0 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies:
# sdk: flutter
get_it: 4.0.0
mockito: ^4.1.1
i18n_extension:
injectable:
path: ../injectable
# path: ^1.6.0
Expand Down
36 changes: 23 additions & 13 deletions injectable/lib/src/injectable_annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,38 @@ class InjectableInit {
const injectableInit = const InjectableInit._();

class Injectable {
const Injectable._();
final Type as;
final String env;
const Injectable({this.as, this.env});
}

const injectable = const Injectable._();
const injectable = const Injectable();

/// Classes annotated with @Singleton
/// will generate registerSingleton or
/// registerLazySingleton if [_lazy] is true
/// will generate registerSingleton func
class Singleton extends Injectable {
final bool signalsReady;
final bool _lazy;
final List<Type> dependsOn;

const Singleton({this.signalsReady, this.dependsOn})
: _lazy = false,
super._();
const Singleton({
this.signalsReady,
this.dependsOn,
Type as,
String env,
}) : super(as: as, env: env);
}

const Singleton.lazy({this.signalsReady})
: _lazy = true,
dependsOn = null,
super._();
/// Classes annotated with @LazySingleton
/// will generate registerLazySingleton func
class LazySingleton extends Injectable {
const LazySingleton({
Type as,
String env,
}) : super(as: as, env: env);
}

const singleton = const Singleton();
const lazySingleton = const Singleton.lazy();
const lazySingleton = const LazySingleton();

// Used to annotate a constructor dependency
// that's registered with an instance names;
Expand Down Expand Up @@ -102,8 +109,11 @@ class RegisterModule {
const RegisterModule._();
}

@Deprecated('Use module instead')
const registerModule = const RegisterModule._();

const module = const RegisterModule._();

/// Futures annotated with [preResolv]
/// will be pre-awaited before they're
/// registered inside of GetIt
Expand Down
1 change: 1 addition & 0 deletions injectable_generator/lib/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'injectable_generator.dart';
Builder injectableBuilder(BuilderOptions options) {
return LibraryBuilder(
InjectableGenerator(options.config),
formatOutput: (generated) => generated.replaceAll(RegExp(r'//.*|\s'), ''),
generatedExtension: '.injectable.json',
);
}
Expand Down
Loading

0 comments on commit 8fba365

Please sign in to comment.