refactor(core): move EventManager from core to platform/dom

Closes #5465
This commit is contained in:
vsavkin
2015-11-24 15:05:04 -08:00
committed by Victor Savkin
parent 0c9596ae2b
commit b7b3c85033
17 changed files with 27 additions and 18 deletions
@@ -24,7 +24,6 @@ import {Compiler} from './linker/compiler';
import {Compiler_} from "./linker/compiler";
import {DynamicComponentLoader} from './linker/dynamic_component_loader';
import {DynamicComponentLoader_} from "./linker/dynamic_component_loader";
import {EventManager} from './render';
/**
* A default set of providers which should be included in any Angular
@@ -44,6 +43,5 @@ export const APPLICATION_COMMON_PROVIDERS: Array<Type | Provider | any[]> = CONS
new Provider(KeyValueDiffers, {useValue: defaultKeyValueDiffers}),
DirectiveResolver,
PipeResolver,
new Provider(DynamicComponentLoader, {useClass: DynamicComponentLoader_}),
EventManager
new Provider(DynamicComponentLoader, {useClass: DynamicComponentLoader_})
]);
+1 -3
View File
@@ -16,6 +16,4 @@ export {
RenderEmbeddedTemplateCmd,
RenderBeginCmd,
RenderComponentTemplate
} from './render/api';
export {EventManager, EventManagerPlugin, EVENT_MANAGER_PLUGINS} from './render/event_manager';
} from './render/api';
@@ -1,57 +0,0 @@
import {CONST_EXPR} from 'angular2/src/facade/lang';
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
import {Injectable, Inject, OpaqueToken} from 'angular2/src/core/di';
import {NgZone} from 'angular2/src/core/zone/ng_zone';
import {ListWrapper} from 'angular2/src/facade/collection';
export const EVENT_MANAGER_PLUGINS: OpaqueToken =
CONST_EXPR(new OpaqueToken("EventManagerPlugins"));
@Injectable()
export class EventManager {
private _plugins: EventManagerPlugin[];
constructor(@Inject(EVENT_MANAGER_PLUGINS) plugins: EventManagerPlugin[], private _zone: NgZone) {
plugins.forEach(p => p.manager = this);
this._plugins = ListWrapper.reversed(plugins);
}
addEventListener(element: HTMLElement, eventName: string, handler: Function) {
var plugin = this._findPluginFor(eventName);
plugin.addEventListener(element, eventName, handler);
}
addGlobalEventListener(target: string, eventName: string, handler: Function): Function {
var plugin = this._findPluginFor(eventName);
return plugin.addGlobalEventListener(target, eventName, handler);
}
getZone(): NgZone { return this._zone; }
/** @internal */
_findPluginFor(eventName: string): EventManagerPlugin {
var plugins = this._plugins;
for (var i = 0; i < plugins.length; i++) {
var plugin = plugins[i];
if (plugin.supports(eventName)) {
return plugin;
}
}
throw new BaseException(`No event manager plugin found for event ${eventName}`);
}
}
export class EventManagerPlugin {
manager: EventManager;
// That is equivalent to having supporting $event.target
supports(eventName: string): boolean { return false; }
addEventListener(element: HTMLElement, eventName: string, handler: Function) {
throw "not implemented";
}
addGlobalEventListener(element: string, eventName: string, handler: Function): Function {
throw "not implemented";
}
}