Revert "fix(core): should support event.stopImmediatePropagation"
This reverts commit 5e0eb5e3d94bd7077c4d6657b89bfc8d900f2bc6.
This commit is contained in:
parent
d47b2a6f70
commit
2586846ee2
|
@ -34,8 +34,6 @@ const FALSE = 'FALSE';
|
||||||
const ANGULAR = 'ANGULAR';
|
const ANGULAR = 'ANGULAR';
|
||||||
const NATIVE_ADD_LISTENER = 'addEventListener';
|
const NATIVE_ADD_LISTENER = 'addEventListener';
|
||||||
const NATIVE_REMOVE_LISTENER = 'removeEventListener';
|
const NATIVE_REMOVE_LISTENER = 'removeEventListener';
|
||||||
// use the same symbol string which is used in zone.js
|
|
||||||
const stopSymbol = '__zone_symbol__propagationStopped';
|
|
||||||
|
|
||||||
const blackListedEvents: string[] =
|
const blackListedEvents: string[] =
|
||||||
(typeof Zone !== 'undefined') && (Zone as any)[__symbol__('BLACK_LISTED_EVENTS')];
|
(typeof Zone !== 'undefined') && (Zone as any)[__symbol__('BLACK_LISTED_EVENTS')];
|
||||||
|
@ -83,9 +81,6 @@ const globalListener = function(event: Event) {
|
||||||
// itself or others
|
// itself or others
|
||||||
const copiedTasks = taskDatas.slice();
|
const copiedTasks = taskDatas.slice();
|
||||||
for (let i = 0; i < copiedTasks.length; i++) {
|
for (let i = 0; i < copiedTasks.length; i++) {
|
||||||
if ((event as any)[stopSymbol] === true) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
const taskData = copiedTasks[i];
|
const taskData = copiedTasks[i];
|
||||||
if (taskData.zone !== Zone.current) {
|
if (taskData.zone !== Zone.current) {
|
||||||
// only use Zone.run when Zone.current not equals to stored zone
|
// only use Zone.run when Zone.current not equals to stored zone
|
||||||
|
@ -99,29 +94,7 @@ const globalListener = function(event: Event) {
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DomEventsPlugin extends EventManagerPlugin {
|
export class DomEventsPlugin extends EventManagerPlugin {
|
||||||
constructor(@Inject(DOCUMENT) doc: any, private ngZone: NgZone) {
|
constructor(@Inject(DOCUMENT) doc: any, private ngZone: NgZone) { super(doc); }
|
||||||
super(doc);
|
|
||||||
|
|
||||||
this.patchEvent();
|
|
||||||
}
|
|
||||||
|
|
||||||
private patchEvent() {
|
|
||||||
if (!Event || !Event.prototype) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const symbol = '__zone_symbol__stopImmediatePropagation';
|
|
||||||
if ((Event.prototype as any)[symbol]) {
|
|
||||||
// already patched by zone.js
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
(Event.prototype as any)[symbol] = Event.prototype.stopImmediatePropagation;
|
|
||||||
Event.prototype.stopImmediatePropagation = function() {
|
|
||||||
if (this) {
|
|
||||||
this[stopSymbol] = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// This plugin should come last in the list of plugins, because it accepts all
|
// This plugin should come last in the list of plugins, because it accepts all
|
||||||
// events.
|
// events.
|
||||||
|
|
|
@ -152,42 +152,6 @@ export function main() {
|
||||||
expect(receivedEvents).toEqual([]);
|
expect(receivedEvents).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support event.stopImmediatePropagation', () => {
|
|
||||||
const Zone = (window as any)['Zone'];
|
|
||||||
|
|
||||||
const element = el('<div><div></div></div>');
|
|
||||||
getDOM().appendChild(doc.body, element);
|
|
||||||
const dispatchedEvent = getDOM().createMouseEvent('click');
|
|
||||||
let receivedEvents: any[] /** TODO #9100 */ = [];
|
|
||||||
let receivedZones: any[] = [];
|
|
||||||
const handler1 = (e: any /** TODO #9100 */) => {
|
|
||||||
receivedEvents.push(e);
|
|
||||||
receivedZones.push(Zone.current.name);
|
|
||||||
e.stopImmediatePropagation();
|
|
||||||
};
|
|
||||||
const handler2 = (e: any /** TODO #9100 */) => {
|
|
||||||
receivedEvents.push(e);
|
|
||||||
receivedZones.push(Zone.current.name);
|
|
||||||
};
|
|
||||||
const manager = new EventManager([domEventPlugin], new FakeNgZone());
|
|
||||||
|
|
||||||
let remover1 = null;
|
|
||||||
let remover2 = null;
|
|
||||||
Zone.root.run(() => { remover1 = manager.addEventListener(element, 'click', handler1); });
|
|
||||||
Zone.root.fork({name: 'test'}).run(() => {
|
|
||||||
remover2 = manager.addEventListener(element, 'click', handler2);
|
|
||||||
});
|
|
||||||
getDOM().dispatchEvent(element, dispatchedEvent);
|
|
||||||
expect(receivedEvents).toEqual([dispatchedEvent]);
|
|
||||||
expect(receivedZones).toEqual([Zone.root.name]);
|
|
||||||
|
|
||||||
receivedEvents = [];
|
|
||||||
remover1 && remover1();
|
|
||||||
remover2 && remover2();
|
|
||||||
getDOM().dispatchEvent(element, dispatchedEvent);
|
|
||||||
expect(receivedEvents).toEqual([]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle event correctly when one handler remove itself ', () => {
|
it('should handle event correctly when one handler remove itself ', () => {
|
||||||
const Zone = (window as any)['Zone'];
|
const Zone = (window as any)['Zone'];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue