Skip to content

Commit 951a808

Browse files
committed
refactor(PropertySetter): use the global reflector
1 parent c67194a commit 951a808

File tree

20 files changed

+75
-120
lines changed

20 files changed

+75
-120
lines changed

modules/angular2/src/core/application.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function _injectorBindings(appComponentType): List<Binding> {
5757
}, [appComponentAnnotatedTypeToken, appDocumentToken]),
5858

5959
bind(appViewToken).toAsyncFactory((changeDetection, compiler, injector, appElement,
60-
appComponentAnnotatedType, strategy, eventManager, reflector) => {
60+
appComponentAnnotatedType, strategy, eventManager) => {
6161
return compiler.compile(appComponentAnnotatedType.type).then(
6262
(protoView) => {
6363
var appProtoView = ProtoView.createRootProtoView(protoView, appElement,
@@ -66,12 +66,12 @@ function _injectorBindings(appComponentType): List<Binding> {
6666
// The light Dom of the app element is not considered part of
6767
// the angular application. Thus the context and lightDomInjector are
6868
// empty.
69-
var view = appProtoView.instantiate(null, eventManager, reflector);
69+
var view = appProtoView.instantiate(null, eventManager);
7070
view.hydrate(injector, null, new Object());
7171
return view;
7272
});
7373
}, [ChangeDetection, Compiler, Injector, appElementToken, appComponentAnnotatedTypeToken,
74-
ShadowDomStrategy, EventManager, Reflector]),
74+
ShadowDomStrategy, EventManager]),
7575

7676
bind(appChangeDetectorToken).toFactory((rootView) => rootView.changeDetector,
7777
[appViewToken]),

modules/angular2/src/core/compiler/element_injector.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {ViewContainer} from 'angular2/src/core/compiler/view_container';
1010
import {NgElement} from 'angular2/src/core/dom/element';
1111
import {Directive, onChange, onDestroy} from 'angular2/src/core/annotations/annotations'
1212
import {BindingPropagationConfig} from 'angular2/src/core/compiler/binding_propagation_config'
13-
import {Reflector} from 'angular2/src/reflection/reflection';
13+
import {reflector} from 'angular2/src/reflection/reflection';
1414

1515
var _MAX_DIRECTIVE_CONSTRUCTION_COUNTER = 10;
1616

@@ -270,8 +270,8 @@ export class ProtoElementInjector {
270270
}
271271
}
272272

273-
instantiate(parent:ElementInjector, host:ElementInjector, reflector: Reflector):ElementInjector {
274-
return new ElementInjector(this, parent, host, reflector);
273+
instantiate(parent:ElementInjector, host:ElementInjector):ElementInjector {
274+
return new ElementInjector(this, parent, host);
275275
}
276276

277277
directParent(): ProtoElementInjector {
@@ -324,10 +324,8 @@ export class ElementInjector extends TreeNode {
324324
_obj9:any;
325325
_preBuiltObjects;
326326
_constructionCounter;
327-
_refelector: Reflector;
328327

329-
constructor(proto:ProtoElementInjector, parent:ElementInjector, host:ElementInjector,
330-
reflector: Reflector) {
328+
constructor(proto:ProtoElementInjector, parent:ElementInjector, host:ElementInjector) {
331329
super(parent);
332330
if (isPresent(parent) && isPresent(host)) {
333331
throw new BaseException('Only either parent or host is allowed');
@@ -340,7 +338,6 @@ export class ElementInjector extends TreeNode {
340338
}
341339

342340
this._proto = proto;
343-
this._refelector = reflector;
344341

345342
//we cannot call clearDirectives because fields won't be detected
346343
this._preBuiltObjects = null;
@@ -518,7 +515,7 @@ export class ElementInjector extends TreeNode {
518515
_buildPropSetter(dep) {
519516
var ngElement = this._getPreBuiltObjectByKeyId(StaticKeys.instance().ngElementId);
520517
var domElement = ngElement.domElement;
521-
var setter = this._refelector.setter(dep.propSetterName);
518+
var setter = reflector.setter(dep.propSetterName);
522519
return function(v) { setter(domElement, v) };
523520
}
524521

modules/angular2/src/core/compiler/view.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import {ShadowDomStrategy} from './shadow_dom_strategy';
1818
import {ViewPool} from './view_pool';
1919
import {EventManager} from 'angular2/src/core/events/event_manager';
2020

21-
import {Reflector} from 'angular2/src/reflection/reflection';
22-
2321
const NG_BINDING_CLASS = 'ng-binding';
2422
const NG_BINDING_CLASS_SELECTOR = '.ng-binding';
2523

@@ -320,23 +318,19 @@ export class ProtoView {
320318
}
321319

322320
// TODO(rado): hostElementInjector should be moved to hydrate phase.
323-
instantiate(hostElementInjector: ElementInjector, eventManager: EventManager,
324-
reflector: Reflector):View {
325-
if (this._viewPool.length() == 0) this._preFillPool(hostElementInjector, eventManager,
326-
reflector);
321+
instantiate(hostElementInjector: ElementInjector, eventManager: EventManager):View {
322+
if (this._viewPool.length() == 0) this._preFillPool(hostElementInjector, eventManager);
327323
var view = this._viewPool.pop();
328-
return isPresent(view) ? view : this._instantiate(hostElementInjector, eventManager, reflector);
324+
return isPresent(view) ? view : this._instantiate(hostElementInjector, eventManager);
329325
}
330326

331-
_preFillPool(hostElementInjector: ElementInjector, eventManager: EventManager,
332-
reflector: Reflector) {
327+
_preFillPool(hostElementInjector: ElementInjector, eventManager: EventManager) {
333328
for (var i = 0; i < VIEW_POOL_PREFILL; i++) {
334-
this._viewPool.push(this._instantiate(hostElementInjector, eventManager, reflector));
329+
this._viewPool.push(this._instantiate(hostElementInjector, eventManager));
335330
}
336331
}
337332

338-
_instantiate(hostElementInjector: ElementInjector, eventManager: EventManager,
339-
reflector: Reflector): View {
333+
_instantiate(hostElementInjector: ElementInjector, eventManager: EventManager): View {
340334
var rootElementClone = this.instantiateInPlace ? this.element : DOM.importIntoDoc(this.element);
341335
var elementsWithBindingsDynamic;
342336
if (this.isTemplateElement) {
@@ -389,9 +383,9 @@ export class ProtoView {
389383
if (isPresent(protoElementInjector)) {
390384
if (isPresent(protoElementInjector.parent)) {
391385
var parentElementInjector = elementInjectors[protoElementInjector.parent.index];
392-
elementInjector = protoElementInjector.instantiate(parentElementInjector, null, reflector);
386+
elementInjector = protoElementInjector.instantiate(parentElementInjector, null);
393387
} else {
394-
elementInjector = protoElementInjector.instantiate(null, hostElementInjector, reflector);
388+
elementInjector = protoElementInjector.instantiate(null, hostElementInjector);
395389
ListWrapper.push(rootElementInjectors, elementInjector);
396390
}
397391
}
@@ -418,7 +412,7 @@ export class ProtoView {
418412
var bindingPropagationConfig = null;
419413
if (isPresent(binder.componentDirective)) {
420414
var strategy = this.shadowDomStrategy;
421-
var childView = binder.nestedProtoView.instantiate(elementInjector, eventManager, reflector);
415+
var childView = binder.nestedProtoView.instantiate(elementInjector, eventManager);
422416
view.changeDetector.addChild(childView.changeDetector);
423417

424418
lightDom = strategy.constructLightDom(view, childView, element);
@@ -434,7 +428,7 @@ export class ProtoView {
434428
if (isPresent(binder.viewportDirective)) {
435429
var destLightDom = this._directParentElementLightDom(protoElementInjector, preBuiltObjects);
436430
viewContainer = new ViewContainer(view, element, binder.nestedProtoView, elementInjector,
437-
eventManager, reflector, destLightDom);
431+
eventManager, destLightDom);
438432
ListWrapper.push(viewContainers, viewContainer);
439433
}
440434

modules/angular2/src/core/compiler/view_container.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {Injector} from 'angular2/di';
66
import * as eiModule from 'angular2/src/core/compiler/element_injector';
77
import {isPresent, isBlank} from 'angular2/src/facade/lang';
88
import {EventManager} from 'angular2/src/core/events/event_manager';
9-
import {Reflector} from 'angular2/src/reflection/reflection';
109

1110
export class ViewContainer {
1211
parentView: viewModule.View;
@@ -15,7 +14,6 @@ export class ViewContainer {
1514
_views: List<viewModule.View>;
1615
_lightDom: any;
1716
_eventManager: EventManager;
18-
_reflector: Reflector;
1917
elementInjector: eiModule.ElementInjector;
2018
appInjector: Injector;
2119
hostElementInjector: eiModule.ElementInjector;
@@ -25,14 +23,12 @@ export class ViewContainer {
2523
defaultProtoView: viewModule.ProtoView,
2624
elementInjector: eiModule.ElementInjector,
2725
eventManager: EventManager,
28-
reflector: Reflector,
2926
lightDom = null) {
3027
this.parentView = parentView;
3128
this.templateElement = templateElement;
3229
this.defaultProtoView = defaultProtoView;
3330
this.elementInjector = elementInjector;
3431
this._lightDom = lightDom;
35-
this._reflector = reflector;
3632

3733
// The order in this list matches the DOM order.
3834
this._views = [];
@@ -81,8 +77,7 @@ export class ViewContainer {
8177
if (!this.hydrated()) throw new BaseException(
8278
'Cannot create views on a dehydrated ViewContainer');
8379
// TODO(rado): replace with viewFactory.
84-
var newView = this.defaultProtoView.instantiate(this.hostElementInjector, this._eventManager,
85-
this._reflector);
80+
var newView = this.defaultProtoView.instantiate(this.hostElementInjector, this._eventManager);
8681
// insertion must come before hydration so that element injector trees are attached.
8782
this.insert(newView, atIndex);
8883
newView.hydrate(this.appInjector, this.hostElementInjector, this.parentView.context);

modules/angular2/test/core/compiler/element_injector_spec.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {NgElement} from 'angular2/src/core/dom/element';
1212
import {LightDom, SourceLightDom, DestinationLightDom} from 'angular2/src/core/compiler/shadow_dom_emulation/light_dom';
1313
import {Directive} from 'angular2/src/core/annotations/annotations';
1414
import {BindingPropagationConfig} from 'angular2/src/core/compiler/binding_propagation_config';
15-
import {reflector} from 'angular2/src/reflection/reflection';
1615
import {DynamicProtoChangeDetector} from 'angular2/change_detection';
1716

1817
@proxy
@@ -131,7 +130,7 @@ export function main() {
131130
if (isBlank(lightDomAppInjector)) lightDomAppInjector = new Injector([]);
132131

133132
var proto = new ProtoElementInjector(null, 0, bindings, isPresent(shadowDomAppInjector));
134-
var inj = proto.instantiate(null, null, reflector);
133+
var inj = proto.instantiate(null, null);
135134
var preBuilt = isPresent(preBuiltObjects) ? preBuiltObjects : defaultPreBuiltObjects;
136135

137136
inj.instantiateDirectives(lightDomAppInjector, shadowDomAppInjector, preBuilt);
@@ -144,12 +143,12 @@ export function main() {
144143
var inj = new Injector([]);
145144

146145
var protoParent = new ProtoElementInjector(null, 0, parentBindings);
147-
var parent = protoParent.instantiate(null, null, reflector);
146+
var parent = protoParent.instantiate(null, null);
148147

149148
parent.instantiateDirectives(inj, null, parentPreBuildObjects);
150149

151150
var protoChild = new ProtoElementInjector(protoParent, 1, childBindings, false, 1);
152-
var child = protoChild.instantiate(parent, null, reflector);
151+
var child = protoChild.instantiate(parent, null);
153152
child.instantiateDirectives(inj, null, defaultPreBuiltObjects);
154153

155154
return child;
@@ -162,11 +161,11 @@ export function main() {
162161
var shadowInj = inj.createChild([]);
163162

164163
var protoParent = new ProtoElementInjector(null, 0, hostBindings, true);
165-
var host = protoParent.instantiate(null, null, reflector);
164+
var host = protoParent.instantiate(null, null);
166165
host.instantiateDirectives(inj, shadowInj, hostPreBuildObjects);
167166

168167
var protoChild = new ProtoElementInjector(protoParent, 0, shadowBindings, false, 1);
169-
var shadow = protoChild.instantiate(null, host, reflector);
168+
var shadow = protoChild.instantiate(null, host);
170169
shadow.instantiateDirectives(shadowInj, null, null);
171170

172171
return shadow;
@@ -199,9 +198,9 @@ export function main() {
199198
var protoChild1 = new ProtoElementInjector(protoParent, 1, []);
200199
var protoChild2 = new ProtoElementInjector(protoParent, 2, []);
201200

202-
var p = protoParent.instantiate(null, null, reflector);
203-
var c1 = protoChild1.instantiate(p, null, reflector);
204-
var c2 = protoChild2.instantiate(p, null, reflector);
201+
var p = protoParent.instantiate(null, null);
202+
var c1 = protoChild1.instantiate(p, null);
203+
var c2 = protoChild2.instantiate(p, null);
205204

206205
expect(humanize(p, [
207206
[p, 'parent'],
@@ -216,8 +215,8 @@ export function main() {
216215
var protoParent = new ProtoElementInjector(null, 0, []);
217216
var protoChild = new ProtoElementInjector(protoParent, 1, [], false, distance);
218217

219-
var p = protoParent.instantiate(null, null, reflector);
220-
var c = protoChild.instantiate(p, null, reflector);
218+
var p = protoParent.instantiate(null, null);
219+
var c = protoChild.instantiate(p, null);
221220

222221
expect(c.directParent()).toEqual(p);
223222
});
@@ -227,8 +226,8 @@ export function main() {
227226
var protoParent = new ProtoElementInjector(null, 0, []);
228227
var protoChild = new ProtoElementInjector(protoParent, 1, [], false, distance);
229228

230-
var p = protoParent.instantiate(null, null, reflector);
231-
var c = protoChild.instantiate(p, null, reflector);
229+
var p = protoParent.instantiate(null, null);
230+
var c = protoChild.instantiate(p, null);
232231

233232
expect(c.directParent()).toEqual(null);
234233
});
@@ -435,7 +434,7 @@ export function main() {
435434
});
436435

437436
it('should return viewContainer', function () {
438-
var viewContainer = new ViewContainer(null, null, null, null, null, null);
437+
var viewContainer = new ViewContainer(null, null, null, null, null);
439438
var inj = injector([], null, null, new PreBuiltObjects(null, null, viewContainer, null, null));
440439

441440
expect(inj.get(ViewContainer)).toEqual(viewContainer);

modules/angular2/test/core/compiler/integration_spec.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import {If} from 'angular2/src/directives/if';
2828

2929
import {ViewContainer} from 'angular2/src/core/compiler/view_container';
3030

31-
import {reflector} from 'angular2/src/reflection/reflection';
32-
3331
export function main() {
3432
describe('integration tests', function() {
3533
var compiler, tplResolver;
@@ -58,11 +56,7 @@ export function main() {
5856
var view, ctx, cd;
5957
function createView(pv) {
6058
ctx = new MyComp();
61-
view = pv.instantiate(
62-
null,
63-
null,
64-
reflector
65-
);
59+
view = pv.instantiate(null, null);
6660
view.hydrate(new Injector([]), null, ctx);
6761
cd = view.changeDetector;
6862
}

modules/angular2/test/core/compiler/pipeline/element_binder_builder_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function main() {
8282

8383
function instantiateView(protoView) {
8484
evalContext = new Context();
85-
view = protoView.instantiate(null, null, null);
85+
view = protoView.instantiate(null, null);
8686
view.hydrate(new Injector([]), null, evalContext);
8787
changeDetector = view.changeDetector;
8888
}

modules/angular2/test/core/compiler/shadow_dom/shadow_dom_emulation_integration_spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import {ViewContainer} from 'angular2/src/core/compiler/view_container';
3232

3333
import {BrowserDomAdapter} from 'angular2/src/dom/browser_adapter';
3434

35-
import {reflector} from 'angular2/src/reflection/reflection';
36-
3735
export function main() {
3836
BrowserDomAdapter.makeCurrent();
3937
describe('integration tests', function() {
@@ -357,7 +355,7 @@ class MyComp {
357355
}
358356

359357
function createView(pv) {
360-
var view = pv.instantiate(null, null, reflector);
358+
var view = pv.instantiate(null, null);
361359
view.hydrate(new Injector([]), null, {});
362360
return view;
363361
}

modules/angular2/test/core/compiler/shadow_dom_strategy_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function main() {
3737
var host = el('<div></div>');
3838
var nodes = el('<div>view</div>');
3939
var pv = new ProtoView(nodes, new DynamicProtoChangeDetector(null), null);
40-
var view = pv.instantiate(null, null, null);
40+
var view = pv.instantiate(null, null);
4141

4242
strategy.attachTemplate(host, view);
4343
var shadowRoot = DOM.getShadowRoot(host);
@@ -83,7 +83,7 @@ export function main() {
8383
var host = el('<div><span>original content</span></div>');
8484
var nodes = el('<div>view</div>');
8585
var pv = new ProtoView(nodes, new DynamicProtoChangeDetector(null), null);
86-
var view = pv.instantiate(null, null, null);
86+
var view = pv.instantiate(null, null);
8787

8888
strategy.attachTemplate(host, view);
8989
var firstChild = DOM.firstChild(host);
@@ -218,7 +218,7 @@ export function main() {
218218
var host = el('<div><span>original content</span></div>');
219219
var nodes = el('<div>view</div>');
220220
var pv = new ProtoView(nodes, new DynamicProtoChangeDetector(null), null);
221-
var view = pv.instantiate(null, null, null);
221+
var view = pv.instantiate(null, null);
222222

223223
strategy.attachTemplate(host, view);
224224
var firstChild = DOM.firstChild(host);

modules/angular2/test/core/compiler/view_container_spec.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {Injector} from 'angular2/di';
88
import {ProtoElementInjector, ElementInjector} from 'angular2/src/core/compiler/element_injector';
99
import {NativeShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy';
1010
import {DynamicProtoChangeDetector, ChangeDetector, Lexer, Parser} from 'angular2/change_detection';
11-
import {reflector} from 'angular2/src/reflection/reflection';
1211

1312
function createView(nodes) {
1413
var view = new View(null, nodes, new DynamicProtoChangeDetector(null), MapWrapper.create());
@@ -72,9 +71,9 @@ export function main() {
7271
parentView = createView([dom.childNodes[0]]);
7372
protoView = new ProtoView(el('<div>hi</div>'), new DynamicProtoChangeDetector(null),
7473
new NativeShadowDomStrategy(null));
75-
elementInjector = new ElementInjector(null, null, null, reflector);
74+
elementInjector = new ElementInjector(null, null, null);
7675
viewContainer = new ViewContainer(parentView, insertionElement, protoView, elementInjector,
77-
null, reflector);
76+
null);
7877
customViewWithOneNode = createView([el('<div>single</div>')]);
7978
customViewWithTwoNodes = createView([el('<div>one</div>'), el('<div>two</div>')]);
8079
});
@@ -219,7 +218,7 @@ export function main() {
219218
new DynamicProtoChangeDetector(null), new NativeShadowDomStrategy(null));
220219
pv.bindElement(new ProtoElementInjector(null, 1, [SomeDirective]));
221220
pv.bindTextNode(0, parser.parseBinding('foo', null));
222-
fancyView = pv.instantiate(null, null, reflector);
221+
fancyView = pv.instantiate(null, null);
223222
});
224223

225224
it('hydrating should update rootElementInjectors and parent change detector', () => {

0 commit comments

Comments
 (0)