Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(984)

Unified Diff: third_party/pkg/di/lib/module.dart

Issue 180873006: Update the Angular/DI tests to latest from github. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review feedback Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/pkg/di/lib/generator.dart ('k') | third_party/pkg/di/lib/reflected_type.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/pkg/di/lib/module.dart
diff --git a/third_party/pkg/di/lib/module.dart b/third_party/pkg/di/lib/module.dart
index bcc9677c54cb33bb03bea5e690f163b544625311..a36a80c8baecbfb0dc73a20ea92a07a5eb7d80d1 100644
--- a/third_party/pkg/di/lib/module.dart
+++ b/third_party/pkg/di/lib/module.dart
@@ -22,6 +22,7 @@ typedef dynamic CreationStrategy(
*/
typedef bool Visibility(Injector requesting, Injector defining);
+typedef Object TypeFactory(factory(Type));
/**
* A collection of type bindings. Once the module is passed into the injector,
@@ -31,6 +32,26 @@ typedef bool Visibility(Injector requesting, Injector defining);
class Module {
final Map<Type, _Provider> _providers = <Type, _Provider>{};
final List<Module> _childModules = <Module>[];
+ Map<Type, TypeFactory> _typeFactories = {};
+
+ Map<Type, TypeFactory> get typeFactories {
+ if (_childModules.isEmpty) {
+ return _typeFactories;
+ }
+ var tmp = new Map.from(_typeFactories);
+ _childModules.forEach((child) {
+ if (child.typeFactories != null) {
+ child.typeFactories.forEach((type, factory) {
+ tmp[type] = factory;
+ });
+ }
+ });
+ return tmp;
+ }
+
+ set typeFactories(Map<Type, TypeFactory> factories) {
+ _typeFactories = factories;
+ }
Map<Type, _Provider> _providersCache;
@@ -39,7 +60,7 @@ class Module {
* child (installed) modules.
*/
Map<Type, _Provider> get _bindings {
- if (_providersCache == null) {
+ if (_isDirty) {
_providersCache = <Type, _Provider>{};
_childModules.forEach((child) => _providersCache.addAll(child._bindings));
_providersCache.addAll(_providers);
@@ -54,7 +75,7 @@ class Module {
*/
void value(Type id, value,
{CreationStrategy creation, Visibility visibility}) {
- _providersCache = null;
+ _dirty();
_providers[id] = new _ValueProvider(value, creation, visibility);
}
@@ -67,7 +88,7 @@ class Module {
*/
void type(Type id, {Type implementedBy, CreationStrategy creation,
Visibility visibility}) {
- _providersCache = null;
+ _dirty();
_providers[id] = new _TypeProvider(
implementedBy == null ? id : implementedBy, creation, visibility);
}
@@ -80,7 +101,7 @@ class Module {
*/
void factory(Type id, FactoryFn factoryFn,
{CreationStrategy creation, Visibility visibility}) {
- _providersCache = null;
+ _dirty();
_providers[id] = new _FactoryProvider(factoryFn, creation, visibility);
}
@@ -90,8 +111,15 @@ class Module {
*/
void install(Module module) {
_childModules.add(module);
+ _dirty();
+ }
+
+ _dirty() {
_providersCache = null;
}
+
+ bool get _isDirty =>
+ _providersCache == null || _childModules.any((m) => m._isDirty);
}
/** Deafault creation strategy is to instantiate on the defining injector. */
« no previous file with comments | « third_party/pkg/di/lib/generator.dart ('k') | third_party/pkg/di/lib/reflected_type.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698