refactor(EventHandler): have a single instance of event handlers per ProtoView
This commit is contained in:
+24
-15
@@ -1,18 +1,19 @@
|
||||
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 {ListWrapper, MapWrapper, List} from 'angular2/src/facade/collection';
|
||||
import {ListWrapper, MapWrapper, List, StringMapWrapper} from 'angular2/src/facade/collection';
|
||||
import {ProtoElementInjector, PreBuiltObjects, DirectiveBinding} from 'angular2/src/core/compiler/element_injector';
|
||||
import {Parent, Ancestor} from 'angular2/src/core/annotations/visibility';
|
||||
import {EventEmitter, PropertySetter} from 'angular2/src/core/annotations/di';
|
||||
import {onDestroy} from 'angular2/src/core/annotations/annotations';
|
||||
import {Optional, Injector, Inject, bind} from 'angular2/di';
|
||||
import {View} from 'angular2/src/core/compiler/view';
|
||||
import {ProtoView, View} from 'angular2/src/core/compiler/view';
|
||||
import {ViewContainer} from 'angular2/src/core/compiler/view_container';
|
||||
import {NgElement} from 'angular2/src/core/dom/element';
|
||||
import {LightDom, SourceLightDom, DestinationLightDom} from 'angular2/src/core/compiler/shadow_dom_emulation/light_dom';
|
||||
import {Directive} from 'angular2/src/core/annotations/annotations';
|
||||
import {BindingPropagationConfig} from 'angular2/src/core/compiler/binding_propagation_config';
|
||||
import {reflector} from 'angular2/src/reflection/reflection';
|
||||
import {DynamicProtoChangeDetector} from 'angular2/change_detection';
|
||||
|
||||
@proxy
|
||||
@IMPLEMENTS(View)
|
||||
@@ -130,7 +131,7 @@ export function main() {
|
||||
if (isBlank(lightDomAppInjector)) lightDomAppInjector = new Injector([]);
|
||||
|
||||
var proto = new ProtoElementInjector(null, 0, bindings, isPresent(shadowDomAppInjector));
|
||||
var inj = proto.instantiate(null, null, null, reflector);
|
||||
var inj = proto.instantiate(null, null, reflector);
|
||||
var preBuilt = isPresent(preBuiltObjects) ? preBuiltObjects : defaultPreBuiltObjects;
|
||||
|
||||
inj.instantiateDirectives(lightDomAppInjector, shadowDomAppInjector, preBuilt);
|
||||
@@ -143,12 +144,12 @@ export function main() {
|
||||
var inj = new Injector([]);
|
||||
|
||||
var protoParent = new ProtoElementInjector(null, 0, parentBindings);
|
||||
var parent = protoParent.instantiate(null, null, null, reflector);
|
||||
var parent = protoParent.instantiate(null, null, reflector);
|
||||
|
||||
parent.instantiateDirectives(inj, null, parentPreBuildObjects);
|
||||
|
||||
var protoChild = new ProtoElementInjector(protoParent, 1, childBindings, false, 1);
|
||||
var child = protoChild.instantiate(parent, null, null, reflector);
|
||||
var child = protoChild.instantiate(parent, null, reflector);
|
||||
child.instantiateDirectives(inj, null, defaultPreBuiltObjects);
|
||||
|
||||
return child;
|
||||
@@ -161,11 +162,11 @@ export function main() {
|
||||
var shadowInj = inj.createChild([]);
|
||||
|
||||
var protoParent = new ProtoElementInjector(null, 0, hostBindings, true);
|
||||
var host = protoParent.instantiate(null, null, null, reflector);
|
||||
var host = protoParent.instantiate(null, null, reflector);
|
||||
host.instantiateDirectives(inj, shadowInj, hostPreBuildObjects);
|
||||
|
||||
var protoChild = new ProtoElementInjector(protoParent, 0, shadowBindings, false, 1);
|
||||
var shadow = protoChild.instantiate(null, host, null, reflector);
|
||||
var shadow = protoChild.instantiate(null, host, reflector);
|
||||
shadow.instantiateDirectives(shadowInj, null, null);
|
||||
|
||||
return shadow;
|
||||
@@ -198,9 +199,9 @@ export function main() {
|
||||
var protoChild1 = new ProtoElementInjector(protoParent, 1, []);
|
||||
var protoChild2 = new ProtoElementInjector(protoParent, 2, []);
|
||||
|
||||
var p = protoParent.instantiate(null, null, null, reflector);
|
||||
var c1 = protoChild1.instantiate(p, null, null, reflector);
|
||||
var c2 = protoChild2.instantiate(p, null, null, reflector);
|
||||
var p = protoParent.instantiate(null, null, reflector);
|
||||
var c1 = protoChild1.instantiate(p, null, reflector);
|
||||
var c2 = protoChild2.instantiate(p, null, reflector);
|
||||
|
||||
expect(humanize(p, [
|
||||
[p, 'parent'],
|
||||
@@ -215,8 +216,8 @@ export function main() {
|
||||
var protoParent = new ProtoElementInjector(null, 0, []);
|
||||
var protoChild = new ProtoElementInjector(protoParent, 1, [], false, distance);
|
||||
|
||||
var p = protoParent.instantiate(null, null, null, reflector);
|
||||
var c = protoChild.instantiate(p, null, null, reflector);
|
||||
var p = protoParent.instantiate(null, null, reflector);
|
||||
var c = protoChild.instantiate(p, null, reflector);
|
||||
|
||||
expect(c.directParent()).toEqual(p);
|
||||
});
|
||||
@@ -226,8 +227,8 @@ export function main() {
|
||||
var protoParent = new ProtoElementInjector(null, 0, []);
|
||||
var protoChild = new ProtoElementInjector(protoParent, 1, [], false, distance);
|
||||
|
||||
var p = protoParent.instantiate(null, null, null, reflector);
|
||||
var c = protoChild.instantiate(p, null, null, reflector);
|
||||
var p = protoParent.instantiate(null, null, reflector);
|
||||
var c = protoChild.instantiate(p, null, reflector);
|
||||
|
||||
expect(c.directParent()).toEqual(null);
|
||||
});
|
||||
@@ -477,8 +478,16 @@ export function main() {
|
||||
|
||||
describe('event emitters', () => {
|
||||
it('should be injectable and callable', () => {
|
||||
var inj = injector([NeedsEventEmitter]);
|
||||
var called = false;
|
||||
var handlers = StringMapWrapper.create();
|
||||
StringMapWrapper.set(handlers, 'click', (e, view) => { called = true;});
|
||||
var pv = new ProtoView(null, null, null);
|
||||
pv.eventHandlers = [handlers];
|
||||
var view = new View(pv, null, new DynamicProtoChangeDetector(null), MapWrapper.create());
|
||||
var preBuildObject = new PreBuiltObjects(view, null, null, null, null);
|
||||
var inj = injector([NeedsEventEmitter], null, null, preBuildObject);
|
||||
inj.get(NeedsEventEmitter).click();
|
||||
expect(called).toEqual(true);
|
||||
});
|
||||
|
||||
it('should be queryable through hasEventEmitter', () => {
|
||||
|
||||
@@ -72,7 +72,7 @@ export function main() {
|
||||
parentView = createView([dom.childNodes[0]]);
|
||||
protoView = new ProtoView(el('<div>hi</div>'), new DynamicProtoChangeDetector(null),
|
||||
new NativeShadowDomStrategy(null));
|
||||
elementInjector = new ElementInjector(null, null, null, null, reflector);
|
||||
elementInjector = new ElementInjector(null, null, null, reflector);
|
||||
viewContainer = new ViewContainer(parentView, insertionElement, protoView, elementInjector,
|
||||
null, reflector);
|
||||
customViewWithOneNode = createView([el('<div>single</div>')]);
|
||||
|
||||
+4
-5
@@ -264,7 +264,7 @@ export function main() {
|
||||
pv.bindElement(testProtoElementInjector);
|
||||
|
||||
var hostProtoInjector = new ProtoElementInjector(null, 0, []);
|
||||
var hostInjector = hostProtoInjector.instantiate(null, null, null, reflector);
|
||||
var hostInjector = hostProtoInjector.instantiate(null, null, reflector);
|
||||
var view;
|
||||
expect(() => view = pv.instantiate(hostInjector, null, reflector)).not.toThrow();
|
||||
expect(testProtoElementInjector.parentElementInjector).toBe(view.elementInjectors[0]);
|
||||
@@ -279,7 +279,7 @@ export function main() {
|
||||
pv.bindElement(testProtoElementInjector);
|
||||
|
||||
var hostProtoInjector = new ProtoElementInjector(null, 0, []);
|
||||
var hostInjector = hostProtoInjector.instantiate(null, null, null, reflector);
|
||||
var hostInjector = hostProtoInjector.instantiate(null, null, reflector);
|
||||
expect(() => pv.instantiate(hostInjector, null, reflector)).not.toThrow();
|
||||
expect(testProtoElementInjector.parentElementInjector).toBeNull();
|
||||
expect(testProtoElementInjector.hostElementInjector).toBe(hostInjector);
|
||||
@@ -751,11 +751,10 @@ class TestProtoElementInjector extends ProtoElementInjector {
|
||||
super(parent, index, bindings, firstBindingIsComponent);
|
||||
}
|
||||
|
||||
instantiate(parent:ElementInjector, host:ElementInjector, events,
|
||||
reflector: Reflector):ElementInjector {
|
||||
instantiate(parent:ElementInjector, host:ElementInjector, reflector: Reflector):ElementInjector {
|
||||
this.parentElementInjector = parent;
|
||||
this.hostElementInjector = host;
|
||||
return super.instantiate(parent, host, events, reflector);
|
||||
return super.instantiate(parent, host, reflector);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user