fix(view): fixed hydrator to pass the right element index when attaching an event listener
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {isPresent, isBlank, Type, int, BaseException} from 'angular2/src/facade/lang';
|
||||
import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
|
||||
import {Math} from 'angular2/src/facade/math';
|
||||
import {List, ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
|
||||
import {Injector, Key, Dependency, bind, Binding, ResolvedBinding, NoBindingError,
|
||||
@@ -318,6 +319,12 @@ class EventEmitterAccessor {
|
||||
this.eventName = eventName;
|
||||
this.getter = getter;
|
||||
}
|
||||
|
||||
subscribe(view:viewModule.AppView, boundElementIndex:number, directive:Object) {
|
||||
var eventEmitter = this.getter(directive);
|
||||
return ObservableWrapper.subscribe(eventEmitter,
|
||||
eventObj => view.triggerEventHandlers(this.eventName, eventObj, boundElementIndex));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-10
@@ -2,7 +2,6 @@ import {Injectable, Inject, OpaqueToken, Injector} from 'angular2/di';
|
||||
import {ListWrapper, MapWrapper, Map, StringMapWrapper, List} from 'angular2/src/facade/collection';
|
||||
import * as eli from './element_injector';
|
||||
import {isPresent, isBlank, BaseException} from 'angular2/src/facade/lang';
|
||||
import {ObservableWrapper} from 'angular2/src/facade/async';
|
||||
import * as vcModule from './view_container';
|
||||
import * as viewModule from './view';
|
||||
import {BindingPropagationConfig, Locals} from 'angular2/change_detection';
|
||||
@@ -160,7 +159,7 @@ export class AppViewHydrator {
|
||||
var elementInjector = view.elementInjectors[i];
|
||||
if (isPresent(elementInjector)) {
|
||||
elementInjector.instantiateDirectives(appInjector, hostElementInjector, shadowDomAppInjector, view.preBuiltObjects[i]);
|
||||
this._setUpEventEmitters(view, elementInjector);
|
||||
this._setUpEventEmitters(view, elementInjector, i);
|
||||
|
||||
// The exporting of $implicit is a special case. Since multiple elements will all export
|
||||
// the different values as $implicit, directly assign $implicit bindings to the variable
|
||||
@@ -190,7 +189,7 @@ export class AppViewHydrator {
|
||||
return renderComponentIndex;
|
||||
}
|
||||
|
||||
_setUpEventEmitters(view:viewModule.AppView, elementInjector:eli.ElementInjector) {
|
||||
_setUpEventEmitters(view:viewModule.AppView, elementInjector:eli.ElementInjector, boundElementIndex:number) {
|
||||
var emitters = elementInjector.getEventEmitterAccessors();
|
||||
for(var directiveIndex = 0; directiveIndex < emitters.length; ++directiveIndex) {
|
||||
var directiveEmitters = emitters[directiveIndex];
|
||||
@@ -198,17 +197,11 @@ export class AppViewHydrator {
|
||||
|
||||
for (var eventIndex = 0; eventIndex < directiveEmitters.length; ++eventIndex) {
|
||||
var eventEmitterAccessor = directiveEmitters[eventIndex];
|
||||
this._setUpSubscription(view, directive, directiveIndex, eventEmitterAccessor);
|
||||
eventEmitterAccessor.subscribe(view, boundElementIndex, directive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_setUpSubscription(view:viewModule.AppView, directive:Object, directiveIndex:number, eventEmitterAccessor) {
|
||||
var eventEmitter = eventEmitterAccessor.getter(directive);
|
||||
ObservableWrapper.subscribe(eventEmitter,
|
||||
eventObj => view.triggerEventHandlers(eventEmitterAccessor.eventName, eventObj, directiveIndex));
|
||||
}
|
||||
|
||||
/**
|
||||
* This should only be called by View or ViewContainer.
|
||||
*/
|
||||
|
||||
@@ -77,7 +77,9 @@ class StringMapWrapper {
|
||||
}
|
||||
static Map merge(Map a, Map b) {
|
||||
var m = new Map.from(a);
|
||||
b.forEach((k, v) => m[k] = v);
|
||||
if (b != null) {
|
||||
b.forEach((k, v) => m[k] = v);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
static bool isEmpty(Map m) => m.isEmpty;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
library test_lib.test_lib;
|
||||
|
||||
import 'package:guinness/guinness.dart' as gns;
|
||||
export 'package:guinness/guinness.dart' hide Expect, expect, NotExpect, beforeEach, it, iit, xit, SpyObject;
|
||||
export 'package:guinness/guinness.dart' hide Expect, expect, NotExpect, beforeEach, it, iit, xit;
|
||||
import 'package:unittest/unittest.dart' hide expect;
|
||||
|
||||
import 'dart:async';
|
||||
@@ -13,6 +13,7 @@ import 'package:angular2/src/reflection/reflection_capabilities.dart';
|
||||
|
||||
import 'package:angular2/src/di/binding.dart' show bind;
|
||||
import 'package:angular2/src/di/injector.dart' show Injector;
|
||||
import 'package:angular2/src/facade/collection.dart' show StringMapWrapper;
|
||||
|
||||
import './test_injector.dart';
|
||||
export './test_injector.dart' show inject;
|
||||
@@ -149,13 +150,40 @@ xit(name, fn) {
|
||||
_it(gns.xit, name, fn);
|
||||
}
|
||||
|
||||
class SpyObject extends gns.SpyObject {
|
||||
// Need to take an optional type as this is required by
|
||||
// the JS SpyObject.
|
||||
SpyObject([type = null]) {
|
||||
class SpyFunction extends gns.SpyFunction {
|
||||
SpyFunction(name): super(name);
|
||||
|
||||
// TODO: vsavkin move to guinness
|
||||
andReturn(value) {
|
||||
return andCallFake(([a0, a1, a2, a3, a4, a5]) => value);
|
||||
}
|
||||
}
|
||||
|
||||
class SpyObject extends gns.SpyObject {
|
||||
final Map<String, SpyFunction> _spyFuncs = {};
|
||||
|
||||
SpyObject([arg]){}
|
||||
|
||||
SpyFunction spy(String funcName) =>
|
||||
_spyFuncs.putIfAbsent(funcName, () => new SpyFunction(funcName));
|
||||
|
||||
static stub([object = null, config = null, overrides = null]) {
|
||||
if (object is! SpyObject) {
|
||||
overrides = config;
|
||||
config = object;
|
||||
object = new SpyObject();
|
||||
}
|
||||
|
||||
var m = StringMapWrapper.merge(config, overrides);
|
||||
StringMapWrapper.forEach(m, (value, key){
|
||||
object.spy(key).andReturn(value);
|
||||
});
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
String elementText(n) {
|
||||
hasNodes(n) {
|
||||
var children = DOM.childNodes(n);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
import {StringMapWrapper} from 'angular2/src/facade/collection';
|
||||
|
||||
import {bind} from 'angular2/di';
|
||||
|
||||
@@ -289,6 +290,20 @@ export class SpyObject {
|
||||
return this[name];
|
||||
}
|
||||
|
||||
static stub(object = null, config = null, overrides = null) {
|
||||
if (!(object instanceof SpyObject)) {
|
||||
overrides = config;
|
||||
config = object;
|
||||
object = new SpyObject();
|
||||
}
|
||||
|
||||
var m = StringMapWrapper.merge(config, overrides);
|
||||
StringMapWrapper.forEach(m, (value, key) => {
|
||||
object.spy(key).andReturn(value);
|
||||
});
|
||||
return object;
|
||||
}
|
||||
|
||||
rttsAssert(value) {
|
||||
return true;
|
||||
}
|
||||
@@ -296,6 +311,7 @@ export class SpyObject {
|
||||
_createGuinnessCompatibleSpy(){
|
||||
var newSpy = jasmine.createSpy();
|
||||
newSpy.andCallFake = newSpy.and.callFake;
|
||||
newSpy.andReturn = newSpy.and.returnValue;
|
||||
// return null by default to satisfy our rtts asserts
|
||||
newSpy.and.returnValue(null);
|
||||
return newSpy;
|
||||
|
||||
Reference in New Issue
Block a user