From bb16d928750bec3a319bf8893bbf740f90ddd815 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 24 Jul 2014 12:22:08 +0200 Subject: [PATCH 1/2] fix: Remove deprecated calls to DI bind(Type, inject[]) fixes #1259 closes #1260 --- lib/core/module_internal.dart | 6 ++-- lib/core_dom/module_internal.dart | 4 +-- lib/mock/module.dart | 2 +- lib/tools/expression_extractor.dart | 4 +-- pubspec.lock | 32 ++++++++++++------- pubspec.yaml | 2 +- .../parser/generated_getter_setter_spec.dart | 2 +- 7 files changed, 30 insertions(+), 22 deletions(-) diff --git a/lib/core/module_internal.dart b/lib/core/module_internal.dart index 7ead73d8a..5b98206b0 100644 --- a/lib/core/module_internal.dart +++ b/lib/core/module_internal.dart @@ -40,15 +40,15 @@ class CoreModule extends Module { bind(FormatterMap); bind(Interpolate); bind(RootScope); - bind(Scope, inject: [RootScope]); + bind(Scope, toInstanceOf: RootScope); bind(ClosureMap, toFactory: () => throw "Must provide dynamic/static ClosureMap.", inject: []); bind(ScopeStats); bind(ScopeStatsEmitter); bind(ScopeStatsConfig); bind(Object, toValue: {}); // RootScope context - bind(Parser, inject: [DynamicParser]); - bind(ParserBackend, inject: [DynamicParserBackend]); + bind(Parser, toInstanceOf: DynamicParser); + bind(ParserBackend, toInstanceOf: DynamicParserBackend); bind(DynamicParser); bind(DynamicParserBackend); bind(Lexer); diff --git a/lib/core_dom/module_internal.dart b/lib/core_dom/module_internal.dart index b794ba097..e599d30ae 100644 --- a/lib/core_dom/module_internal.dart +++ b/lib/core_dom/module_internal.dart @@ -72,14 +72,14 @@ class CoreDomModule extends Module { bind(Compiler, toImplementation: TaggingCompiler); bind(CompilerConfig); - bind(ComponentFactory, inject: [SHADOW_DOM_COMPONENT_FACTORY_KEY]); + bind(ComponentFactory, toInstanceOf: SHADOW_DOM_COMPONENT_FACTORY_KEY); bind(ShadowDomComponentFactory); bind(TranscludingComponentFactory); bind(Content); bind(ContentPort, toValue: null); bind(ComponentCssRewriter); bind(WebPlatform); - + bind(Http); bind(UrlRewriter); bind(HttpBackend); diff --git a/lib/mock/module.dart b/lib/mock/module.dart index 4c0b4535f..6978540d4 100644 --- a/lib/mock/module.dart +++ b/lib/mock/module.dart @@ -63,7 +63,7 @@ class AngularMockModule extends Module { bind(MockHttpBackend); bind(Element, toValue: document.body); bind(Node, toValue: document.body); - bind(HttpBackend, inject:[MOCK_HTTP_BACKEND_KEY]); + bind(HttpBackend, toInstanceOf: MOCK_HTTP_BACKEND_KEY); bind(VmTurnZone, toFactory: () { return new VmTurnZone() ..onError = (e, s, LongStackTrace ls) => dump('EXCEPTION: $e\n$s\n$ls'); diff --git a/lib/tools/expression_extractor.dart b/lib/tools/expression_extractor.dart index 0a10b9ac6..acc231aa5 100644 --- a/lib/tools/expression_extractor.dart +++ b/lib/tools/expression_extractor.dart @@ -58,8 +58,8 @@ main(args) { ..bind(DynamicParser) ..bind(DartGetterSetterGen) ..bind(CacheRegister) - ..bind(Parser, inject: [DynamicParser]) - ..bind(ParserBackend, inject: [DartGetterSetterGen]); + ..bind(Parser, toInstanceOf: DynamicParser) + ..bind(ParserBackend, toInstanceOf: DartGetterSetterGen); Injector injector = new ModuleInjector([module]); runZoned(() { diff --git a/pubspec.lock b/pubspec.lock index c6994cc37..1660722b2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -4,7 +4,7 @@ packages: analyzer: description: analyzer source: hosted - version: "0.15.7" + version: "0.18.0" args: description: args source: hosted @@ -12,7 +12,7 @@ packages: barback: description: barback source: hosted - version: "0.13.0" + version: "0.14.1+3" benchmark_harness: description: benchmark_harness source: hosted @@ -24,11 +24,11 @@ packages: code_transformers: description: code_transformers source: hosted - version: "0.1.4+2" + version: "0.1.5" collection: description: collection source: hosted - version: "0.9.2" + version: "0.9.4" di: description: di source: hosted @@ -44,7 +44,7 @@ packages: intl: description: intl source: hosted - version: "0.9.10" + version: "0.8.10+4" js: description: js source: hosted @@ -56,15 +56,19 @@ packages: matcher: description: matcher source: hosted - version: "0.10.0" + version: "0.11.0" + meta: + description: meta + source: hosted + version: "0.8.8" mock: description: mock source: hosted - version: "0.11.0+1" + version: "0.11.0+2" path: description: path source: hosted - version: "1.2.0" + version: "1.2.1" perf_api: description: perf_api source: hosted @@ -80,15 +84,19 @@ packages: source_maps: description: source_maps source: hosted - version: "0.9.0" + version: "0.9.3" stack_trace: description: stack_trace source: hosted - version: "0.9.3+2" + version: "1.0.2" + typed_mock: + description: typed_mock + source: hosted + version: "0.0.4" unittest: description: unittest source: hosted - version: "0.11.0" + version: "0.11.0+3" utf: description: utf source: hosted @@ -96,4 +104,4 @@ packages: web_components: description: web_components source: hosted - version: "0.3.4" + version: "0.3.5+1" diff --git a/pubspec.yaml b/pubspec.yaml index 50a3dd823..9ef6dafa1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: browser: '>=0.10.0 <0.11.0' code_transformers: '>=0.1.4+2 <0.2.0' collection: '>=0.9.1 <1.0.0' - di: '>=2.0.0 <3.0.0' + di: '>=2.0.1 <3.0.0' html5lib: '>=0.10.0 <0.11.0' intl: '>=0.8.7 <0.10.0' perf_api: '>=0.0.8 <0.1.0' diff --git a/test/core/parser/generated_getter_setter_spec.dart b/test/core/parser/generated_getter_setter_spec.dart index 5e44e8126..74a4d93e4 100644 --- a/test/core/parser/generated_getter_setter_spec.dart +++ b/test/core/parser/generated_getter_setter_spec.dart @@ -7,7 +7,7 @@ import 'generated_getter_setter.dart' as gen; main() { describe('hybrid getter-setter', () { beforeEachModule((Module module) { - module..bind(Parser, inject: [DynamicParser]) + module..bind(Parser, toInstanceOf: DynamicParser) ..bind(ClosureMap, toValue: gen.closureMap); }); parser_spec.main(); From f8bbd35ffdfd21005be118e45ddc8d3dd6a265ce Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 25 Jul 2014 09:21:45 +0200 Subject: [PATCH 2/2] feat(DirectiveInjector): add a toInstanceOf parameter to bind() --- lib/core/annotation_src.dart | 7 ++++++- lib/core_dom/directive_injector.dart | 24 +++++++++++++----------- lib/core_dom/element_binder.dart | 14 -------------- lib/directive/ng_form.dart | 2 +- lib/routing/ng_bind_route.dart | 4 ++-- lib/routing/ng_view.dart | 4 ++-- test/core_dom/compiler_spec.dart | 3 ++- 7 files changed, 26 insertions(+), 32 deletions(-) diff --git a/lib/core/annotation_src.dart b/lib/core/annotation_src.dart index ee478ec20..11357d563 100644 --- a/lib/core/annotation_src.dart +++ b/lib/core/annotation_src.dart @@ -3,7 +3,12 @@ library angular.core.annotation_src; import "package:di/di.dart" show Injector, Visibility, Factory; abstract class DirectiveBinder { - bind(key, {Function toFactory, inject, Visibility visibility: Visibility.CHILDREN}); + void bind(key, {dynamic toValue, + Function toFactory, + Type toImplementation, + toInstanceOf, + inject: const[], + Visibility visibility: Visibility.LOCAL}); } typedef void DirectiveBinderFn(DirectiveBinder module); diff --git a/lib/core_dom/directive_injector.dart b/lib/core_dom/directive_injector.dart index 3b8dda2f7..7e10f74b2 100644 --- a/lib/core_dom/directive_injector.dart +++ b/lib/core_dom/directive_injector.dart @@ -99,7 +99,7 @@ class DirectiveInjector implements DirectiveBinder { , EVENT_HANDLER_KEY , KEEP_ME_LAST ]; - + final DirectiveInjector parent; final Injector appInjector; final Node _node; @@ -138,7 +138,7 @@ class DirectiveInjector implements DirectiveBinder { } } - static Binding _temp_binding = new Binding(); + static Binding _tempBinding = new Binding(); DirectiveInjector(parent, appInjector, this._node, this._nodeAttrs, this._eventHandler, this.scope, this._animate) @@ -152,21 +152,23 @@ class DirectiveInjector implements DirectiveBinder { scope = null, _animate = null; - bind(key, {dynamic toValue: DEFAULT_VALUE, + void bind(key, {dynamic toValue: DEFAULT_VALUE, Function toFactory: DEFAULT_VALUE, - Type toImplementation, inject: const[], + Type toImplementation, + toInstanceOf, + inject: const[], Visibility visibility: Visibility.LOCAL}) { if (key == null) throw 'Key is required'; if (key is! Key) key = new Key(key); if (inject is! List) inject = [inject]; - _temp_binding.bind(key, Module.DEFAULT_REFLECTOR, toValue: toValue, toFactory: toFactory, - toImplementation: toImplementation, inject: inject); + _tempBinding.bind(key, Module.DEFAULT_REFLECTOR, toValue: toValue, toFactory: toFactory, + toImplementation: toImplementation, inject: inject, toInstanceOf: toInstanceOf); - bindByKey(key, _temp_binding.factory, _temp_binding.parameterKeys, visibility); + bindByKey(key, _tempBinding.factory, _tempBinding.parameterKeys, visibility); } - bindByKey(Key key, Function factory, List parameterKeys, [Visibility visibility]) { + void bindByKey(Key key, Function factory, List parameterKeys, [Visibility visibility]) { if (visibility == null) visibility = Visibility.CHILDREN; int visibilityId = _toVisId(visibility); int keyVisId = key.uid; @@ -211,7 +213,7 @@ class DirectiveInjector implements DirectiveBinder { return isDirective ? _getDirectiveByKey(key, uid, appInjector) : _getById(uid); } - _getDirectiveByKey(Key k, int visType, Injector i) { + Object _getDirectiveByKey(Key k, int visType, Injector i) { do { if (_key0 == null) break; if (identical(_key0, k)) return _obj0 == null ? _obj0 = _new(_pKeys0, _factory0) : _obj0; if (_key1 == null) break; if (identical(_key1, k)) return _obj1 == null ? _obj1 = _new(_pKeys1, _factory1) : _obj1; @@ -340,7 +342,7 @@ class TemplateDirectiveInjector extends DirectiveInjector { final ViewFactory _viewFactory; ViewPort _viewPort; BoundViewFactory _boundViewFactory; - + TemplateDirectiveInjector(DirectiveInjector parent, Injector appInjector, Node node, NodeAttrs nodeAttrs, EventHandler eventHandler, Scope scope, Animate animate, this._viewFactory) @@ -357,7 +359,7 @@ class TemplateDirectiveInjector extends DirectiveInjector { default: return super._getById(keyId); } } - + } abstract class ComponentDirectiveInjector extends DirectiveInjector { diff --git a/lib/core_dom/element_binder.dart b/lib/core_dom/element_binder.dart index 55e4cd8cd..75ed412e8 100644 --- a/lib/core_dom/element_binder.dart +++ b/lib/core_dom/element_binder.dart @@ -23,20 +23,6 @@ class TemplateElementBinder extends ElementBinder { String toString() => "[TemplateElementBinder template:$template]"; } -// TODO: This class exists for forwards API compatibility only. -// Remove it after migration to DI 2.0. -class _DirectiveBinderImpl implements DirectiveBinder { - final module = new Module(); - - _DirectiveBinderImpl(); - - bind(key, {Function toFactory: DEFAULT_VALUE, List inject: null, - Visibility visibility: Directive.LOCAL_VISIBILITY}) { - module.bind(key, toFactory: toFactory, inject: inject, - visibility: visibility); - } -} - /** * ElementBinder is created by the Selector and is responsible for instantiating * individual directives and binding element properties. diff --git a/lib/directive/ng_form.dart b/lib/directive/ng_form.dart index ac1ce00ce..595d547a2 100644 --- a/lib/directive/ng_form.dart +++ b/lib/directive/ng_form.dart @@ -20,7 +20,7 @@ part of angular.directive; map: const { 'ng-form': '@name' }) class NgForm extends NgControl { static module(DirectiveBinder binder) => - binder.bind(NgControl, inject: NG_FORM_KEY, visibility: Visibility.CHILDREN); + binder.bind(NgControl, toInstanceOf: NG_FORM_KEY, visibility: Visibility.CHILDREN); final Scope _scope; diff --git a/lib/routing/ng_bind_route.dart b/lib/routing/ng_bind_route.dart index 52c786626..0956d7c98 100644 --- a/lib/routing/ng_bind_route.dart +++ b/lib/routing/ng_bind_route.dart @@ -31,8 +31,8 @@ class NgBindRoute implements RouteProvider { final Router _router; final DirectiveInjector _injector; - static void module(DirectiveBinder binder) - => binder.bind(RouteProvider, inject: NG_BIND_ROUTE_KEY, visibility: Visibility.CHILDREN); + static void module(DirectiveBinder binder) => + binder.bind(RouteProvider, toInstanceOf: NG_BIND_ROUTE_KEY, visibility: Visibility.CHILDREN); // We inject NgRoutingHelper to force initialization of routing. NgBindRoute(this._router, this._injector, NgRoutingHelper _); diff --git a/lib/routing/ng_view.dart b/lib/routing/ng_view.dart index cf1aaa2c9..3a60fc05f 100644 --- a/lib/routing/ng_view.dart +++ b/lib/routing/ng_view.dart @@ -56,8 +56,8 @@ part of angular.routing; module: NgView.module, visibility: Visibility.CHILDREN) class NgView implements DetachAware, RouteProvider { - static void module(DirectiveBinder binder) - => binder.bind(RouteProvider, inject: NG_VIEW_KEY, visibility: Visibility.CHILDREN); + static void module(DirectiveBinder binder) => + binder.bind(RouteProvider, toInstanceOf: NG_VIEW_KEY, visibility: Visibility.CHILDREN); final NgRoutingHelper _locationService; final ViewCache _viewCache; diff --git a/test/core_dom/compiler_spec.dart b/test/core_dom/compiler_spec.dart index 01d58302b..6be107436 100644 --- a/test/core_dom/compiler_spec.dart +++ b/test/core_dom/compiler_spec.dart @@ -1075,7 +1075,8 @@ class PublishModuleDirectiveSuperType { selector: '[publish-types]', module: PublishModuleAttrDirective.module) class PublishModuleAttrDirective implements PublishModuleDirectiveSuperType { - static module(i) => i.bind(PublishModuleDirectiveSuperType, inject: PublishModuleAttrDirective); + static module(i) => + i.bind(PublishModuleDirectiveSuperType, toInstanceOf: PublishModuleAttrDirective); static DirectiveInjector _injector; PublishModuleAttrDirective(DirectiveInjector injector) {