Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 97a87a1

Browse files
committed
Revert "feat(compiler): support ScopeAware for decorators"
This reverts commit 9659dd1. Wrong version of this PR was added in master, correct version is in g3v1x.
1 parent 3983b5f commit 97a87a1

File tree

5 files changed

+12
-24
lines changed

5 files changed

+12
-24
lines changed

lib/core/scope.dart

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,29 +110,28 @@ class ScopeLocals implements Map {
110110
}
111111

112112
/**
113-
* When a [Directive] or the root context class implements [ScopeAware] the scope
114-
* setter will be called to set the [Scope] on this component.
113+
* When a [Component] or the root context class implements [ScopeAware] the scope setter will be
114+
* called to set the [Scope] on this component.
115115
*
116-
* The order of calls is as follows:
117-
* - [Component] instance is created.
118-
* - [Scope] instance is created (taking [Component] instance as evaluation context).
119-
* - if [Component] is [ScopeAware], set scope method is called with scope instance.
116+
* Typically classes implementing [ScopeAware] will declare a `Scope scope` property which will get
117+
* initialized after the [Scope] is available. For this reason the `scope` property will not be
118+
* initialized during the execution of the constructor - it will be immediately after.
120119
*
121-
* [ScopeAware] is guaranteed to be called before [AttachAware] or [DetachAware] methods.
120+
* However, if you need to execute some code as soon as the scope is available you should implement
121+
* a `scope` setter:
122122
*
123-
* Example:
124123
* @Component(...)
125124
* class MyComponent implements ScopeAware {
126125
* Watch watch;
127126
*
128127
* MyComponent(Dependency myDep) {
129-
* // It is an error to add a Scope argument to the ctor and will result in a DI
130-
* // circular dependency error - the scope has a dependency on the component instance.
128+
* // It is an error to add a Scope / RootScope argument to the ctor and will result in a DI
129+
* // circular dependency error - the scope is never accessible in the class constructor
131130
* }
132131
*
133132
* void set scope(Scope scope) {
134133
* // This setter gets called to initialize the scope
135-
* watch = scope.watch("expression", (v, p) => ...);
134+
* watch = scope.rootScope.watch("expression", (v, p) => ...);
136135
* }
137136
* }
138137
*/

lib/core_dom/element_binder.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ class ElementBinder {
226226
_createAttrMappings(directive, scope, ref.mappings, nodeAttrs, tasks);
227227
}
228228

229-
if (directive is ScopeAware) directive.scope = scope;
230-
231229
if (directive is AttachAware) {
232230
var taskId = (tasks != null) ? tasks.registerTask() : 0;
233231
Watch watch;

lib/core_dom/shadow_dom_component_factory.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ class BoundShadowDomComponentFactory implements BoundComponentFactory {
145145
}
146146

147147
var controller = shadowInjector.getByKey(_ref.typeKey);
148+
if (controller is ScopeAware) controller.scope = shadowScope;
148149
BoundComponentFactory._setupOnShadowDomAttach(controller, templateLoader, shadowScope);
149150
shadowScope.context[_component.publishAs] = controller;
150151

lib/core_dom/transcluding_component_factory.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class BoundTranscludingComponentFactory implements BoundComponentFactory {
114114

115115
var controller = childInjector.getByKey(_ref.typeKey);
116116
shadowScope.context[component.publishAs] = controller;
117+
if (controller is ScopeAware) controller.scope = shadowScope;
117118
BoundComponentFactory._setupOnShadowDomAttach(controller, templateLoader, shadowScope);
118119
return controller;
119120
};

test/core_dom/compiler_spec.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,14 +1072,6 @@ void main() {
10721072

10731073
expect(log.result()).toEqual('Scope set');
10741074
}));
1075-
1076-
it('should call scope setter on ScopeAware decorators', async((TestBed _, Logger log) {
1077-
var element = _.compile('<div scope-aware-dec></div>');
1078-
1079-
_.rootScope.apply();
1080-
1081-
expect(log.result()).toEqual('Scope set');
1082-
}));
10831075
});
10841076

10851077

@@ -1555,9 +1547,6 @@ class SameNameDecorator {
15551547
@Component(
15561548
selector: 'scope-aware-cmp'
15571549
)
1558-
@Decorator(
1559-
selector: '[scope-aware-dec]'
1560-
)
15611550
class ScopeAwareComponent implements ScopeAware {
15621551
Logger log;
15631552
ScopeAwareComponent(this.log) {}

0 commit comments

Comments
 (0)