feat(ElementInjector): implement @PropertySetter

relates to #621
This commit is contained in:
Victor Berchet 2015-03-06 18:12:48 +01:00
parent c3873be295
commit b349c35678
21 changed files with 192 additions and 82 deletions

View File

@ -13,3 +13,16 @@ export class EventEmitter extends DependencyAnnotation {
this.eventName = eventName; this.eventName = eventName;
} }
} }
/**
* The directive can inject a property setter that would allow setting this property on the
* host element
*/
export class PropertySetter extends DependencyAnnotation {
propName: string;
@CONST()
constructor(propName) {
super();
this.propName = propName;
}
}

View File

@ -59,7 +59,7 @@ function _injectorBindings(appComponentType): List<Binding> {
}, [appComponentAnnotatedTypeToken, appDocumentToken]), }, [appComponentAnnotatedTypeToken, appDocumentToken]),
bind(appViewToken).toAsyncFactory((changeDetection, compiler, injector, appElement, bind(appViewToken).toAsyncFactory((changeDetection, compiler, injector, appElement,
appComponentAnnotatedType, strategy, eventManager) => { appComponentAnnotatedType, strategy, eventManager, reflector) => {
return compiler.compile(appComponentAnnotatedType.type).then( return compiler.compile(appComponentAnnotatedType.type).then(
(protoView) => { (protoView) => {
var appProtoView = ProtoView.createRootProtoView(protoView, appElement, var appProtoView = ProtoView.createRootProtoView(protoView, appElement,
@ -68,12 +68,12 @@ function _injectorBindings(appComponentType): List<Binding> {
// The light Dom of the app element is not considered part of // The light Dom of the app element is not considered part of
// the angular application. Thus the context and lightDomInjector are // the angular application. Thus the context and lightDomInjector are
// empty. // empty.
var view = appProtoView.instantiate(null, eventManager); var view = appProtoView.instantiate(null, eventManager, reflector);
view.hydrate(injector, null, new Object()); view.hydrate(injector, null, new Object());
return view; return view;
}); });
}, [ChangeDetection, Compiler, Injector, appElementToken, appComponentAnnotatedTypeToken, }, [ChangeDetection, Compiler, Injector, appElementToken, appComponentAnnotatedTypeToken,
ShadowDomStrategy, EventManager]), ShadowDomStrategy, EventManager, Reflector]),
bind(appChangeDetectorToken).toFactory((rootView) => rootView.changeDetector, bind(appChangeDetectorToken).toFactory((rootView) => rootView.changeDetector,
[appViewToken]), [appViewToken]),

View File

@ -3,13 +3,14 @@ import {Math} from 'angular2/src/facade/math';
import {List, ListWrapper, MapWrapper} from 'angular2/src/facade/collection'; import {List, ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
import {Injector, Key, Dependency, bind, Binding, NoProviderError, ProviderError, CyclicDependencyError} from 'angular2/di'; import {Injector, Key, Dependency, bind, Binding, NoProviderError, ProviderError, CyclicDependencyError} from 'angular2/di';
import {Parent, Ancestor} from 'angular2/src/core/annotations/visibility'; import {Parent, Ancestor} from 'angular2/src/core/annotations/visibility';
import {EventEmitter} from 'angular2/src/core/annotations/events'; import {EventEmitter, PropertySetter} from 'angular2/src/core/annotations/di';
import {View, ProtoView} from 'angular2/src/core/compiler/view'; import {View, ProtoView} from 'angular2/src/core/compiler/view';
import {LightDom, SourceLightDom, DestinationLightDom} from 'angular2/src/core/compiler/shadow_dom_emulation/light_dom'; import {LightDom, SourceLightDom, DestinationLightDom} from 'angular2/src/core/compiler/shadow_dom_emulation/light_dom';
import {ViewContainer} from 'angular2/src/core/compiler/view_container'; import {ViewContainer} from 'angular2/src/core/compiler/view_container';
import {NgElement} from 'angular2/src/core/dom/element'; import {NgElement} from 'angular2/src/core/dom/element';
import {Directive, onChange, onDestroy} from 'angular2/src/core/annotations/annotations' import {Directive, onChange, onDestroy} from 'angular2/src/core/annotations/annotations'
import {BindingPropagationConfig} from 'angular2/src/core/compiler/binding_propagation_config' import {BindingPropagationConfig} from 'angular2/src/core/compiler/binding_propagation_config'
import {Reflector} from 'angular2/src/reflection/reflection';
var _MAX_DIRECTIVE_CONSTRUCTION_COUNTER = 10; var _MAX_DIRECTIVE_CONSTRUCTION_COUNTER = 10;
@ -90,18 +91,22 @@ class TreeNode {
export class DirectiveDependency extends Dependency { export class DirectiveDependency extends Dependency {
depth:int; depth:int;
eventEmitterName:string; eventEmitterName:string;
propSetterName:string;
constructor(key:Key, asPromise:boolean, lazy:boolean, optional:boolean, constructor(key:Key, asPromise:boolean, lazy:boolean, optional:boolean,
properties:List, depth:int, eventEmitterName: string) { properties:List, depth:int, eventEmitterName: string, propSetterName: string) {
super(key, asPromise, lazy, optional, properties); super(key, asPromise, lazy, optional, properties);
this.depth = depth; this.depth = depth;
this.eventEmitterName = eventEmitterName; this.eventEmitterName = eventEmitterName;
this.propSetterName = propSetterName;
} }
static createFrom(d:Dependency):Dependency { static createFrom(d:Dependency):Dependency {
return new DirectiveDependency(d.key, d.asPromise, d.lazy, d.optional, return new DirectiveDependency(d.key, d.asPromise, d.lazy, d.optional,
d.properties, DirectiveDependency._depth(d.properties), d.properties, DirectiveDependency._depth(d.properties),
DirectiveDependency._eventEmitterName(d.properties)); DirectiveDependency._eventEmitterName(d.properties),
DirectiveDependency._propSetterName(d.properties)
);
} }
static _depth(properties):int { static _depth(properties):int {
@ -119,6 +124,15 @@ export class DirectiveDependency extends Dependency {
} }
return null; return null;
} }
static _propSetterName(properties):string {
for (var i = 0; i < properties.length; i++) {
if (properties[i] instanceof PropertySetter) {
return properties[i].propName;
}
}
return null;
}
} }
export class DirectiveBinding extends Binding { export class DirectiveBinding extends Binding {
@ -256,8 +270,9 @@ export class ProtoElementInjector {
} }
} }
instantiate(parent:ElementInjector, host:ElementInjector, eventCallbacks):ElementInjector { instantiate(parent:ElementInjector, host:ElementInjector, eventCallbacks,
return new ElementInjector(this, parent, host, eventCallbacks); reflector: Reflector):ElementInjector {
return new ElementInjector(this, parent, host, eventCallbacks, reflector);
} }
directParent(): ProtoElementInjector { directParent(): ProtoElementInjector {
@ -311,7 +326,10 @@ export class ElementInjector extends TreeNode {
_preBuiltObjects; _preBuiltObjects;
_constructionCounter; _constructionCounter;
_eventCallbacks; _eventCallbacks;
constructor(proto:ProtoElementInjector, parent:ElementInjector, host:ElementInjector, eventCallbacks: Map) { _refelector: Reflector;
constructor(proto:ProtoElementInjector, parent:ElementInjector, host:ElementInjector,
eventCallbacks: Map, reflector: Reflector) {
super(parent); super(parent);
if (isPresent(parent) && isPresent(host)) { if (isPresent(parent) && isPresent(host)) {
throw new BaseException('Only either parent or host is allowed'); throw new BaseException('Only either parent or host is allowed');
@ -324,6 +342,7 @@ export class ElementInjector extends TreeNode {
} }
this._proto = proto; this._proto = proto;
this._refelector = reflector;
//we cannot call clearDirectives because fields won't be detected //we cannot call clearDirectives because fields won't be detected
this._preBuiltObjects = null; this._preBuiltObjects = null;
@ -488,6 +507,7 @@ export class ElementInjector extends TreeNode {
_getByDependency(dep:DirectiveDependency, requestor:Key) { _getByDependency(dep:DirectiveDependency, requestor:Key) {
if (isPresent(dep.eventEmitterName)) return this._buildEventEmitter(dep); if (isPresent(dep.eventEmitterName)) return this._buildEventEmitter(dep);
if (isPresent(dep.propSetterName)) return this._buildPropSetter(dep);
return this._getByKey(dep.key, dep.depth, dep.optional, requestor); return this._getByKey(dep.key, dep.depth, dep.optional, requestor);
} }
@ -502,6 +522,13 @@ export class ElementInjector extends TreeNode {
return (_) => {}; return (_) => {};
} }
_buildPropSetter(dep) {
var ngElement = this._getPreBuiltObjectByKeyId(StaticKeys.instance().ngElementId);
var domElement = ngElement.domElement;
var setter = this._refelector.setter(dep.propSetterName);
return function(v) { setter(domElement, v) };
}
/* /*
* It is fairly easy to annotate keys with metadata. * It is fairly easy to annotate keys with metadata.
* For example, key.metadata = 'directive'. * For example, key.metadata = 'directive'.

View File

@ -18,6 +18,8 @@ import {ShadowDomStrategy} from './shadow_dom_strategy';
import {ViewPool} from './view_pool'; import {ViewPool} from './view_pool';
import {EventManager} from 'angular2/src/core/events/event_manager'; import {EventManager} from 'angular2/src/core/events/event_manager';
import {Reflector} from 'angular2/src/reflection/reflection';
const NG_BINDING_CLASS = 'ng-binding'; const NG_BINDING_CLASS = 'ng-binding';
const NG_BINDING_CLASS_SELECTOR = '.ng-binding'; const NG_BINDING_CLASS_SELECTOR = '.ng-binding';
@ -298,19 +300,23 @@ export class ProtoView {
} }
// TODO(rado): hostElementInjector should be moved to hydrate phase. // TODO(rado): hostElementInjector should be moved to hydrate phase.
instantiate(hostElementInjector: ElementInjector, eventManager: EventManager):View { instantiate(hostElementInjector: ElementInjector, eventManager: EventManager,
if (this._viewPool.length() == 0) this._preFillPool(hostElementInjector, eventManager); reflector: Reflector):View {
if (this._viewPool.length() == 0) this._preFillPool(hostElementInjector, eventManager,
reflector);
var view = this._viewPool.pop(); var view = this._viewPool.pop();
return isPresent(view) ? view : this._instantiate(hostElementInjector, eventManager); return isPresent(view) ? view : this._instantiate(hostElementInjector, eventManager, reflector);
} }
_preFillPool(hostElementInjector: ElementInjector, eventManager: EventManager) { _preFillPool(hostElementInjector: ElementInjector, eventManager: EventManager,
reflector: Reflector) {
for (var i = 0; i < VIEW_POOL_PREFILL; i++) { for (var i = 0; i < VIEW_POOL_PREFILL; i++) {
this._viewPool.push(this._instantiate(hostElementInjector, eventManager)); this._viewPool.push(this._instantiate(hostElementInjector, eventManager, reflector));
} }
} }
_instantiate(hostElementInjector: ElementInjector, eventManager: EventManager): View { _instantiate(hostElementInjector: ElementInjector, eventManager: EventManager,
reflector: Reflector): View {
var rootElementClone = this.instantiateInPlace ? this.element : DOM.importIntoDoc(this.element); var rootElementClone = this.instantiateInPlace ? this.element : DOM.importIntoDoc(this.element);
var elementsWithBindingsDynamic; var elementsWithBindingsDynamic;
if (this.isTemplateElement) { if (this.isTemplateElement) {
@ -362,9 +368,11 @@ export class ProtoView {
if (isPresent(protoElementInjector)) { if (isPresent(protoElementInjector)) {
if (isPresent(protoElementInjector.parent)) { if (isPresent(protoElementInjector.parent)) {
var parentElementInjector = elementInjectors[protoElementInjector.parent.index]; var parentElementInjector = elementInjectors[protoElementInjector.parent.index];
elementInjector = protoElementInjector.instantiate(parentElementInjector, null, binder.events); elementInjector = protoElementInjector.instantiate(parentElementInjector, null,
binder.events, reflector);
} else { } else {
elementInjector = protoElementInjector.instantiate(null, hostElementInjector, binder.events); elementInjector = protoElementInjector.instantiate(null, hostElementInjector,
binder.events, reflector);
ListWrapper.push(rootElementInjectors, elementInjector); ListWrapper.push(rootElementInjectors, elementInjector);
} }
} }
@ -391,7 +399,7 @@ export class ProtoView {
var bindingPropagationConfig = null; var bindingPropagationConfig = null;
if (isPresent(binder.componentDirective)) { if (isPresent(binder.componentDirective)) {
var strategy = this.shadowDomStrategy; var strategy = this.shadowDomStrategy;
var childView = binder.nestedProtoView.instantiate(elementInjector, eventManager); var childView = binder.nestedProtoView.instantiate(elementInjector, eventManager, reflector);
view.changeDetector.addChild(childView.changeDetector); view.changeDetector.addChild(childView.changeDetector);
lightDom = strategy.constructLightDom(view, childView, element); lightDom = strategy.constructLightDom(view, childView, element);
@ -407,7 +415,7 @@ export class ProtoView {
if (isPresent(binder.viewportDirective)) { if (isPresent(binder.viewportDirective)) {
var destLightDom = this._directParentElementLightDom(protoElementInjector, preBuiltObjects); var destLightDom = this._directParentElementLightDom(protoElementInjector, preBuiltObjects);
viewContainer = new ViewContainer(view, element, binder.nestedProtoView, elementInjector, viewContainer = new ViewContainer(view, element, binder.nestedProtoView, elementInjector,
eventManager, destLightDom); eventManager, reflector, destLightDom);
ListWrapper.push(viewContainers, viewContainer); ListWrapper.push(viewContainers, viewContainer);
} }

View File

@ -6,6 +6,7 @@ import {Injector} from 'angular2/di';
import * as eiModule from 'angular2/src/core/compiler/element_injector'; import * as eiModule from 'angular2/src/core/compiler/element_injector';
import {isPresent, isBlank} from 'angular2/src/facade/lang'; import {isPresent, isBlank} from 'angular2/src/facade/lang';
import {EventManager} from 'angular2/src/core/events/event_manager'; import {EventManager} from 'angular2/src/core/events/event_manager';
import {Reflector} from 'angular2/src/reflection/reflection';
export class ViewContainer { export class ViewContainer {
parentView: viewModule.View; parentView: viewModule.View;
@ -14,17 +15,24 @@ export class ViewContainer {
_views: List<viewModule.View>; _views: List<viewModule.View>;
_lightDom: any; _lightDom: any;
_eventManager: EventManager; _eventManager: EventManager;
_reflector: Reflector;
elementInjector: eiModule.ElementInjector; elementInjector: eiModule.ElementInjector;
appInjector: Injector; appInjector: Injector;
hostElementInjector: eiModule.ElementInjector; hostElementInjector: eiModule.ElementInjector;
constructor(parentView: viewModule.View, templateElement, defaultProtoView: viewModule.ProtoView, constructor(parentView: viewModule.View,
elementInjector: eiModule.ElementInjector, eventManager: EventManager, lightDom = null) { templateElement,
defaultProtoView: viewModule.ProtoView,
elementInjector: eiModule.ElementInjector,
eventManager: EventManager,
reflector: Reflector,
lightDom = null) {
this.parentView = parentView; this.parentView = parentView;
this.templateElement = templateElement; this.templateElement = templateElement;
this.defaultProtoView = defaultProtoView; this.defaultProtoView = defaultProtoView;
this.elementInjector = elementInjector; this.elementInjector = elementInjector;
this._lightDom = lightDom; this._lightDom = lightDom;
this._reflector = reflector;
// The order in this list matches the DOM order. // The order in this list matches the DOM order.
this._views = []; this._views = [];
@ -73,7 +81,8 @@ export class ViewContainer {
if (!this.hydrated()) throw new BaseException( if (!this.hydrated()) throw new BaseException(
'Cannot create views on a dehydrated ViewContainer'); 'Cannot create views on a dehydrated ViewContainer');
// TODO(rado): replace with viewFactory. // TODO(rado): replace with viewFactory.
var newView = this.defaultProtoView.instantiate(this.hostElementInjector, this._eventManager); var newView = this.defaultProtoView.instantiate(this.hostElementInjector, this._eventManager,
this._reflector);
// insertion must come before hydration so that element injector trees are attached. // insertion must come before hydration so that element injector trees are attached.
this.insert(newView, atIndex); this.insert(newView, atIndex);
newView.hydrate(this.appInjector, this.hostElementInjector, this.parentView.context); newView.hydrate(this.appInjector, this.hostElementInjector, this.parentView.context);

View File

@ -1,9 +1,9 @@
import {describe, ddescribe, it, iit, xit, xdescribe, expect, beforeEach, SpyObject, proxy} from 'angular2/test_lib'; import {describe, ddescribe, it, iit, xit, xdescribe, expect, beforeEach, SpyObject, proxy, el} from 'angular2/test_lib';
import {isBlank, isPresent, FIELD, IMPLEMENTS} from 'angular2/src/facade/lang'; import {isBlank, isPresent, FIELD, IMPLEMENTS} from 'angular2/src/facade/lang';
import {ListWrapper, MapWrapper, List} from 'angular2/src/facade/collection'; import {ListWrapper, MapWrapper, List} from 'angular2/src/facade/collection';
import {ProtoElementInjector, PreBuiltObjects, DirectiveBinding} from 'angular2/src/core/compiler/element_injector'; import {ProtoElementInjector, PreBuiltObjects, DirectiveBinding} from 'angular2/src/core/compiler/element_injector';
import {Parent, Ancestor} from 'angular2/src/core/annotations/visibility'; import {Parent, Ancestor} from 'angular2/src/core/annotations/visibility';
import {EventEmitter} from 'angular2/src/core/annotations/events'; import {EventEmitter, PropertySetter} from 'angular2/src/core/annotations/di';
import {onDestroy} from 'angular2/src/core/annotations/annotations'; import {onDestroy} from 'angular2/src/core/annotations/annotations';
import {Optional, Injector, Inject, bind} from 'angular2/di'; import {Optional, Injector, Inject, bind} from 'angular2/di';
import {View} from 'angular2/src/core/compiler/view'; import {View} from 'angular2/src/core/compiler/view';
@ -12,6 +12,7 @@ import {NgElement} from 'angular2/src/core/dom/element';
import {LightDom, SourceLightDom, DestinationLightDom} from 'angular2/src/core/compiler/shadow_dom_emulation/light_dom'; import {LightDom, SourceLightDom, DestinationLightDom} from 'angular2/src/core/compiler/shadow_dom_emulation/light_dom';
import {Directive} from 'angular2/src/core/annotations/annotations'; import {Directive} from 'angular2/src/core/annotations/annotations';
import {BindingPropagationConfig} from 'angular2/src/core/compiler/binding_propagation_config'; import {BindingPropagationConfig} from 'angular2/src/core/compiler/binding_propagation_config';
import {reflector} from 'angular2/src/reflection/reflection';
@proxy @proxy
@IMPLEMENTS(View) @IMPLEMENTS(View)
@ -74,6 +75,17 @@ class NeedsEventEmitter {
} }
} }
class NeedsPropertySetter {
propSetter;
constructor(@PropertySetter('title') propSetter: Function) {
this.propSetter = propSetter;
}
setProp(value) {
this.propSetter(value);
}
}
class A_Needs_B { class A_Needs_B {
constructor(dep){} constructor(dep){}
} }
@ -118,7 +130,7 @@ export function main() {
if (isBlank(lightDomAppInjector)) lightDomAppInjector = new Injector([]); if (isBlank(lightDomAppInjector)) lightDomAppInjector = new Injector([]);
var proto = new ProtoElementInjector(null, 0, bindings, isPresent(shadowDomAppInjector)); var proto = new ProtoElementInjector(null, 0, bindings, isPresent(shadowDomAppInjector));
var inj = proto.instantiate(null, null, null); var inj = proto.instantiate(null, null, null, reflector);
var preBuilt = isPresent(preBuiltObjects) ? preBuiltObjects : defaultPreBuiltObjects; var preBuilt = isPresent(preBuiltObjects) ? preBuiltObjects : defaultPreBuiltObjects;
inj.instantiateDirectives(lightDomAppInjector, shadowDomAppInjector, preBuilt); inj.instantiateDirectives(lightDomAppInjector, shadowDomAppInjector, preBuilt);
@ -131,12 +143,12 @@ export function main() {
var inj = new Injector([]); var inj = new Injector([]);
var protoParent = new ProtoElementInjector(null, 0, parentBindings); var protoParent = new ProtoElementInjector(null, 0, parentBindings);
var parent = protoParent.instantiate(null, null, null); var parent = protoParent.instantiate(null, null, null, reflector);
parent.instantiateDirectives(inj, null, parentPreBuildObjects); parent.instantiateDirectives(inj, null, parentPreBuildObjects);
var protoChild = new ProtoElementInjector(protoParent, 1, childBindings, false, 1); var protoChild = new ProtoElementInjector(protoParent, 1, childBindings, false, 1);
var child = protoChild.instantiate(parent, null, null); var child = protoChild.instantiate(parent, null, null, reflector);
child.instantiateDirectives(inj, null, defaultPreBuiltObjects); child.instantiateDirectives(inj, null, defaultPreBuiltObjects);
return child; return child;
@ -149,11 +161,11 @@ export function main() {
var shadowInj = inj.createChild([]); var shadowInj = inj.createChild([]);
var protoParent = new ProtoElementInjector(null, 0, hostBindings, true); var protoParent = new ProtoElementInjector(null, 0, hostBindings, true);
var host = protoParent.instantiate(null, null, null); var host = protoParent.instantiate(null, null, null, reflector);
host.instantiateDirectives(inj, shadowInj, hostPreBuildObjects); host.instantiateDirectives(inj, shadowInj, hostPreBuildObjects);
var protoChild = new ProtoElementInjector(protoParent, 0, shadowBindings, false, 1); var protoChild = new ProtoElementInjector(protoParent, 0, shadowBindings, false, 1);
var shadow = protoChild.instantiate(null, host, null); var shadow = protoChild.instantiate(null, host, null, reflector);
shadow.instantiateDirectives(shadowInj, null, null); shadow.instantiateDirectives(shadowInj, null, null);
return shadow; return shadow;
@ -186,9 +198,9 @@ export function main() {
var protoChild1 = new ProtoElementInjector(protoParent, 1, []); var protoChild1 = new ProtoElementInjector(protoParent, 1, []);
var protoChild2 = new ProtoElementInjector(protoParent, 2, []); var protoChild2 = new ProtoElementInjector(protoParent, 2, []);
var p = protoParent.instantiate(null, null, null); var p = protoParent.instantiate(null, null, null, reflector);
var c1 = protoChild1.instantiate(p, null, null); var c1 = protoChild1.instantiate(p, null, null, reflector);
var c2 = protoChild2.instantiate(p, null, null); var c2 = protoChild2.instantiate(p, null, null, reflector);
expect(humanize(p, [ expect(humanize(p, [
[p, 'parent'], [p, 'parent'],
@ -203,8 +215,8 @@ export function main() {
var protoParent = new ProtoElementInjector(null, 0, []); var protoParent = new ProtoElementInjector(null, 0, []);
var protoChild = new ProtoElementInjector(protoParent, 1, [], false, distance); var protoChild = new ProtoElementInjector(protoParent, 1, [], false, distance);
var p = protoParent.instantiate(null, null, null); var p = protoParent.instantiate(null, null, null, reflector);
var c = protoChild.instantiate(p, null, null); var c = protoChild.instantiate(p, null, null, reflector);
expect(c.directParent()).toEqual(p); expect(c.directParent()).toEqual(p);
}); });
@ -214,8 +226,8 @@ export function main() {
var protoParent = new ProtoElementInjector(null, 0, []); var protoParent = new ProtoElementInjector(null, 0, []);
var protoChild = new ProtoElementInjector(protoParent, 1, [], false, distance); var protoChild = new ProtoElementInjector(protoParent, 1, [], false, distance);
var p = protoParent.instantiate(null, null, null); var p = protoParent.instantiate(null, null, null, reflector);
var c = protoChild.instantiate(p, null, null); var c = protoChild.instantiate(p, null, null, reflector);
expect(c.directParent()).toEqual(null); expect(c.directParent()).toEqual(null);
}); });
@ -422,7 +434,7 @@ export function main() {
}); });
it('should return viewContainer', function () { it('should return viewContainer', function () {
var viewContainer = new ViewContainer(null, null, null, null, null); var viewContainer = new ViewContainer(null, null, null, null, null, null);
var inj = injector([], null, null, new PreBuiltObjects(null, null, viewContainer, null, null)); var inj = injector([], null, null, new PreBuiltObjects(null, null, viewContainer, null, null));
expect(inj.get(ViewContainer)).toEqual(viewContainer); expect(inj.get(ViewContainer)).toEqual(viewContainer);
@ -475,5 +487,19 @@ export function main() {
expect(inj.hasEventEmitter('move')).toBe(false); expect(inj.hasEventEmitter('move')).toBe(false);
}); });
}); });
describe('property setter', () => {
it('should be injectable and callable', () => {
var div = el('<div></div>');
var ngElement = new NgElement(div);
var preBuildObject = new PreBuiltObjects(null, ngElement, null, null, null);
var inj = injector([NeedsPropertySetter], null, null, preBuildObject);
inj.get(NeedsPropertySetter).setProp('foobar');
expect(div.title).toEqual('foobar');
});
});
}); });
} }

View File

@ -27,6 +27,8 @@ import {If} from 'angular2/src/directives/if';
import {ViewContainer} from 'angular2/src/core/compiler/view_container'; import {ViewContainer} from 'angular2/src/core/compiler/view_container';
import {reflector} from 'angular2/src/reflection/reflection';
export function main() { export function main() {
describe('integration tests', function() { describe('integration tests', function() {
var compiler, tplResolver; var compiler, tplResolver;
@ -55,7 +57,7 @@ export function main() {
var view, ctx, cd; var view, ctx, cd;
function createView(pv) { function createView(pv) {
ctx = new MyComp(); ctx = new MyComp();
view = pv.instantiate(null, null); view = pv.instantiate(null, null, reflector);
view.hydrate(new Injector([]), null, ctx); view.hydrate(new Injector([]), null, ctx);
cd = view.changeDetector; cd = view.changeDetector;
} }

View File

@ -82,7 +82,7 @@ export function main() {
function instantiateView(protoView) { function instantiateView(protoView) {
evalContext = new Context(); evalContext = new Context();
view = protoView.instantiate(null, null); view = protoView.instantiate(null, null, null);
view.hydrate(new Injector([]), null, evalContext); view.hydrate(new Injector([]), null, evalContext);
changeDetector = view.changeDetector; changeDetector = view.changeDetector;
} }

View File

@ -32,6 +32,8 @@ import {ViewContainer} from 'angular2/src/core/compiler/view_container';
import {BrowserDomAdapter} from 'angular2/src/dom/browser_adapter'; import {BrowserDomAdapter} from 'angular2/src/dom/browser_adapter';
import {reflector} from 'angular2/src/reflection/reflection';
export function main() { export function main() {
BrowserDomAdapter.makeCurrent(); BrowserDomAdapter.makeCurrent();
describe('integration tests', function() { describe('integration tests', function() {
@ -352,7 +354,7 @@ class MyComp {
} }
function createView(pv) { function createView(pv) {
var view = pv.instantiate(null, null); var view = pv.instantiate(null, null, reflector);
view.hydrate(new Injector([]), null, {}); view.hydrate(new Injector([]), null, {});
return view; return view;
} }

View File

@ -37,7 +37,7 @@ export function main() {
var host = el('<div></div>'); var host = el('<div></div>');
var nodes = el('<div>view</div>'); var nodes = el('<div>view</div>');
var pv = new ProtoView(nodes, new DynamicProtoChangeDetector(null), null); var pv = new ProtoView(nodes, new DynamicProtoChangeDetector(null), null);
var view = pv.instantiate(null, null); var view = pv.instantiate(null, null, null);
strategy.attachTemplate(host, view); strategy.attachTemplate(host, view);
var shadowRoot = DOM.getShadowRoot(host); var shadowRoot = DOM.getShadowRoot(host);
@ -83,7 +83,7 @@ export function main() {
var host = el('<div><span>original content</span></div>'); var host = el('<div><span>original content</span></div>');
var nodes = el('<div>view</div>'); var nodes = el('<div>view</div>');
var pv = new ProtoView(nodes, new DynamicProtoChangeDetector(null), null); var pv = new ProtoView(nodes, new DynamicProtoChangeDetector(null), null);
var view = pv.instantiate(null, null); var view = pv.instantiate(null, null, null);
strategy.attachTemplate(host, view); strategy.attachTemplate(host, view);
var firstChild = DOM.firstChild(host); var firstChild = DOM.firstChild(host);
@ -218,7 +218,7 @@ export function main() {
var host = el('<div><span>original content</span></div>'); var host = el('<div><span>original content</span></div>');
var nodes = el('<div>view</div>'); var nodes = el('<div>view</div>');
var pv = new ProtoView(nodes, new DynamicProtoChangeDetector(null), null); var pv = new ProtoView(nodes, new DynamicProtoChangeDetector(null), null);
var view = pv.instantiate(null, null); var view = pv.instantiate(null, null, null);
strategy.attachTemplate(host, view); strategy.attachTemplate(host, view);
var firstChild = DOM.firstChild(host); var firstChild = DOM.firstChild(host);

View File

@ -8,6 +8,7 @@ import {Injector} from 'angular2/di';
import {ProtoElementInjector, ElementInjector} from 'angular2/src/core/compiler/element_injector'; import {ProtoElementInjector, ElementInjector} from 'angular2/src/core/compiler/element_injector';
import {NativeShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy'; import {NativeShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy';
import {DynamicProtoChangeDetector, ChangeDetector, Lexer, Parser} from 'angular2/change_detection'; import {DynamicProtoChangeDetector, ChangeDetector, Lexer, Parser} from 'angular2/change_detection';
import {reflector} from 'angular2/src/reflection/reflection';
function createView(nodes) { function createView(nodes) {
var view = new View(null, nodes, new DynamicProtoChangeDetector(null), MapWrapper.create()); var view = new View(null, nodes, new DynamicProtoChangeDetector(null), MapWrapper.create());
@ -71,8 +72,9 @@ export function main() {
parentView = createView([dom.childNodes[0]]); parentView = createView([dom.childNodes[0]]);
protoView = new ProtoView(el('<div>hi</div>'), new DynamicProtoChangeDetector(null), protoView = new ProtoView(el('<div>hi</div>'), new DynamicProtoChangeDetector(null),
new NativeShadowDomStrategy(null)); new NativeShadowDomStrategy(null));
elementInjector = new ElementInjector(null, null, null, null); elementInjector = new ElementInjector(null, null, null, null, reflector);
viewContainer = new ViewContainer(parentView, insertionElement, protoView, elementInjector, null); viewContainer = new ViewContainer(parentView, insertionElement, protoView, elementInjector,
null, reflector);
customViewWithOneNode = createView([el('<div>single</div>')]); customViewWithOneNode = createView([el('<div>single</div>')]);
customViewWithTwoNodes = createView([el('<div>one</div>'), el('<div>two</div>')]); customViewWithTwoNodes = createView([el('<div>one</div>'), el('<div>two</div>')]);
}); });
@ -217,7 +219,7 @@ export function main() {
new DynamicProtoChangeDetector(null), new NativeShadowDomStrategy(null)); new DynamicProtoChangeDetector(null), new NativeShadowDomStrategy(null));
pv.bindElement(new ProtoElementInjector(null, 1, [SomeDirective])); pv.bindElement(new ProtoElementInjector(null, 1, [SomeDirective]));
pv.bindTextNode(0, parser.parseBinding('foo', null)); pv.bindTextNode(0, parser.parseBinding('foo', null));
fancyView = pv.instantiate(null, null); fancyView = pv.instantiate(null, null, reflector);
}); });
it('hydrating should update rootElementInjectors and parent change detector', () => { it('hydrating should update rootElementInjectors and parent change detector', () => {

View File

@ -6,16 +6,16 @@ import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_meta
import {Component, Decorator, Viewport, Directive, onChange} from 'angular2/src/core/annotations/annotations'; import {Component, Decorator, Viewport, Directive, onChange} from 'angular2/src/core/annotations/annotations';
import {Lexer, Parser, DynamicProtoChangeDetector, import {Lexer, Parser, DynamicProtoChangeDetector,
ChangeDetector} from 'angular2/change_detection'; ChangeDetector} from 'angular2/change_detection';
import {EventEmitter} from 'angular2/src/core/annotations/events'; import {EventEmitter} from 'angular2/src/core/annotations/di';
import {List, MapWrapper} from 'angular2/src/facade/collection'; import {List, MapWrapper} from 'angular2/src/facade/collection';
import {DOM} from 'angular2/src/dom/dom_adapter'; import {DOM} from 'angular2/src/dom/dom_adapter';
import {int, IMPLEMENTS} from 'angular2/src/facade/lang'; import {int, IMPLEMENTS} from 'angular2/src/facade/lang';
import {Injector} from 'angular2/di'; import {Injector} from 'angular2/di';
import {View} from 'angular2/src/core/compiler/view'; import {View} from 'angular2/src/core/compiler/view';
import {ViewContainer} from 'angular2/src/core/compiler/view_container'; import {ViewContainer} from 'angular2/src/core/compiler/view_container';
import {reflector} from 'angular2/src/reflection/reflection';
import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone'; import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone';
import {EventManager, DomEventsPlugin} from 'angular2/src/core/events/event_manager'; import {EventManager, DomEventsPlugin} from 'angular2/src/core/events/event_manager';
import {Reflector, reflector} from 'angular2/src/reflection/reflection';
@proxy @proxy
@IMPLEMENTS(ViewContainer) @IMPLEMENTS(ViewContainer)
@ -45,7 +45,7 @@ export function main() {
function createView(protoView, eventManager: EventManager = null) { function createView(protoView, eventManager: EventManager = null) {
var ctx = new MyEvaluationContext(); var ctx = new MyEvaluationContext();
var view = protoView.instantiate(null, eventManager); var view = protoView.instantiate(null, eventManager, reflector);
view.hydrate(null, null, ctx); view.hydrate(null, null, ctx);
return view; return view;
} }
@ -60,7 +60,7 @@ export function main() {
var view; var view;
beforeEach(() => { beforeEach(() => {
var pv = new ProtoView(el('<div id="1"></div>'), new DynamicProtoChangeDetector(null), null); var pv = new ProtoView(el('<div id="1"></div>'), new DynamicProtoChangeDetector(null), null);
view = pv.instantiate(null, null); view = pv.instantiate(null, null, reflector);
}); });
it('should be dehydrated by default', () => { it('should be dehydrated by default', () => {
@ -90,7 +90,7 @@ export function main() {
var fakeView = new FakeView(); var fakeView = new FakeView();
pv.returnToPool(fakeView); pv.returnToPool(fakeView);
expect(pv.instantiate(null, null)).toBe(fakeView); expect(pv.instantiate(null, null, reflector)).toBe(fakeView);
}); });
}); });
@ -135,7 +135,7 @@ export function main() {
it('should collect the root node in the ProtoView element', () => { it('should collect the root node in the ProtoView element', () => {
var pv = new ProtoView(templateAwareCreateElement('<div id="1"></div>'), var pv = new ProtoView(templateAwareCreateElement('<div id="1"></div>'),
new DynamicProtoChangeDetector(null), null); new DynamicProtoChangeDetector(null), null);
var view = pv.instantiate(null, null); var view = pv.instantiate(null, null, reflector);
view.hydrate(null, null, null); view.hydrate(null, null, null);
expect(view.nodes.length).toBe(1); expect(view.nodes.length).toBe(1);
expect(view.nodes[0].getAttribute('id')).toEqual('1'); expect(view.nodes[0].getAttribute('id')).toEqual('1');
@ -149,7 +149,7 @@ export function main() {
pv.bindElement(null); pv.bindElement(null);
pv.bindElementProperty(parser.parseBinding('a', null), 'prop', reflector.setter('prop')); pv.bindElementProperty(parser.parseBinding('a', null), 'prop', reflector.setter('prop'));
var view = pv.instantiate(null, null); var view = pv.instantiate(null, null, reflector);
view.hydrate(null, null, null); view.hydrate(null, null, null);
expect(view.bindElements.length).toEqual(1); expect(view.bindElements.length).toEqual(1);
expect(view.bindElements[0]).toBe(view.nodes[0]); expect(view.bindElements[0]).toBe(view.nodes[0]);
@ -161,7 +161,7 @@ export function main() {
pv.bindElement(null); pv.bindElement(null);
pv.bindElementProperty(parser.parseBinding('b', null), 'a', reflector.setter('a')); pv.bindElementProperty(parser.parseBinding('b', null), 'a', reflector.setter('a'));
var view = pv.instantiate(null, null); var view = pv.instantiate(null, null, reflector);
view.hydrate(null, null, null); view.hydrate(null, null, null);
expect(view.bindElements.length).toEqual(1); expect(view.bindElements.length).toEqual(1);
expect(view.bindElements[0]).toBe(view.nodes[0].childNodes[1]); expect(view.bindElements[0]).toBe(view.nodes[0].childNodes[1]);
@ -178,7 +178,7 @@ export function main() {
pv.bindTextNode(0, parser.parseBinding('a', null)); pv.bindTextNode(0, parser.parseBinding('a', null));
pv.bindTextNode(2, parser.parseBinding('b', null)); pv.bindTextNode(2, parser.parseBinding('b', null));
var view = pv.instantiate(null, null); var view = pv.instantiate(null, null, reflector);
view.hydrate(null, null, null); view.hydrate(null, null, null);
expect(view.textNodes.length).toEqual(2); expect(view.textNodes.length).toEqual(2);
expect(view.textNodes[0]).toBe(view.nodes[0].childNodes[0]); expect(view.textNodes[0]).toBe(view.nodes[0].childNodes[0]);
@ -191,7 +191,7 @@ export function main() {
pv.bindElement(null); pv.bindElement(null);
pv.bindTextNode(0, parser.parseBinding('b', null)); pv.bindTextNode(0, parser.parseBinding('b', null));
var view = pv.instantiate(null, null); var view = pv.instantiate(null, null, reflector);
view.hydrate(null, null, null); view.hydrate(null, null, null);
expect(view.textNodes.length).toEqual(1); expect(view.textNodes.length).toEqual(1);
expect(view.textNodes[0]).toBe(view.nodes[0].childNodes[1].childNodes[0]); expect(view.textNodes[0]).toBe(view.nodes[0].childNodes[1].childNodes[0]);
@ -206,16 +206,16 @@ export function main() {
var pv = new ProtoView(template, new DynamicProtoChangeDetector(null), var pv = new ProtoView(template, new DynamicProtoChangeDetector(null),
new NativeShadowDomStrategy(null)); new NativeShadowDomStrategy(null));
pv.instantiateInPlace = true; pv.instantiateInPlace = true;
var view = pv.instantiate(null, null); var view = pv.instantiate(null, null, reflector);
view.hydrate(null, null, null); view.hydrate(null, null, null);
expect(view.nodes[0]).toBe(template); expect(view.nodes[0]).toBe(template);
}); });
it('should be off by default.', () => { it('should be off by default.', () => {
var template = el('<div></div>') var template = el('<div></div>')
var view = new ProtoView(template, new DynamicProtoChangeDetector(null), var pv = new ProtoView(template, new DynamicProtoChangeDetector(null),
new NativeShadowDomStrategy(null)) new NativeShadowDomStrategy(null))
.instantiate(null, null); var view = pv.instantiate(null, null, reflector);
view.hydrate(null, null, null); view.hydrate(null, null, null);
expect(view.nodes[0]).not.toBe(template); expect(view.nodes[0]).not.toBe(template);
}); });
@ -235,7 +235,7 @@ export function main() {
new DynamicProtoChangeDetector(null), null); new DynamicProtoChangeDetector(null), null);
pv.bindElement(new ProtoElementInjector(null, 1, [SomeDirective])); pv.bindElement(new ProtoElementInjector(null, 1, [SomeDirective]));
var view = pv.instantiate(null, null); var view = pv.instantiate(null, null, reflector);
view.hydrate(null, null, null); view.hydrate(null, null, null);
expect(view.elementInjectors.length).toBe(1); expect(view.elementInjectors.length).toBe(1);
expect(view.elementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true); expect(view.elementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true);
@ -248,7 +248,7 @@ export function main() {
pv.bindElement(protoParent); pv.bindElement(protoParent);
pv.bindElement(new ProtoElementInjector(protoParent, 1, [AnotherDirective])); pv.bindElement(new ProtoElementInjector(protoParent, 1, [AnotherDirective]));
var view = pv.instantiate(null, null); var view = pv.instantiate(null, null, reflector);
view.hydrate(null, null, null); view.hydrate(null, null, null);
expect(view.elementInjectors.length).toBe(2); expect(view.elementInjectors.length).toBe(2);
expect(view.elementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true); expect(view.elementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true);
@ -264,9 +264,9 @@ export function main() {
pv.bindElement(testProtoElementInjector); pv.bindElement(testProtoElementInjector);
var hostProtoInjector = new ProtoElementInjector(null, 0, []); var hostProtoInjector = new ProtoElementInjector(null, 0, []);
var hostInjector = hostProtoInjector.instantiate(null, null, null); var hostInjector = hostProtoInjector.instantiate(null, null, null, reflector);
var view; var view;
expect(() => view = pv.instantiate(hostInjector, null)).not.toThrow(); expect(() => view = pv.instantiate(hostInjector, null, reflector)).not.toThrow();
expect(testProtoElementInjector.parentElementInjector).toBe(view.elementInjectors[0]); expect(testProtoElementInjector.parentElementInjector).toBe(view.elementInjectors[0]);
expect(testProtoElementInjector.hostElementInjector).toBeNull(); expect(testProtoElementInjector.hostElementInjector).toBeNull();
}); });
@ -279,8 +279,8 @@ export function main() {
pv.bindElement(testProtoElementInjector); pv.bindElement(testProtoElementInjector);
var hostProtoInjector = new ProtoElementInjector(null, 0, []); var hostProtoInjector = new ProtoElementInjector(null, 0, []);
var hostInjector = hostProtoInjector.instantiate(null, null, null); var hostInjector = hostProtoInjector.instantiate(null, null, null, reflector);
expect(() => pv.instantiate(hostInjector, null)).not.toThrow(); expect(() => pv.instantiate(hostInjector, null, reflector)).not.toThrow();
expect(testProtoElementInjector.parentElementInjector).toBeNull(); expect(testProtoElementInjector.parentElementInjector).toBeNull();
expect(testProtoElementInjector.hostElementInjector).toBe(hostInjector); expect(testProtoElementInjector.hostElementInjector).toBe(hostInjector);
}); });
@ -295,7 +295,7 @@ export function main() {
pv.bindElement(protoParent); pv.bindElement(protoParent);
pv.bindElement(new ProtoElementInjector(protoParent, 1, [AnotherDirective])); pv.bindElement(new ProtoElementInjector(protoParent, 1, [AnotherDirective]));
var view = pv.instantiate(null, null); var view = pv.instantiate(null, null, reflector);
view.hydrate(null, null, null); view.hydrate(null, null, null);
expect(view.rootElementInjectors.length).toBe(1); expect(view.rootElementInjectors.length).toBe(1);
expect(view.rootElementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true); expect(view.rootElementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true);
@ -307,7 +307,7 @@ export function main() {
pv.bindElement(new ProtoElementInjector(null, 1, [SomeDirective])); pv.bindElement(new ProtoElementInjector(null, 1, [SomeDirective]));
pv.bindElement(new ProtoElementInjector(null, 2, [AnotherDirective])); pv.bindElement(new ProtoElementInjector(null, 2, [AnotherDirective]));
var view = pv.instantiate(null, null); var view = pv.instantiate(null, null, reflector);
view.hydrate(null, null, null); view.hydrate(null, null, null);
expect(view.rootElementInjectors.length).toBe(2) expect(view.rootElementInjectors.length).toBe(2)
expect(view.rootElementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true); expect(view.rootElementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true);
@ -330,7 +330,7 @@ export function main() {
function createNestedView(protoView) { function createNestedView(protoView) {
ctx = new MyEvaluationContext(); ctx = new MyEvaluationContext();
var view = protoView.instantiate(null, null); var view = protoView.instantiate(null, null, reflector);
view.hydrate(new Injector([]), null, ctx); view.hydrate(new Injector([]), null, ctx);
return view; return view;
} }
@ -622,7 +622,7 @@ export function main() {
var rootProtoView = ProtoView.createRootProtoView(pv, element, var rootProtoView = ProtoView.createRootProtoView(pv, element,
someComponentDirective, new DynamicProtoChangeDetector(null), someComponentDirective, new DynamicProtoChangeDetector(null),
new NativeShadowDomStrategy(null)); new NativeShadowDomStrategy(null));
var view = rootProtoView.instantiate(null, null); var view = rootProtoView.instantiate(null, null, reflector);
view.hydrate(new Injector([]), null, null); view.hydrate(new Injector([]), null, null);
expect(view.rootElementInjectors[0].get(SomeComponent)).not.toBe(null); expect(view.rootElementInjectors[0].get(SomeComponent)).not.toBe(null);
}); });
@ -631,7 +631,7 @@ export function main() {
var rootProtoView = ProtoView.createRootProtoView(pv, element, var rootProtoView = ProtoView.createRootProtoView(pv, element,
someComponentDirective, new DynamicProtoChangeDetector(null), someComponentDirective, new DynamicProtoChangeDetector(null),
new NativeShadowDomStrategy(null)); new NativeShadowDomStrategy(null));
var view = rootProtoView.instantiate(null, null); var view = rootProtoView.instantiate(null, null, reflector);
view.hydrate(new Injector([]), null, null); view.hydrate(new Injector([]), null, null);
expect(element.shadowRoot.childNodes[0].childNodes[0].nodeValue).toEqual('hi'); expect(element.shadowRoot.childNodes[0].childNodes[0].nodeValue).toEqual('hi');
}); });
@ -727,10 +727,11 @@ class TestProtoElementInjector extends ProtoElementInjector {
super(parent, index, bindings, firstBindingIsComponent); super(parent, index, bindings, firstBindingIsComponent);
} }
instantiate(parent:ElementInjector, host:ElementInjector, events):ElementInjector { instantiate(parent:ElementInjector, host:ElementInjector, events,
reflector: Reflector):ElementInjector {
this.parentElementInjector = parent; this.parentElementInjector = parent;
this.hostElementInjector = host; this.hostElementInjector = host;
return super.instantiate(parent, host, events); return super.instantiate(parent, host, events, reflector);
} }
} }

View File

@ -44,7 +44,7 @@ export function main() {
function createView(pv) { function createView(pv) {
component = new TestComponent(); component = new TestComponent();
view = pv.instantiate(null, null); view = pv.instantiate(null, null, null);
view.hydrate(new Injector([]), null, component); view.hydrate(new Injector([]), null, component);
cd = view.changeDetector; cd = view.changeDetector;
} }

View File

@ -44,7 +44,7 @@ export function main() {
function createView(pv) { function createView(pv) {
component = new TestComponent(); component = new TestComponent();
view = pv.instantiate(null, null); view = pv.instantiate(null, null, null);
view.hydrate(new Injector([]), null, component); view.hydrate(new Injector([]), null, component);
cd = view.changeDetector; cd = view.changeDetector;
} }

View File

@ -42,7 +42,7 @@ export function main() {
function createView(pv) { function createView(pv) {
component = new TestComponent(); component = new TestComponent();
view = pv.instantiate(null, null); view = pv.instantiate(null, null, null);
view.hydrate(new Injector([]), null, component); view.hydrate(new Injector([]), null, component);
cd = view.changeDetector; cd = view.changeDetector;
} }

View File

@ -39,7 +39,7 @@ export function main() {
function createView(pv) { function createView(pv) {
component = new TestComponent(); component = new TestComponent();
view = pv.instantiate(null, null); view = pv.instantiate(null, null, null);
view.hydrate(new Injector([]), null, component); view.hydrate(new Injector([]), null, component);
cd = view.changeDetector; cd = view.changeDetector;
} }

View File

@ -21,6 +21,8 @@ import {ControlGroupDirective, ControlDirective, Control, ControlGroup, Optional
import * as validators from 'angular2/src/forms/validators'; import * as validators from 'angular2/src/forms/validators';
import {reflector} from 'angular2/src/reflection/reflection';
export function main() { export function main() {
function detectChanges(view) { function detectChanges(view) {
view.changeDetector.detectChanges(); view.changeDetector.detectChanges();
@ -48,7 +50,7 @@ export function main() {
})); }));
compiler.compile(componentType).then((pv) => { compiler.compile(componentType).then((pv) => {
var view = pv.instantiate(null, null); var view = pv.instantiate(null, null, reflector);
view.hydrate(new Injector([]), null, context); view.hydrate(new Injector([]), null, context);
detectChanges(view); detectChanges(view);
callback(view); callback(view);

View File

@ -33,11 +33,11 @@ export function main() {
var bindings = [A, B, C]; var bindings = [A, B, C];
var proto = new ProtoElementInjector(null, 0, bindings); var proto = new ProtoElementInjector(null, 0, bindings);
var elementInjector = proto.instantiate(null,null, null); var elementInjector = proto.instantiate(null, null, null, null);
function instantiate () { function instantiate () {
for (var i = 0; i < iterations; ++i) { for (var i = 0; i < iterations; ++i) {
var ei = proto.instantiate(null, null, null); var ei = proto.instantiate(null, null, null, null);
ei.instantiateDirectives(appInjector, null, null); ei.instantiateDirectives(appInjector, null, null);
} }
} }

View File

@ -8,7 +8,7 @@ import {ExceptionHandler} from 'angular2/src/core/exception_handler';
import { import {
bootstrap, Component, Viewport, Template, ViewContainer, Compiler, onChange bootstrap, Component, Viewport, Template, ViewContainer, Compiler, onChange
} from 'angular2/angular2'; } from 'angular2/angular2';
import {reflector} from 'angular2/src/reflection/reflection'; import {Reflector, reflector} from 'angular2/src/reflection/reflection';
import {CompilerCache} from 'angular2/src/core/compiler/compiler'; import {CompilerCache} from 'angular2/src/core/compiler/compiler';
import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader'; import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader';
import {ShadowDomStrategy, NativeShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy'; import {ShadowDomStrategy, NativeShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy';
@ -286,4 +286,10 @@ export function setupReflectorForAngular() {
"parameters": [], "parameters": [],
"annotations": [] "annotations": []
}); });
reflector.registerType(Reflector, {
"factory": () => reflector,
"parameters": [],
"annotations": []
});
} }

View File

@ -16,7 +16,7 @@ import {ComponentUrlMapper} from 'angular2/src/core/compiler/component_url_mappe
import {StyleInliner} from 'angular2/src/core/compiler/style_inliner'; import {StyleInliner} from 'angular2/src/core/compiler/style_inliner';
import {CssProcessor} from 'angular2/src/core/compiler/css_processor'; import {CssProcessor} from 'angular2/src/core/compiler/css_processor';
import {reflector} from 'angular2/src/reflection/reflection'; import {Reflector, reflector} from 'angular2/src/reflection/reflection';
import {DOM} from 'angular2/src/dom/dom_adapter'; import {DOM} from 'angular2/src/dom/dom_adapter';
import {isPresent} from 'angular2/src/facade/lang'; import {isPresent} from 'angular2/src/facade/lang';
import {window, document, gc} from 'angular2/src/facade/browser'; import {window, document, gc} from 'angular2/src/facade/browser';
@ -177,6 +177,12 @@ function setupReflector() {
"annotations": [] "annotations": []
}); });
reflector.registerType(Reflector, {
"factory": () => reflector,
"parameters": [],
"annotations": []
});
reflector.registerGetters({ reflector.registerGetters({
'value': (a) => a.value, 'value': (a) => a.value,
'left': (a) => a.left, 'left': (a) => a.left,

View File

@ -18,7 +18,7 @@ import {ComponentUrlMapper} from 'angular2/src/core/compiler/component_url_mappe
import {StyleInliner} from 'angular2/src/core/compiler/style_inliner'; import {StyleInliner} from 'angular2/src/core/compiler/style_inliner';
import {CssProcessor} from 'angular2/src/core/compiler/css_processor'; import {CssProcessor} from 'angular2/src/core/compiler/css_processor';
import {reflector} from 'angular2/src/reflection/reflection'; import {Reflector, reflector} from 'angular2/src/reflection/reflection';
function setup() { function setup() {
reflector.registerType(app.HelloCmp, { reflector.registerType(app.HelloCmp, {
@ -156,6 +156,12 @@ function setup() {
"annotations": [] "annotations": []
}); });
reflector.registerType(Reflector, {
"factory": () => reflector,
"parameters": [],
"annotations": []
});
reflector.registerGetters({ reflector.registerGetters({
"greeting": (a) => a.greeting "greeting": (a) => a.greeting
}); });