diff --git a/lib/angular.dart b/lib/angular.dart index 8674068db..6dc1a954c 100644 --- a/lib/angular.dart +++ b/lib/angular.dart @@ -5,6 +5,7 @@ export 'package:angular/application.dart'; export 'package:angular/core/module.dart'; export 'package:angular/directive/module.dart'; export 'package:angular/core/annotation.dart'; +export 'package:angular/core/aware_interface.dart'; export 'package:angular/tracing.dart'; export 'package:angular/introspection.dart' hide elementExpando, publishToJavaScript; diff --git a/lib/animate/module.dart b/lib/animate/module.dart index f2135a76f..7be9020e1 100644 --- a/lib/animate/module.dart +++ b/lib/animate/module.dart @@ -102,6 +102,7 @@ import 'dart:async'; import 'dart:html' as dom; import 'package:angular/core/annotation.dart'; +import 'package:angular/core/aware_interface.dart'; import 'package:angular/core/module_internal.dart'; import 'package:angular/core_dom/module_internal.dart'; import 'package:angular/core_dom/dom_util.dart' as util; diff --git a/lib/core/annotation.dart b/lib/core/annotation.dart index b3361d8e3..40291f9b5 100644 --- a/lib/core/annotation.dart +++ b/lib/core/annotation.dart @@ -3,13 +3,7 @@ */ library angular.core.annotation; -import "dart:html" show ShadowRoot; - export "package:angular/core/annotation_src.dart" show - AttachAware, - DetachAware, - ShadowRootAware, - Formatter, DirectiveBinder, DirectiveBinderFn, @@ -26,14 +20,3 @@ export "package:angular/core/annotation_src.dart" show NgOneWayOneTime, NgTwoWay; - -/** - * Implementing components [onShadowRoot] method will be called when - * the template for the component has been loaded and inserted into Shadow DOM. - * It is guaranteed that when [onShadowRoot] is invoked, that shadow DOM - * has been loaded and is ready. - */ -abstract class ShadowRootAware { - void onShadowRoot(ShadowRoot shadowRoot); -} - diff --git a/lib/core/annotation_src.dart b/lib/core/annotation_src.dart index ff864cf47..992044feb 100644 --- a/lib/core/annotation_src.dart +++ b/lib/core/annotation_src.dart @@ -469,24 +469,6 @@ class NgCallback extends DirectiveAnnotation { const NgCallback(String attrName) : super(attrName); } -/** - * A directives or components may chose to implements [AttachAware].[attach] method. - * If implemented the method will be called when the next scope digest occurs after - * component instantiation. It is guaranteed that when [attach] is invoked, that all - * attribute mappings have already been processed. - */ -abstract class AttachAware { - void attach(); -} - -/** - * A directives or components may chose to implements [DetachAware].[detach] method. - * If implemented the method will be called when the next associated scope is destroyed. - */ -abstract class DetachAware { - void detach(); -} - /** * Use the @[Formatter] class annotation to identify a class as a formatter. * diff --git a/lib/core/aware_interface.dart b/lib/core/aware_interface.dart new file mode 100644 index 000000000..5a7c320e6 --- /dev/null +++ b/lib/core/aware_interface.dart @@ -0,0 +1,63 @@ +library angular.core.aware_interface; + +import "dart:html" show ShadowRoot; + +/** + * Implementing components [onShadowRoot] method will be called when + * the template for the component has been loaded and inserted into Shadow DOM. + * It is guaranteed that when [onShadowRoot] is invoked, that shadow DOM + * has been loaded and is ready. + */ +abstract class ShadowRootAware { + void onShadowRoot(ShadowRoot shadowRoot); +} + +/** + * A directives or components may chose to implements [AttachAware].[attach] method. + * If implemented the method will be called when the next scope digest occurs after + * component instantiation. It is guaranteed that when [attach] is invoked, that all + * attribute mappings have already been processed. + */ +abstract class AttachAware { + void attach(); +} + +/** + * A directives or components may chose to implements [DetachAware].[detach] method. + * If implemented the method will be called when the next associated scope is destroyed. + */ +abstract class DetachAware { + void detach(); +} + + +/** + * When a [Directive] or the root context class implements [ScopeAware] the scope + * setter will be called to set the [Scope] on this component. + * + * The order of calls is as follows: + * - [Component] instance is created. + * - [Scope] instance is created (taking [Component] instance as evaluation context). + * - if [Component] is [ScopeAware], set scope method is called with scope instance. + * + * [ScopeAware] is guaranteed to be called before [AttachAware] or [DetachAware] methods. + * + * Example: + * @Component(...) + * class MyComponent implements ScopeAware { + * Watch watch; + * + * MyComponent(Dependency myDep) { + * // It is an error to add a Scope argument to the ctor and will result in a DI + * // circular dependency error - the scope has a dependency on the component instance. + * } + * + * void set scope(Scope scope) { + * // This setter gets called to initialize the scope + * watch = scope.watch("expression", (v, p) => ...); + * } + * } + */ +abstract class ScopeAware { + void set scope(Scope scope); +} \ No newline at end of file diff --git a/lib/core/scope.dart b/lib/core/scope.dart index f2b3d521d..fcc1f06ed 100644 --- a/lib/core/scope.dart +++ b/lib/core/scope.dart @@ -69,37 +69,6 @@ class ScopeDigestTTL { ScopeDigestTTL.value(this.ttl); } -/** - * When a [Directive] or the root context class implements [ScopeAware] the scope - * setter will be called to set the [Scope] on this component. - * - * The order of calls is as follows: - * - [Component] instance is created. - * - [Scope] instance is created (taking [Component] instance as evaluation context). - * - if [Component] is [ScopeAware], set scope method is called with scope instance. - * - * [ScopeAware] is guaranteed to be called before [AttachAware] or [DetachAware] methods. - * - * Example: - * @Component(...) - * class MyComponent implements ScopeAware { - * Watch watch; - * - * MyComponent(Dependency myDep) { - * // It is an error to add a Scope argument to the ctor and will result in a DI - * // circular dependency error - the scope has a dependency on the component instance. - * } - * - * void set scope(Scope scope) { - * // This setter gets called to initialize the scope - * watch = scope.watch("expression", (v, p) => ...); - * } - * } - */ -abstract class ScopeAware { - void set scope(Scope scope); -} - /** * [Scope] represents a collection of [watch]es [observer]s, and a [context] for the watchers, * observers and [eval]uations. Scopes structure loosely mimics the DOM structure. Scopes and diff --git a/lib/core_dom/module_internal.dart b/lib/core_dom/module_internal.dart index 47f8a4a20..cc95f5f73 100644 --- a/lib/core_dom/module_internal.dart +++ b/lib/core_dom/module_internal.dart @@ -15,6 +15,7 @@ import 'package:angular/utils.dart'; import 'package:angular/cache/module.dart'; import 'package:angular/core/annotation.dart'; +import 'package:angular/core/aware_interface.dart'; import 'package:angular/core/module_internal.dart'; import 'package:angular/core/parser/parser.dart'; import 'package:angular/core_dom/dom_util.dart' as util; diff --git a/lib/directive/module.dart b/lib/directive/module.dart index 69a29d7a9..faaed999f 100644 --- a/lib/directive/module.dart +++ b/lib/directive/module.dart @@ -22,6 +22,7 @@ import 'dart:html' as dom; import 'dart:async' as async; import 'package:intl/intl.dart'; import 'package:angular/core/annotation.dart'; +import 'package:angular/core/aware_interface.dart'; import 'package:angular/core/module_internal.dart'; import 'package:angular/core/parser/parser.dart'; import 'package:angular/core_dom/module_internal.dart'; diff --git a/lib/routing/module.dart b/lib/routing/module.dart index c796f5b4e..d28a1f980 100644 --- a/lib/routing/module.dart +++ b/lib/routing/module.dart @@ -127,6 +127,7 @@ import 'dart:html'; import 'package:di/di.dart'; import 'package:di/annotations.dart'; +import 'package:angular/core/aware_interface.dart'; import 'package:angular/application.dart'; import 'package:angular/core/annotation_src.dart'; import 'package:angular/core/module_internal.dart'; diff --git a/test/angular_spec.dart b/test/angular_spec.dart index 7e88a19c1..0c7d5d9ee 100644 --- a/test/angular_spec.dart +++ b/test/angular_spec.dart @@ -84,11 +84,12 @@ main() { "angular.app.Application", "angular.cache.CacheRegister", "angular.cache.CacheRegisterStats", - "angular.core.annotation.ShadowRootAware", - "angular.core.annotation_src.AttachAware", + "angular.core.aware_interface.AttachAware", + "angular.core.aware_interface.DetachAware", + "angular.core.aware_interface.ScopeAware", + "angular.core.aware_interface.ShadowRootAware", "angular.core.annotation_src.Component", "angular.core.annotation_src.Decorator", - "angular.core.annotation_src.DetachAware", "angular.core.annotation_src.Directive", "angular.core.annotation_src.DirectiveAnnotation", "angular.core.annotation_src.DirectiveBinder", @@ -142,7 +143,6 @@ main() { "angular.core_internal.Interpolate", "angular.core_internal.RootScope", "angular.core_internal.Scope", - "angular.core_internal.ScopeAware", "angular.core_internal.ScopeDigestTTL", "angular.core_internal.ScopeEvent", "angular.core_internal.ScopeStats",