11import { describe , ddescribe , it , iit , xit , xdescribe , expect , beforeEach } from 'test_lib/test_lib' ;
2- import { isBlank , FIELD } from 'facade/lang' ;
2+ import { isBlank , FIELD , IMPLEMENTS } from 'facade/lang' ;
33import { ListWrapper , MapWrapper , List } from 'facade/collection' ;
4- import { ProtoElementInjector } from 'core/compiler/element_injector' ;
4+ import { ProtoElementInjector , VIEW_KEY } from 'core/compiler/element_injector' ;
55import { Parent , Ancestor } from 'core/annotations/visibility' ;
66import { Injector , Inject , bind } from 'di/di' ;
7+ import { View } from 'core/compiler/view' ;
8+
9+ @IMPLEMENTS ( View )
10+ class DummyView { }
711
812class Directive {
913}
@@ -36,6 +40,13 @@ class NeedsService {
3640 }
3741}
3842
43+ class NeedsView {
44+ @FIELD ( "view:Object" )
45+ constructor ( @Inject ( View ) view ) {
46+ this . view = view ;
47+ }
48+ }
49+
3950export function main ( ) {
4051 function humanize ( tree , names :List ) {
4152 var lookupName = ( item ) =>
@@ -47,6 +58,30 @@ export function main() {
4758 return [ lookupName ( tree ) , children ] ;
4859 }
4960
61+ function injector ( bindings , appInjector = null , props = null ) {
62+ if ( isBlank ( appInjector ) ) appInjector = new Injector ( [ ] ) ;
63+ if ( isBlank ( props ) ) props = { } ;
64+
65+ var proto = new ProtoElementInjector ( null , bindings , [ ] ) ;
66+ var inj = proto . instantiate ( { view : props [ "view" ] } ) ;
67+ inj . instantiateDirectives ( appInjector ) ;
68+ return inj ;
69+ }
70+
71+ function parentChildInjectors ( parentBindings , childBindings ) {
72+ var inj = new Injector ( [ ] ) ;
73+
74+ var protoParent = new ProtoElementInjector ( null , parentBindings , [ ] ) ;
75+ var parent = protoParent . instantiate ( { view : null } ) ;
76+ parent . instantiateDirectives ( inj ) ;
77+
78+ var protoChild = new ProtoElementInjector ( protoParent , childBindings , [ ] ) ;
79+ var child = protoChild . instantiate ( { view : null } ) ;
80+ child . instantiateDirectives ( inj ) ;
81+
82+ return child ;
83+ }
84+
5085 describe ( "ElementInjector" , function ( ) {
5186 describe ( "proto injectors" , function ( ) {
5287 it ( "should construct a proto tree" , function ( ) {
@@ -68,9 +103,9 @@ export function main() {
68103 var protoChild1 = new ProtoElementInjector ( protoParent , [ ] , [ ] ) ;
69104 var protoChild2 = new ProtoElementInjector ( protoParent , [ ] , [ ] ) ;
70105
71- var p = protoParent . instantiate ( ) ;
72- var c1 = protoChild1 . instantiate ( ) ;
73- var c2 = protoChild2 . instantiate ( ) ;
106+ var p = protoParent . instantiate ( { view : null } ) ;
107+ var c1 = protoChild1 . instantiate ( { view : null } ) ;
108+ var c2 = protoChild2 . instantiate ( { view : null } ) ;
74109
75110 expect ( humanize ( p , [
76111 [ p , 'parent' ] ,
@@ -93,29 +128,6 @@ export function main() {
93128 } ) ;
94129
95130 describe ( "instantiateDirectives" , function ( ) {
96- function injector ( bindings , appInjector = null ) {
97- var proto = new ProtoElementInjector ( null , bindings , [ ] ) ;
98- var inj = proto . instantiate ( ) ;
99-
100- if ( isBlank ( appInjector ) ) appInjector = new Injector ( [ ] ) ;
101- inj . instantiateDirectives ( appInjector ) ;
102- return inj ;
103- }
104-
105- function parentChildInjectors ( parentBindings , childBindings ) {
106- var inj = new Injector ( [ ] ) ;
107-
108- var protoParent = new ProtoElementInjector ( null , parentBindings , [ ] ) ;
109- var parent = protoParent . instantiate ( ) ;
110- parent . instantiateDirectives ( inj ) ;
111-
112- var protoChild = new ProtoElementInjector ( protoParent , childBindings , [ ] ) ;
113- var child = protoChild . instantiate ( ) ;
114- child . instantiateDirectives ( inj ) ;
115-
116- return child ;
117- }
118-
119131 it ( "should instantiate directives that have no dependencies" , function ( ) {
120132 var inj = injector ( [ Directive ] ) ;
121133 expect ( inj . get ( Directive ) ) . toBeAnInstanceOf ( Directive ) ;
@@ -141,6 +153,13 @@ export function main() {
141153 expect ( d . service ) . toEqual ( "service" ) ;
142154 } ) ;
143155
156+ it ( "should instantiate directives that depend on speical objects" , function ( ) {
157+ var view = new DummyView ( ) ;
158+ var inj = injector ( [ NeedsView ] , null , { "view" : view } ) ;
159+
160+ expect ( inj . get ( NeedsView ) . view ) . toBe ( view ) ;
161+ } ) ;
162+
144163 it ( "should return app services" , function ( ) {
145164 var appInjector = new Injector ( [
146165 bind ( "service" ) . toValue ( "service" )
@@ -173,5 +192,14 @@ export function main() {
173192 toThrowError ( 'No provider for Directive! (NeedDirectiveFromParent -> Directive)' ) ;
174193 } ) ;
175194 } ) ;
195+
196+ describe ( "special objects" , function ( ) {
197+ it ( "should return view" , function ( ) {
198+ var view = new DummyView ( ) ;
199+ var inj = injector ( [ ] , null , { "view" : view } ) ;
200+
201+ expect ( inj . get ( View ) ) . toEqual ( view ) ;
202+ } ) ;
203+ } ) ;
176204 } ) ;
177205}
0 commit comments