Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

fix: Remove deprecated calls to DI bind(Type, inject[]) #1260

Merged
merged 2 commits into from
Jul 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/core/annotation_src.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions lib/core/module_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 13 additions & 11 deletions lib/core_dom/directive_injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class DirectiveInjector implements DirectiveBinder {
, EVENT_HANDLER_KEY
, KEEP_ME_LAST
];

final DirectiveInjector parent;
final Injector appInjector;
final Node _node;
Expand Down Expand Up @@ -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)
Expand All @@ -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<Key> parameterKeys, [Visibility visibility]) {
void bindByKey(Key key, Function factory, List<Key> parameterKeys, [Visibility visibility]) {
if (visibility == null) visibility = Visibility.CHILDREN;
int visibilityId = _toVisId(visibility);
int keyVisId = key.uid;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -357,7 +359,7 @@ class TemplateDirectiveInjector extends DirectiveInjector {
default: return super._getById(keyId);
}
}

}

abstract class ComponentDirectiveInjector extends DirectiveInjector {
Expand Down
14 changes: 0 additions & 14 deletions lib/core_dom/element_binder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions lib/core_dom/module_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/directive/ng_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/mock/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions lib/routing/ng_bind_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 _);
Expand Down
4 changes: 2 additions & 2 deletions lib/routing/ng_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/tools/expression_extractor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(() {
Expand Down
32 changes: 20 additions & 12 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ packages:
analyzer:
description: analyzer
source: hosted
version: "0.15.7"
version: "0.18.0"
args:
description: args
source: hosted
version: "0.10.0+2"
barback:
description: barback
source: hosted
version: "0.13.0"
version: "0.14.1+3"
benchmark_harness:
description: benchmark_harness
source: hosted
Expand All @@ -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
Expand All @@ -44,7 +44,7 @@ packages:
intl:
description: intl
source: hosted
version: "0.9.10"
version: "0.8.10+4"
js:
description: js
source: hosted
Expand All @@ -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
Expand All @@ -80,20 +84,24 @@ 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
version: "0.9.0"
web_components:
description: web_components
source: hosted
version: "0.3.4"
version: "0.3.5+1"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion test/core/parser/generated_getter_setter_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion test/core_dom/compiler_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down