feat(bootstrap): add platform and app initializers

Often some init logic needs to run when a platform or an application is boostrapped.
For example, boostraping a platform requires initializing the dom adapter.
Now, it can be done as follows:

new Provider(PLATFORM_INITIALIZER, {useValue: initDomAdapter, multi: true}),

All platform initializers will be run after the platform injector has been created.

Similarly, all application initializers will be run after the app injector has been
created.

Closes #5355
This commit is contained in:
vsavkin
2015-11-18 09:18:37 -08:00
committed by Victor Savkin
parent 3fa287aae2
commit 3c43a8c549
9 changed files with 80 additions and 19 deletions

View File

@ -11,13 +11,13 @@ import {
reflector,
APPLICATION_COMMON_PROVIDERS,
PLATFORM_COMMON_PROVIDERS,
EVENT_MANAGER_PLUGINS
EVENT_MANAGER_PLUGINS,
PLATFORM_INITIALIZER
} from "angular2/core";
import {COMMON_DIRECTIVES, COMMON_PIPES, FORM_PROVIDERS} from "angular2/common";
import {Renderer} from 'angular2/render';
import {Testability} from 'angular2/src/core/testability/testability';
// TODO change these imports once dom_adapter is moved out of core
import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {DomEventsPlugin} from 'angular2/src/platform/dom/events/dom_events';
import {KeyEventsPlugin} from 'angular2/src/platform/dom/events/key_events';
@ -42,8 +42,10 @@ export {
export {By} from 'angular2/src/platform/browser/debug/by';
export {BrowserDomAdapter} from './browser/browser_adapter';
export const BROWSER_PROVIDERS: Array<any /*Type | Provider | any[]*/> =
CONST_EXPR([PLATFORM_COMMON_PROVIDERS]);
export const BROWSER_PROVIDERS: Array<any /*Type | Provider | any[]*/> = CONST_EXPR([
PLATFORM_COMMON_PROVIDERS,
new Provider(PLATFORM_INITIALIZER, {useValue: initDomAdapter, multi: true}),
]);
function _exceptionHandler(): ExceptionHandler {
return new ExceptionHandler(DOM, false);
@ -73,7 +75,6 @@ export const BROWSER_APP_COMMON_PROVIDERS: Array<any /*Type | Provider | any[]*/
]);
export function initDomAdapter() {
// TODO: refactor into a generic init function
BrowserDomAdapter.makeCurrent();
wtfInit();
BrowserGetTestability.init();