refactor(core): move render/dom from core

Currently, core depends on DomRenderer, which depends on the browser.
This means that if you depend on angular2/core, you will always
pull in the browser dom adapter and the browser render, regardless
if you need them or not.

This PR moves the browser dom adapter and the browser renderer out of core.

BREAKING CHANGE

If you import browser adapter or dom renderer directly (not via angular2/core),
you will have to change the import path.
This commit is contained in:
vsavkin
2015-11-17 15:24:36 -08:00
parent 60a2bbb226
commit 2c8fcec432
120 changed files with 1163 additions and 806 deletions
@@ -16,7 +16,7 @@ import {ApplicationRef} from 'angular2/src/core/application_ref';
import {Component, Directive, View, OnDestroy, platform} from 'angular2/core';
import {BROWSER_PROVIDERS, BROWSER_APP_PROVIDERS} from 'angular2/platform/browser';
import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {DOCUMENT} from 'angular2/render';
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
import {PromiseWrapper} from 'angular2/src/facade/async';
import {provide, Inject, Injector} from 'angular2/core';
import {ExceptionHandler} from 'angular2/src/facade/exceptions';
@@ -0,0 +1,74 @@
import {
AsyncTestCompleter,
beforeEach,
ddescribe,
xdescribe,
describe,
dispatchEvent,
expect,
iit,
inject,
beforeEachProviders,
it,
xit,
TestComponentBuilder,
} from 'angular2/testing_internal';
import {global} from 'angular2/src/facade/lang';
import {APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/linker/view_pool';
import {provide, Component, Directive, Injectable, View} from 'angular2/core';
import {inspectNativeElement} from 'angular2/platform/browser';
import {IS_DART} from 'angular2/src/facade/lang';
@Component({selector: 'my-comp'})
@View({directives: []})
@Injectable()
class MyComp {
ctxProp: string;
}
export function main() {
describe('element probe', function() {
beforeEachProviders(() => [provide(APP_VIEW_POOL_CAPACITY, {useValue: 0})]);
it('should return a TestElement from a dom element',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(MyComp, '<div some-dir></div>')
.createAsync(MyComp)
.then((componentFixture) => {
expect(inspectNativeElement(componentFixture.debugElement.nativeElement)
.componentInstance)
.toBeAnInstanceOf(MyComp);
async.done();
});
}));
it('should clean up whent the view is destroyed',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(MyComp, '')
.createAsync(MyComp)
.then((componentFixture) => {
componentFixture.destroy();
expect(inspectNativeElement(componentFixture.debugElement.nativeElement)).toBe(null);
async.done();
});
}));
if (!IS_DART) {
it('should provide a global function to inspect elements',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideTemplate(MyComp, '')
.createAsync(MyComp)
.then((componentFixture) => {
expect(global['ng']['probe'](componentFixture.debugElement.nativeElement)
.componentInstance)
.toBeAnInstanceOf(MyComp);
async.done();
});
}));
}
});
}
@@ -0,0 +1,5 @@
import 'dart:html';
Rectangle createRectangle(left, top, width, height) {
return new Rectangle(left, top, width, height);
}
@@ -0,0 +1,3 @@
export function createRectangle(left, top, width, height) {
return {left, top, width, height};
}
@@ -0,0 +1,56 @@
import {
AsyncTestCompleter,
inject,
ddescribe,
describe,
it,
iit,
xit,
expect,
SpyObject
} from 'angular2/testing_internal';
import {SpyElementRef, SpyDomAdapter} from '../../core/spies';
import {DOM, DomAdapter} from 'angular2/src/core/dom/dom_adapter';
import {Ruler, Rectangle} from 'angular2/src/platform/browser/ruler';
import {createRectangle} from './rectangle_mock';
function assertDimensions(rect: Rectangle, left, right, top, bottom, width, height) {
expect(rect.left).toEqual(left);
expect(rect.right).toEqual(right);
expect(rect.top).toEqual(top);
expect(rect.bottom).toEqual(bottom);
expect(rect.width).toEqual(width);
expect(rect.height).toEqual(height);
}
export function main() {
describe('ruler service', () => {
it('should allow measuring ElementRefs', inject([AsyncTestCompleter], (async) => {
var ruler = new Ruler(SpyObject.stub(
new SpyDomAdapter(), {'getBoundingClientRect': createRectangle(10, 20, 200, 100)}));
var elRef = <any>new SpyElementRef();
ruler.measure(elRef).then((rect) => {
assertDimensions(rect, 10, 210, 20, 120, 200, 100);
async.done();
});
}));
it('should return 0 for all rectangle values while measuring elements in a document fragment',
inject([AsyncTestCompleter], (async) => {
var ruler = new Ruler(DOM);
var elRef = <any>new SpyElementRef();
elRef.prop("nativeElement", DOM.createElement('div'));
ruler.measure(elRef).then((rect) => {
// here we are using an element created in a doc fragment so all the measures will come
// back as 0
assertDimensions(rect, 0, 0, 0, 0, 0, 0);
async.done();
});
}));
});
}
@@ -0,0 +1 @@
<p>hey</p>
@@ -0,0 +1,27 @@
import {ddescribe, describe, it, iit, xit, expect, afterEach} from 'angular2/testing_internal';
import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {Title} from 'angular2/platform/browser';
export function main() {
describe('title service', () => {
var initialTitle = DOM.getTitle();
var titleService = new Title();
afterEach(() => { DOM.setTitle(initialTitle); });
it('should allow reading initial title',
() => { expect(titleService.getTitle()).toEqual(initialTitle); });
it('should set a title on the injected document', () => {
titleService.setTitle('test title');
expect(DOM.getTitle()).toEqual('test title');
expect(titleService.getTitle()).toEqual('test title');
});
it('should reset title to empty string if title not provided', () => {
titleService.setTitle(null);
expect(DOM.getTitle()).toEqual('');
});
});
}
@@ -16,8 +16,8 @@ import {PromiseWrapper} from 'angular2/src/facade/async';
export function main() {
describe('XHRImpl', () => {
var xhr: XHRImpl;
var url200 = '/base/modules/angular2/test/core/services/static_assets/200.html';
var url404 = '/base/modules/angular2/test/core/services/static_assets/404.html';
var url200 = '/base/modules/angular2/test/platform/browser/static_assets/200.html';
var url404 = '/base/modules/angular2/test/platform/browser/static_assets/404.html';
beforeEach(() => { xhr = new XHRImpl(); });