1
1
library angular.core.annotation_src;
2
2
3
- import "package:di/di.dart" show Injector, Visibility;
3
+ import "package:di/di.dart" show Injector, Visibility, Factory ;
4
4
5
5
abstract class DirectiveBinder {
6
- bind (key, {Function toFactory, inject,
7
- Visibility visibility: Directive .CHILDREN_VISIBILITY });
6
+ bind (key, {Function toFactory, inject, Visibility visibility: Visibility .CHILDREN });
8
7
}
9
8
10
9
typedef void DirectiveBinderFn (DirectiveBinder module);
11
10
12
11
RegExp _ATTR_NAME = new RegExp (r'\[([^\]]+)\]$' );
13
12
14
- const String SHADOW_DOM_INJECTOR_NAME = 'SHADOW_INJECTOR' ;
15
-
16
- skipShadow (Injector injector)
17
- => injector.name == SHADOW_DOM_INJECTOR_NAME ? injector.parent : injector;
18
-
19
- localVisibility (Injector requesting, Injector defining)
20
- => identical (skipShadow (requesting), defining);
21
-
22
- directChildrenVisibility (Injector requesting, Injector defining) {
23
- requesting = skipShadow (requesting);
24
- return identical (requesting.parent, defining) || localVisibility (requesting, defining);
25
- }
26
-
27
13
Directive cloneWithNewMap (Directive annotation, map)
28
14
=> annotation._cloneWithNewMap (map);
29
15
30
16
String mappingSpec (DirectiveAnnotation annotation) => annotation._mappingSpec;
31
17
18
+ class Visibility {
19
+ static const LOCAL = const Visibility ._('LOCAL' );
20
+ static const CHILDREN = const Visibility ._('CHILDREN' );
21
+ static const DIRECT_CHILD = const Visibility ._('DIRECT_CHILD' );
32
22
33
- /**
34
- * An annotation when applied to a class indicates that the class (service) will
35
- * be instantiated by di injector. This annotation is also used to designate which
36
- * classes need to have a static factory generated when using static angular, and
37
- * therefore is required on any injectable class.
38
- */
39
- class Injectable {
40
- const Injectable ();
23
+ final String name;
24
+ const Visibility ._(this .name);
25
+ toString () => 'Visibility: $name ' ;
41
26
}
42
27
43
28
/**
@@ -46,16 +31,19 @@ class Injectable {
46
31
abstract class Directive {
47
32
48
33
/// The directive can only be injected to other directives on the same element.
49
- static const Visibility LOCAL_VISIBILITY = localVisibility;
34
+ @deprecated // ('Use Visibility.LOCAL instead')
35
+ static const Visibility LOCAL_VISIBILITY = Visibility .LOCAL ;
50
36
51
37
/// The directive can be injected to other directives on the same or child elements.
52
- static const Visibility CHILDREN_VISIBILITY = null ;
38
+ @deprecated // ('Use Visibility.CHILDREN instead')
39
+ static const Visibility CHILDREN_VISIBILITY = Visibility .CHILDREN ;
53
40
54
41
/**
55
42
* The directive on this element can only be injected to other directives
56
43
* declared on elements which are direct children of the current element.
57
44
*/
58
- static const Visibility DIRECT_CHILDREN_VISIBILITY = directChildrenVisibility;
45
+ @deprecated // ('Use Visibility.DIRECT_CHILD instead')
46
+ static const Visibility DIRECT_CHILDREN_VISIBILITY = Visibility .DIRECT_CHILD ;
59
47
60
48
/**
61
49
* CSS selector which will trigger this component/directive.
@@ -129,8 +117,8 @@ abstract class Directive {
129
117
* selector: '[foo]',
130
118
* module: Foo.moduleFactory)
131
119
* class Foo {
132
- * static moduleFactory() => new Module()
133
- * . .bind(SomeTypeA, visibility: Directive.LOCAL_VISIBILITY);
120
+ * static moduleFactory(DirectiveBinder binder ) =>
121
+ * binder .bind(SomeTypeA, visibility: Directive.LOCAL_VISIBILITY);
134
122
* }
135
123
*
136
124
* When specifying types, factories or values in the module, notice that
@@ -139,7 +127,7 @@ abstract class Directive {
139
127
* * [Directive.CHILDREN_VISIBILITY]
140
128
* * [Directive.DIRECT_CHILDREN_VISIBILITY]
141
129
*/
142
- final Function module;
130
+ final DirectiveBinderFn module;
143
131
144
132
/**
145
133
* Use map to define the mapping of DOM attributes to fields.
@@ -222,19 +210,15 @@ abstract class Directive {
222
210
223
211
const Directive ({
224
212
this .selector,
225
- this .children: Directive . COMPILE_CHILDREN ,
226
- this .visibility: Directive . LOCAL_VISIBILITY ,
213
+ this .children,
214
+ this .visibility,
227
215
this .module,
228
216
this .map: const {},
229
217
this .exportExpressions: const [],
230
218
this .exportExpressionAttrs: const []
231
219
});
232
220
233
221
toString () => selector;
234
- get hashCode => selector.hashCode;
235
- operator == (other) =>
236
- other is Directive && selector == other.selector;
237
-
238
222
Directive _cloneWithNewMap (newMap);
239
223
}
240
224
@@ -335,7 +319,7 @@ class Component extends Directive {
335
319
applyAuthorStyles,
336
320
resetStyleInheritance,
337
321
this .publishAs,
338
- module,
322
+ DirectiveBinderFn module,
339
323
map,
340
324
selector,
341
325
visibility,
@@ -393,7 +377,7 @@ class Decorator extends Directive {
393
377
const Decorator ({children: Directive .COMPILE_CHILDREN ,
394
378
map,
395
379
selector,
396
- module,
380
+ DirectiveBinderFn module,
397
381
visibility,
398
382
exportExpressions,
399
383
exportExpressionAttrs})
@@ -446,7 +430,7 @@ class Controller extends Decorator {
446
430
children: Directive .COMPILE_CHILDREN ,
447
431
this .publishAs,
448
432
map,
449
- module,
433
+ DirectiveBinderFn module,
450
434
selector,
451
435
visibility,
452
436
exportExpressions,
@@ -595,8 +579,5 @@ class Formatter {
595
579
596
580
const Formatter ({this .name});
597
581
598
- int get hashCode => name.hashCode;
599
- bool operator == (other) => name == other.name;
600
-
601
582
toString () => 'Formatter: $name ' ;
602
583
}
0 commit comments