Skip to content

Commit 16e3d7e

Browse files
committed
refactor(shadow_dom): remove ShadowDomStrategy in favor of @View(encapsulation)
BREAKING CHANGES: - `ShadowDomStrategy` was removed. To specify the encapsulation of a component use `@View(encapsulation: ViewEncapsulation.NONE | ViewEncapsulation.EMULATED | ViewEncapsulation.NATIVE)` - The default encapsulation strategy is now `ViewEncapsulation.EMULATED` if a component contains styles and `ViewEncapsulation.NONE` if it does not. Before this was always `NONE`. - `ViewLoader` now returns the template as a string and the styles as a separate array
1 parent e40ff36 commit 16e3d7e

File tree

77 files changed

+1229
-891
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1229
-891
lines changed

modules/angular2/annotations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export {
1515
LifecycleEvent
1616
} from './src/core/annotations/annotations';
1717

18-
export {ViewAnnotation} from 'angular2/src/core/annotations/view';
18+
export {ViewAnnotation, ViewEncapsulation} from 'angular2/src/core/annotations/view';
1919
export {QueryAnnotation, AttributeAnnotation} from 'angular2/src/core/annotations/di';
2020

2121
export {

modules/angular2/render.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ export {
1414
RenderViewWithFragments,
1515
DomRenderer,
1616
DOCUMENT_TOKEN,
17+
APP_ID_TOKEN,
1718
DOM_REFLECT_PROPERTIES_AS_ATTRIBUTES
1819
} from './src/render/render';

modules/angular2/src/core/annotations/decorators.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Class
1010
} from '../../util/decorators';
1111
import {Type} from 'angular2/src/facade/lang';
12+
import {ViewEncapsulation} from 'angular2/src/render/api';
1213

1314
/**
1415
* Interface for the {@link Directive} decorator function.
@@ -226,15 +227,15 @@ export interface ViewFactory {
226227
templateUrl?: string,
227228
template?: string,
228229
directives?: List<Type | any | List<any>>,
229-
renderer?: string,
230+
encapsulation?: ViewEncapsulation,
230231
styles?: List<string>,
231232
styleUrls?: List<string>,
232233
}): ViewDecorator;
233234
new (obj: {
234235
templateUrl?: string,
235236
template?: string,
236237
directives?: List<Type | any | List<any>>,
237-
renderer?: string,
238+
encapsulation?: ViewEncapsulation,
238239
styles?: List<string>,
239240
styleUrls?: List<string>,
240241
}): ViewAnnotation;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export {View as ViewAnnotation} from '../annotations_impl/view';
1+
export {View as ViewAnnotation, ViewEncapsulation} from '../annotations_impl/view';

modules/angular2/src/core/annotations_impl/view.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import {ABSTRACT, CONST, Type} from 'angular2/src/facade/lang';
2+
import {ViewEncapsulation} from 'angular2/src/render/api';
3+
4+
export {ViewEncapsulation} from 'angular2/src/render/api';
25

36
/**
47
* Declares the available HTML templates for an application.
@@ -85,17 +88,17 @@ export class View {
8588
directives: List<Type | any | List<any>>;
8689

8790
/**
88-
* Specify a custom renderer for this View.
89-
* If this is set, neither `template`, `templateUrl`, `styles`, `styleUrls` nor `directives` are
90-
* used.
91+
* Specify how the template and the styles should be encapsulated.
92+
* The default is {@link ViewEncapsulation.EMULATED} if the view has styles,
93+
* otherwise {@link ViewEncapsulation.NONE}.
9194
*/
92-
renderer: string;
95+
encapsulation: ViewEncapsulation;
9396

94-
constructor({templateUrl, template, directives, renderer, styles, styleUrls}: {
97+
constructor({templateUrl, template, directives, encapsulation, styles, styleUrls}: {
9598
templateUrl?: string,
9699
template?: string,
97100
directives?: List<Type | any | List<any>>,
98-
renderer?: string,
101+
encapsulation?: ViewEncapsulation,
99102
styles?: List<string>,
100103
styleUrls?: List<string>,
101104
} = {}) {
@@ -104,6 +107,6 @@ export class View {
104107
this.styleUrls = styleUrls;
105108
this.styles = styles;
106109
this.directives = directives;
107-
this.renderer = renderer;
110+
this.encapsulation = encapsulation;
108111
}
109112
}

modules/angular2/src/core/application_common.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ import {List, ListWrapper} from 'angular2/src/facade/collection';
3434
import {Promise, PromiseWrapper, PromiseCompleter} from 'angular2/src/facade/async';
3535
import {NgZone} from 'angular2/src/core/zone/ng_zone';
3636
import {LifeCycle} from 'angular2/src/core/life_cycle/life_cycle';
37-
import {ShadowDomStrategy} from 'angular2/src/render/dom/shadow_dom/shadow_dom_strategy';
38-
import {
39-
EmulatedUnscopedShadowDomStrategy
40-
} from 'angular2/src/render/dom/shadow_dom/emulated_unscoped_shadow_dom_strategy';
4137
import {XHR} from 'angular2/src/render/xhr';
4238
import {XHRImpl} from 'angular2/src/render/xhr_impl';
4339
import {EventManager, DomEventsPlugin} from 'angular2/src/render/dom/events/event_manager';
@@ -61,9 +57,14 @@ import {Renderer, RenderCompiler} from 'angular2/src/render/api';
6157
import {
6258
DomRenderer,
6359
DOCUMENT_TOKEN,
64-
DOM_REFLECT_PROPERTIES_AS_ATTRIBUTES
65-
} from 'angular2/src/render/dom/dom_renderer';
66-
import {DefaultDomCompiler} from 'angular2/src/render/dom/compiler/compiler';
60+
DOM_REFLECT_PROPERTIES_AS_ATTRIBUTES,
61+
DefaultDomCompiler,
62+
APP_ID_RANDOM_BINDING
63+
} from 'angular2/src/render/render';
64+
import {
65+
SharedStylesHost,
66+
DomSharedStylesHost
67+
} from 'angular2/src/render/dom/view/shared_styles_host';
6768
import {internalView} from 'angular2/src/core/compiler/view_ref';
6869
import {appComponentRefPromiseToken, appComponentTypeToken} from './application_tokens';
6970

@@ -108,12 +109,13 @@ function _injectorBindings(appComponentType): List<Type | Binding | List<any>> {
108109
return new EventManager(plugins, ngZone);
109110
},
110111
[NgZone]),
111-
bind(ShadowDomStrategy)
112-
.toFactory((doc) => new EmulatedUnscopedShadowDomStrategy(doc.head), [DOCUMENT_TOKEN]),
113112
DomRenderer,
114-
DefaultDomCompiler,
115113
bind(Renderer).toAlias(DomRenderer),
114+
APP_ID_RANDOM_BINDING,
115+
DefaultDomCompiler,
116116
bind(RenderCompiler).toAlias(DefaultDomCompiler),
117+
DomSharedStylesHost,
118+
bind(SharedStylesHost).toAlias(DomSharedStylesHost),
117119
ProtoViewFactory,
118120
AppViewPool,
119121
bind(APP_VIEW_POOL_CAPACITY).toValue(10000),

modules/angular2/src/core/compiler/compiler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ export class Compiler {
307307
templateAbsUrl: templateAbsUrl, template: view.template,
308308
styleAbsUrls: styleAbsUrls,
309309
styles: view.styles,
310-
directives: ListWrapper.map(directives, directiveBinding => directiveBinding.metadata)
310+
directives: ListWrapper.map(directives, directiveBinding => directiveBinding.metadata),
311+
encapsulation: view.encapsulation
311312
});
312313
}
313314

modules/angular2/src/dom/html_adapter.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,10 @@ class Html5LibDomAdapter implements DomAdapter {
317317
throw 'not implemented';
318318
}
319319
bool supportsDOMEvents() {
320-
throw 'not implemented';
320+
return false;
321321
}
322322
bool supportsNativeShadowDOM() {
323-
throw 'not implemented';
323+
return false;
324324
}
325325
getHistory() {
326326
throw 'not implemented';

modules/angular2/src/facade/collection.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,7 @@ void iterateListLike(iter, fn(item)) {
212212
class SetWrapper {
213213
static Set createFromList(List l) => new Set.from(l);
214214
static bool has(Set s, key) => s.contains(key);
215+
static void delete(Set m, k) {
216+
m.remove(k);
217+
}
215218
}

modules/angular2/src/facade/collection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,5 @@ var createSetFromList: {(lst: List<any>): Set<any>} = (function() {
290290
export class SetWrapper {
291291
static createFromList<T>(lst: List<T>): Set<T> { return createSetFromList(lst); }
292292
static has<T>(s: Set<T>, key: T): boolean { return s.has(key); }
293+
static delete<K>(m: Set<K>, k: K) { m.delete(k); }
293294
}

0 commit comments

Comments
 (0)