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

refactor(aware_interfaces): extract all aware interfaces. #1532

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/angular.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/animate/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 0 additions & 17 deletions lib/core/annotation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}

18 changes: 0 additions & 18 deletions lib/core/annotation_src.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
63 changes: 63 additions & 0 deletions lib/core/aware_interface.dart
Original file line number Diff line number Diff line change
@@ -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);
}
31 changes: 0 additions & 31 deletions lib/core/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/core_dom/module_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/directive/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions lib/routing/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
8 changes: 4 additions & 4 deletions test/angular_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down