| OLD | NEW |
| 1 library angular.core.annotation_src; | 1 part of angular.core; |
| 2 | 2 |
| 3 import "package:di/di.dart" show Injector, Visibility; | 3 abstract class NgAnnotation { |
| 4 | |
| 5 RegExp _ATTR_NAME = new RegExp(r'\[([^\]]+)\]$'); | |
| 6 | |
| 7 const String SHADOW_DOM_INJECTOR_NAME = 'SHADOW_INJECTOR'; | |
| 8 | |
| 9 skipShadow(Injector injector) | |
| 10 => injector.name == SHADOW_DOM_INJECTOR_NAME ? injector.parent : injector; | |
| 11 | |
| 12 localVisibility (Injector requesting, Injector defining) | |
| 13 => identical(skipShadow(requesting), defining); | |
| 14 | |
| 15 directChildrenVisibility(Injector requesting, Injector defining) { | |
| 16 requesting = skipShadow(requesting); | |
| 17 return identical(requesting.parent, defining) || localVisibility(requesting, d
efining); | |
| 18 } | |
| 19 | |
| 20 Directive cloneWithNewMap(Directive annotation, map) | |
| 21 => annotation._cloneWithNewMap(map); | |
| 22 | |
| 23 String mappingSpec(DirectiveAnnotation annotation) => annotation._mappingSpec; | |
| 24 | |
| 25 | |
| 26 /** | |
| 27 * An annotation when applied to a class indicates that the class (service) will | |
| 28 * be instantiated by di injector. This annotation is also used to designate whi
ch | |
| 29 * classes need to have a static factory generated when using static angular, an
d | |
| 30 * therefore is required on any injectable class. | |
| 31 */ | |
| 32 class Injectable { | |
| 33 const Injectable(); | |
| 34 } | |
| 35 | |
| 36 /** | |
| 37 * Abstract supper class of [Controller], [Component], and [Decorator]. | |
| 38 */ | |
| 39 abstract class Directive { | |
| 40 | |
| 41 /// The directive can only be injected to other directives on the same element
. | |
| 42 static const Visibility LOCAL_VISIBILITY = localVisibility; | |
| 43 | |
| 44 /// The directive can be injected to other directives on the same or child ele
ments. | |
| 45 static const Visibility CHILDREN_VISIBILITY = null; | |
| 46 | |
| 47 /** | |
| 48 * The directive on this element can only be injected to other directives | |
| 49 * declared on elements which are direct children of the current element. | |
| 50 */ | |
| 51 static const Visibility DIRECT_CHILDREN_VISIBILITY = directChildrenVisibility; | |
| 52 | |
| 53 /** | 4 /** |
| 54 * CSS selector which will trigger this component/directive. | 5 * CSS selector which will trigger this component/directive. |
| 55 * CSS Selectors are limited to a single element and can contain: | 6 * CSS Selectors are limited to a single element and can contain: |
| 56 * | 7 * |
| 57 * * `element-name` limit to a given element name. | 8 * * `element-name` limit to a given element name. |
| 58 * * `.class` limit to an element with a given class. | 9 * * `.class` limit to an element with a given class. |
| 59 * * `[attribute]` limit to an element with a given attribute name. | 10 * * `[attribute]` limit to an element with a given attribute name. |
| 60 * * `[attribute=value]` limit to an element with a given attribute and value. | 11 * * `[attribute=value]` limit to an element with a given attribute and value. |
| 61 * * `:contains(/abc/)` limit to an element which contains the given text. | |
| 62 * | 12 * |
| 63 * | 13 * |
| 64 * Example: `input[type=checkbox][ng-model]` | 14 * Example: `input[type=checkbox][ng-model]` |
| 65 */ | 15 */ |
| 66 final String selector; | 16 final String selector; |
| 67 | 17 |
| 68 /** | 18 /** |
| 69 * Specifies the compiler action to be taken on the child nodes of the | 19 * Specifies the compiler action to be taken on the child nodes of the |
| 70 * element which this currently being compiled. The values are: | 20 * element which this currently being compiled. The values are: |
| 71 * | 21 * |
| 72 * * [COMPILE_CHILDREN] (*default*) | 22 * * [COMPILE_CHILDREN] (*default*) |
| 73 * * [TRANSCLUDE_CHILDREN] | 23 * * [TRANSCLUDE_CHILDREN] |
| 74 * * [IGNORE_CHILDREN] | 24 * * [IGNORE_CHILDREN] |
| 75 */ | 25 */ |
| 76 @deprecated | |
| 77 final String children; | 26 final String children; |
| 78 | 27 |
| 79 /** | 28 /** |
| 80 * Compile the child nodes of the element. This is the default. | 29 * Compile the child nodes of the element. This is the default. |
| 81 */ | 30 */ |
| 82 @deprecated | |
| 83 static const String COMPILE_CHILDREN = 'compile'; | 31 static const String COMPILE_CHILDREN = 'compile'; |
| 84 /** | 32 /** |
| 85 * Compile the child nodes for transclusion and makes available | 33 * Compile the child nodes for transclusion and makes available |
| 86 * [BoundViewFactory], [ViewFactory] and [ViewPort] for injection. | 34 * [BoundBlockFactory], [BlockFactory] and [BlockHole] for injection. |
| 87 */ | 35 */ |
| 88 @deprecated | |
| 89 static const String TRANSCLUDE_CHILDREN = 'transclude'; | 36 static const String TRANSCLUDE_CHILDREN = 'transclude'; |
| 90 /** | 37 /** |
| 91 * Do not compile/visit the child nodes. Angular markup on descendant nodes | 38 * Do not compile/visit the child nodes. Angular markup on descendant nodes |
| 92 * will not be processed. | 39 * will not be processed. |
| 93 */ | 40 */ |
| 94 @deprecated | |
| 95 static const String IGNORE_CHILDREN = 'ignore'; | 41 static const String IGNORE_CHILDREN = 'ignore'; |
| 96 | 42 |
| 97 /** | 43 /** |
| 98 * A directive/component controller class can be injected into other | 44 * A directive/component controller class can be injected into other |
| 99 * directives/components. This attribute controls whether the | 45 * directives/components. This attribute controls whether the |
| 100 * controller is available to others. | 46 * controller is available to others. |
| 101 * | 47 * |
| 102 * * `local` [Directive.LOCAL_VISIBILITY] - the controller can be injected | 48 * * `local` [NgDirective.LOCAL_VISIBILITY] - the controller can be injected |
| 103 * into other directives / components on the same DOM element. | 49 * into other directives / components on the same DOM element. |
| 104 * * `children` [Directive.CHILDREN_VISIBILITY] - the controller can be | 50 * * `children` [NgDirective.CHILDREN_VISIBILITY] - the controller can be |
| 105 * injected into other directives / components on the same or child DOM | 51 * injected into other directives / components on the same or child DOM |
| 106 * elements. | 52 * elements. |
| 107 * * `direct_children` [Directive.DIRECT_CHILDREN_VISIBILITY] - the | 53 * * `direct_children` [NgDirective.DIRECT_CHILDREN_VISIBILITY] - the |
| 108 * controller can be injected into other directives / components on the | 54 * controller can be injected into other directives / components on the |
| 109 * direct children of the current DOM element. | 55 * direct children of the current DOM element. |
| 110 */ | 56 */ |
| 111 final Visibility visibility; | 57 final String visibility; |
| 112 | 58 final List<Type> publishTypes; |
| 113 /** | |
| 114 * A directive/component class can publish types by using a factory | |
| 115 * function to generate a module. The module is then installed into | |
| 116 * the injector at that element. Any types declared in the module then | |
| 117 * become available for injection. | |
| 118 * | |
| 119 * Example: | |
| 120 * | |
| 121 * @Decorator( | |
| 122 * selector: '[foo]', | |
| 123 * module: Foo.moduleFactory) | |
| 124 * class Foo { | |
| 125 * static moduleFactory() => new Module() | |
| 126 * ..type(SomeTypeA, visibility: Directive.LOCAL_VISIBILITY); | |
| 127 * } | |
| 128 * | |
| 129 * When specifying types, factories or values in the module, notice that | |
| 130 * `Visibility` maps to: | |
| 131 * * [Directive.LOCAL_VISIBILITY] | |
| 132 * * [Directive.CHILDREN_VISIBILITY] | |
| 133 * * [Directive.DIRECT_CHILDREN_VISIBILITY] | |
| 134 */ | |
| 135 final Function module; | |
| 136 | 59 |
| 137 /** | 60 /** |
| 138 * Use map to define the mapping of DOM attributes to fields. | 61 * Use map to define the mapping of DOM attributes to fields. |
| 139 * The map's key is the DOM attribute name (DOM attribute is in dash-case). | 62 * The map's key is the DOM attribute name (DOM attribute is in dash-case). |
| 140 * The Map's value consists of a mode prefix followed by an expression. | 63 * The Map's value consists of a mode prefix followed by an expression. |
| 141 * The destination expression will be evaluated against the instance of the | 64 * The destination expression will be evaluated against the instance of the |
| 142 * directive / component class. | 65 * directive / component class. |
| 143 * | 66 * |
| 144 * * `@` - Map the DOM attribute string. The attribute string will be taken | 67 * * `@` - Map the DOM attribute string. The attribute string will be taken |
| 145 * literally or interpolated if it contains binding {{}} systax and assigned | 68 * literally or interpolated if it contains binding {{}} systax and assigned |
| (...skipping 15 matching lines...) Expand all Loading... |
| 161 * function into the field. This allows the component to control | 84 * function into the field. This allows the component to control |
| 162 * the invocation of the closure. This is useful for passing | 85 * the invocation of the closure. This is useful for passing |
| 163 * expressions into controllers which act like callbacks. (cost: 0 watches) | 86 * expressions into controllers which act like callbacks. (cost: 0 watches) |
| 164 * | 87 * |
| 165 * Example: | 88 * Example: |
| 166 * | 89 * |
| 167 * <my-component title="Hello {{username}}" | 90 * <my-component title="Hello {{username}}" |
| 168 * selection="selectedItem" | 91 * selection="selectedItem" |
| 169 * on-selection-change="doSomething()"> | 92 * on-selection-change="doSomething()"> |
| 170 * | 93 * |
| 171 * @Component( | 94 * @NgComponent( |
| 172 * selector: 'my-component' | 95 * selector: 'my-component' |
| 173 * map: const { | 96 * map: const { |
| 174 * 'title': '@title', | 97 * 'title': '@title', |
| 175 * 'selection': '<=>currentItem', | 98 * 'selection': '<=>currentItem', |
| 176 * 'on-selection-change': '&onChange'}) | 99 * 'on-selection-change': '&onChange' |
| 100 * } |
| 101 * ) |
| 177 * class MyComponent { | 102 * class MyComponent { |
| 178 * String title; | 103 * String title; |
| 179 * var currentItem; | 104 * var currentItem; |
| 180 * ParsedFn onChange; | 105 * ParsedFn onChange; |
| 181 * } | 106 * } |
| 182 * | 107 * |
| 183 * The above example shows how all three mapping modes are used. | 108 * The above example shows how all three mapping modes are used. |
| 184 * | 109 * |
| 185 * * `@title` maps the title DOM attribute to the controller `title` | 110 * * `@title` maps the title DOM attribute to the controller `title` |
| 186 * field. Notice that this maps the content of the attribute, which | 111 * field. Notice that this maps the content of the attribute, which |
| 187 * means that it can be used with `{{}}` interpolation. | 112 * means that it can be used with `{{}}` interpolation. |
| 188 * | 113 * |
| 189 * * `<=>currentItem` maps the expression (in this case the `selectedItem` | 114 * * `<=>currentItem` maps the expression (in this case the `selectedItem` |
| 190 * in the current scope into the `currentItem` in the controller. Notice | 115 * in the current scope into the `currentItem` in the controller. Notice |
| 191 * that mapping is bi-directional. A change either in field or on | 116 * that mapping is bi-directional. A change either in field or on |
| 192 * parent scope will result in change to the other. | 117 * parent scope will result in change to the other. |
| 193 * | 118 * |
| 194 * * `&onChange` maps the expression into the controller `onChange` | 119 * * `&onChange` maps the expression into the controller `onChange` |
| 195 * field. The result of mapping is a callable function which can be | 120 * field. The result of mapping is a callable function which can be |
| 196 * invoked at any time by the controller. The invocation of the | 121 * invoked at any time by the controller. The invocation of the |
| 197 * callable function will result in the expression `doSomething()` to | 122 * callable function will result in the expression `doSomething()` to |
| 198 * be executed in the parent context. | 123 * be executed in the parent context. |
| 199 */ | 124 */ |
| 200 final Map<String, String> map; | 125 final Map<String, String> map; |
| 201 | 126 |
| 202 /** | 127 /** |
| 203 * Use the list to specify expressions containing attributes which are not | 128 * Use the list to specify expression containing attributes which are not |
| 204 * included under [map] with '=' or '@' specification. This is used by | 129 * included under [map] with '=' or '@' specification. |
| 205 * angular transformer during deployment. | |
| 206 */ | 130 */ |
| 207 final List<String> exportExpressionAttrs; | 131 final List<String> exportExpressionAttrs; |
| 208 | 132 |
| 209 /** | 133 /** |
| 210 * Use the list to specify expressions which are evaluated dynamically | 134 * Use the list to specify a expressions which are evaluated dynamically |
| 211 * (ex. via [Scope.eval]) and are otherwise not statically discoverable. | 135 * (ex. via [Scope.eval]) and are otherwise not statically discoverable. |
| 212 * This is used by angular transformer during deployment. | |
| 213 */ | 136 */ |
| 214 final List<String> exportExpressions; | 137 final List<String> exportExpressions; |
| 215 | 138 |
| 216 const Directive({ | 139 const NgAnnotation({ |
| 217 this.selector, | 140 this.selector, |
| 218 this.children: Directive.COMPILE_CHILDREN, | 141 this.children: NgAnnotation.COMPILE_CHILDREN, |
| 219 this.visibility: Directive.LOCAL_VISIBILITY, | 142 this.visibility: NgDirective.LOCAL_VISIBILITY, |
| 220 this.module, | 143 this.publishTypes: const [], |
| 221 this.map: const {}, | 144 this.map: const {}, |
| 222 this.exportExpressions: const [], | 145 this.exportExpressions: const [], |
| 223 this.exportExpressionAttrs: const [] | 146 this.exportExpressionAttrs: const [] |
| 224 }); | 147 }); |
| 225 | 148 |
| 226 toString() => selector; | 149 toString() => selector; |
| 227 get hashCode => selector.hashCode; | 150 get hashCode => selector.hashCode; |
| 228 operator==(other) => | 151 operator==(other) => |
| 229 other is Directive && selector == other.selector; | 152 other is NgAnnotation && this.selector == other.selector; |
| 230 | 153 |
| 231 Directive _cloneWithNewMap(newMap); | 154 NgAnnotation cloneWithNewMap(newMap); |
| 232 } | 155 } |
| 233 | 156 |
| 234 | 157 |
| 235 bool _applyAuthorStylesDeprecationWarningPrinted = false; | |
| 236 bool _resetStyleInheritanceDeprecationWarningPrinted = false; | |
| 237 | |
| 238 /** | 158 /** |
| 239 * Meta-data marker placed on a class which should act as a controller for the | 159 * Meta-data marker placed on a class which should act as a controller for the |
| 240 * component. Angular components are a light-weight version of web-components. | 160 * component. Angular components are a light-weight version of web-components. |
| 241 * Angular components use shadow-DOM for rendering their templates. | 161 * Angular components use shadow-DOM for rendering their templates. |
| 242 * | 162 * |
| 243 * Angular components are instantiated using dependency injection, and can | 163 * Angular components are instantiated using dependency injection, and can |
| 244 * ask for any injectable object in their constructor. Components | 164 * ask for any injectable object in their constructor. Components |
| 245 * can also ask for other components or directives declared on the DOM element. | 165 * can also ask for other components or directives declared on the DOM element. |
| 246 * | 166 * |
| 247 * Components can implement [AttachAware], [DetachAware], | 167 * Components can implement [NgAttachAware], [NgDetachAware], |
| 248 * [ShadowRootAware] and declare these optional methods: | 168 * [NgShadowRootAware] and declare these optional methods: |
| 249 * | 169 * |
| 250 * * `attach()` - Called on first [Scope.apply()]. | 170 * * `attach()` - Called on first [Scope.apply()]. |
| 251 * * `detach()` - Called on when owning scope is destroyed. | 171 * * `detach()` - Called on when owning scope is destroyed. |
| 252 * * `onShadowRoot(ShadowRoot shadowRoot)` - Called when [ShadowRoot] is loaded. | 172 * * `onShadowRoot(ShadowRoot shadowRoot)` - Called when [ShadowRoot] is loaded. |
| 253 */ | 173 */ |
| 254 class Component extends Directive { | 174 class NgComponent extends NgAnnotation { |
| 255 /** | 175 /** |
| 256 * Inlined HTML template for the component. | 176 * Inlined HTML template for the component. |
| 257 */ | 177 */ |
| 258 final String template; | 178 final String template; |
| 259 | 179 |
| 260 /** | 180 /** |
| 261 * A URL to HTML template. This will be loaded asynchronously and | 181 * A URL to HTML template. This will be loaded asynchronously and |
| 262 * cached for future component instances. | 182 * cached for future component instances. |
| 263 */ | 183 */ |
| 264 final String templateUrl; | 184 final String templateUrl; |
| 265 | 185 |
| 266 /** | 186 /** |
| 267 * A list of CSS URLs to load into the shadow DOM. | 187 * A list of CSS URLs to load into the shadow DOM. |
| 268 */ | 188 */ |
| 269 final _cssUrls; | 189 final _cssUrls; |
| 270 | 190 |
| 271 /** | 191 /** |
| 272 * Set the shadow root applyAuthorStyles property. See shadow-DOM | 192 * Set the shadow root applyAuthorStyles property. See shadow-DOM |
| 273 * documentation for further details. | 193 * documentation for further details. |
| 274 * | |
| 275 * This feature will be removed in Chrome 35. | |
| 276 */ | 194 */ |
| 277 @deprecated | 195 final bool applyAuthorStyles; |
| 278 bool get applyAuthorStyles { | |
| 279 if (!_applyAuthorStylesDeprecationWarningPrinted && _applyAuthorStyles == tr
ue) { | |
| 280 print("WARNING applyAuthorStyles is deprecated in component $selector"); | |
| 281 _applyAuthorStylesDeprecationWarningPrinted = true; | |
| 282 } | |
| 283 return _applyAuthorStyles; | |
| 284 } | |
| 285 final bool _applyAuthorStyles; | |
| 286 | 196 |
| 287 /** | 197 /** |
| 288 * Set the shadow root resetStyleInheritance property. See shadow-DOM | 198 * Set the shadow root resetStyleInheritance property. See shadow-DOM |
| 289 * documentation for further details. | 199 * documentation for further details. |
| 290 * | |
| 291 * This feature will be removed in Chrome 35. | |
| 292 */ | 200 */ |
| 293 @deprecated | 201 final bool resetStyleInheritance; |
| 294 bool get resetStyleInheritance { | |
| 295 if (!_resetStyleInheritanceDeprecationWarningPrinted && _resetStyleInheritan
ce == true) { | |
| 296 print("WARNING resetStyleInheritance is deprecated in component $selector"
); | |
| 297 _resetStyleInheritanceDeprecationWarningPrinted = true; | |
| 298 } | |
| 299 return _resetStyleInheritance; | |
| 300 } | |
| 301 final bool _resetStyleInheritance; | |
| 302 | 202 |
| 303 /** | 203 /** |
| 304 * An expression under which the component's controller instance will be | 204 * An expression under which the component's controller instance will be |
| 305 * published into. This allows the expressions in the template to be referring | 205 * published into. This allows the expressions in the template to be referring |
| 306 * to controller instance and its properties. | 206 * to controller instance and its properties. |
| 307 */ | 207 */ |
| 308 @deprecated | |
| 309 final String publishAs; | 208 final String publishAs; |
| 310 | 209 |
| 311 /** | 210 const NgComponent({ |
| 312 * If set to true, this component will always use shadow DOM. | |
| 313 * If set to false, this component will never use shadow DOM. | |
| 314 * If unset, the compiler's default construction strategy will be used | |
| 315 */ | |
| 316 final bool useShadowDom; | |
| 317 | |
| 318 const Component({ | |
| 319 this.template, | 211 this.template, |
| 320 this.templateUrl, | 212 this.templateUrl, |
| 321 cssUrl, | 213 cssUrl, |
| 322 applyAuthorStyles, | 214 this.applyAuthorStyles, |
| 323 resetStyleInheritance, | 215 this.resetStyleInheritance, |
| 324 this.publishAs, | 216 this.publishAs, |
| 325 module, | |
| 326 map, | 217 map, |
| 327 selector, | 218 selector, |
| 328 visibility, | 219 visibility, |
| 220 publishTypes : const <Type>[], |
| 329 exportExpressions, | 221 exportExpressions, |
| 330 exportExpressionAttrs, | 222 exportExpressionAttrs}) |
| 331 this.useShadowDom}) | |
| 332 : _cssUrls = cssUrl, | 223 : _cssUrls = cssUrl, |
| 333 _applyAuthorStyles = applyAuthorStyles, | |
| 334 _resetStyleInheritance = resetStyleInheritance, | |
| 335 super(selector: selector, | 224 super(selector: selector, |
| 336 children: Directive.COMPILE_CHILDREN, | 225 children: NgAnnotation.COMPILE_CHILDREN, |
| 337 visibility: visibility, | 226 visibility: visibility, |
| 227 publishTypes: publishTypes, |
| 338 map: map, | 228 map: map, |
| 339 module: module, | |
| 340 exportExpressions: exportExpressions, | 229 exportExpressions: exportExpressions, |
| 341 exportExpressionAttrs: exportExpressionAttrs); | 230 exportExpressionAttrs: exportExpressionAttrs); |
| 342 | 231 |
| 343 List<String> get cssUrls => _cssUrls == null ? | 232 List<String> get cssUrls => _cssUrls == null ? |
| 344 const [] : | 233 const [] : |
| 345 _cssUrls is List ? _cssUrls : [_cssUrls]; | 234 _cssUrls is List ? _cssUrls : [_cssUrls]; |
| 346 | 235 |
| 347 Directive _cloneWithNewMap(newMap) => | 236 NgAnnotation cloneWithNewMap(newMap) => |
| 348 new Component( | 237 new NgComponent( |
| 349 template: template, | 238 template: template, |
| 350 templateUrl: templateUrl, | 239 templateUrl: templateUrl, |
| 351 cssUrl: cssUrls, | 240 cssUrl: cssUrls, |
| 352 applyAuthorStyles: applyAuthorStyles, | 241 applyAuthorStyles: applyAuthorStyles, |
| 353 resetStyleInheritance: resetStyleInheritance, | 242 resetStyleInheritance: resetStyleInheritance, |
| 354 publishAs: publishAs, | 243 publishAs: publishAs, |
| 355 map: newMap, | 244 map: newMap, |
| 356 module: module, | |
| 357 selector: selector, | 245 selector: selector, |
| 358 visibility: visibility, | 246 visibility: visibility, |
| 247 publishTypes: publishTypes, |
| 359 exportExpressions: exportExpressions, | 248 exportExpressions: exportExpressions, |
| 360 exportExpressionAttrs: exportExpressionAttrs, | 249 exportExpressionAttrs: exportExpressionAttrs); |
| 361 useShadowDom: useShadowDom); | |
| 362 } | 250 } |
| 363 | 251 |
| 252 RegExp _ATTR_NAME = new RegExp(r'\[([^\]]+)\]$'); |
| 253 |
| 364 /** | 254 /** |
| 365 * Meta-data marker placed on a class which should act as a directive. | 255 * Meta-data marker placed on a class which should act as a directive. |
| 366 * | 256 * |
| 367 * Angular directives are instantiated using dependency injection, and can | 257 * Angular directives are instantiated using dependency injection, and can |
| 368 * ask for any injectable object in their constructor. Directives | 258 * ask for any injectable object in their constructor. Directives |
| 369 * can also ask for other components or directives declared on the DOM element. | 259 * can also ask for other components or directives declared on the DOM element. |
| 370 * | 260 * |
| 371 * Directives can implement [AttachAware], [DetachAware] and | 261 * Directives can implement [NgAttachAware], [NgDetachAware] and |
| 372 * declare these optional methods: | 262 * declare these optional methods: |
| 373 * | 263 * |
| 374 * * `attach()` - Called on first [Scope.apply()]. | 264 * * `attach()` - Called on first [Scope.apply()]. |
| 375 * * `detach()` - Called on when owning scope is destroyed. | 265 * * `detach()` - Called on when owning scope is destroyed. |
| 376 */ | 266 */ |
| 377 class Decorator extends Directive { | 267 class NgDirective extends NgAnnotation { |
| 378 const Decorator({children: Directive.COMPILE_CHILDREN, | 268 static const String LOCAL_VISIBILITY = 'local'; |
| 269 static const String CHILDREN_VISIBILITY = 'children'; |
| 270 static const String DIRECT_CHILDREN_VISIBILITY = 'direct_children'; |
| 271 |
| 272 const NgDirective({children: NgAnnotation.COMPILE_CHILDREN, |
| 379 map, | 273 map, |
| 380 selector, | 274 selector, |
| 381 module, | |
| 382 visibility, | 275 visibility, |
| 276 publishTypes : const <Type>[], |
| 383 exportExpressions, | 277 exportExpressions, |
| 384 exportExpressionAttrs}) | 278 exportExpressionAttrs}) : super(selector: selector, children
: children, visibility: visibility, |
| 385 : super(selector: selector, | 279 publishTypes: publishTypes, map: map, |
| 386 children: children, | 280 exportExpressions: exportExpressions, |
| 387 visibility: visibility, | 281 exportExpressionAttrs: exportExpressionAttrs); |
| 388 map: map, | |
| 389 module: module, | |
| 390 exportExpressions: exportExpressions, | |
| 391 exportExpressionAttrs: exportExpressionAttrs); | |
| 392 | 282 |
| 393 Directive _cloneWithNewMap(newMap) => | 283 NgAnnotation cloneWithNewMap(newMap) => |
| 394 new Decorator( | 284 new NgDirective( |
| 395 children: children, | 285 children: children, |
| 396 map: newMap, | 286 map: newMap, |
| 397 module: module, | |
| 398 selector: selector, | 287 selector: selector, |
| 399 visibility: visibility, | 288 visibility: visibility, |
| 289 publishTypes: publishTypes, |
| 400 exportExpressions: exportExpressions, | 290 exportExpressions: exportExpressions, |
| 401 exportExpressionAttrs: exportExpressionAttrs); | 291 exportExpressionAttrs: exportExpressionAttrs); |
| 402 } | 292 } |
| 403 | 293 |
| 404 /** | 294 /** |
| 405 * Meta-data marker placed on a class which should act as a controller for your | 295 * Meta-data marker placed on a class which should act as a controller for your
application. |
| 406 * application. | |
| 407 * | 296 * |
| 408 * Controllers are essentially [Decorator]s with few key differences: | 297 * Controllers are essentially [NgDirective]s with few key differences: |
| 409 * | 298 * |
| 410 * * Controllers create a new scope at the element. | 299 * * Controllers create a new scope at the element. |
| 411 * * Controllers should not do any DOM manipulation. | 300 * * Controllers should not do any DOM manipulation. |
| 412 * * Controllers are meant for application-logic | 301 * * Controllers are meant for application-logic |
| 413 * (rather then DOM manipulation logic which directives are meant for.) | 302 * (rather then DOM monipulation logic which directives are meant for.) |
| 414 * | 303 * |
| 415 * Controllers can implement [AttachAware], [DetachAware] and | 304 * Controllers can implement [NgAttachAware], [NgDetachAware] and |
| 416 * declare these optional methods: | 305 * declare these optional methods: |
| 417 * | 306 * |
| 418 * * `attach()` - Called on first [Scope.apply()]. | 307 * * `attach()` - Called on first [Scope.apply()]. |
| 419 * * `detach()` - Called on when owning scope is destroyed. | 308 * * `detach()` - Called on when owning scope is destroyed. |
| 420 */ | 309 */ |
| 421 @deprecated | 310 class NgController extends NgDirective { |
| 422 class Controller extends Decorator { | 311 static const String LOCAL_VISIBILITY = 'local'; |
| 312 static const String CHILDREN_VISIBILITY = 'children'; |
| 313 static const String DIRECT_CHILDREN_VISIBILITY = 'direct_children'; |
| 314 |
| 423 /** | 315 /** |
| 424 * An expression under which the controller instance will be published into. | 316 * An expression under which the controller instance will be published into. |
| 425 * This allows the expressions in the template to be referring to controller | 317 * This allows the expressions in the template to be referring to controller |
| 426 * instance and its properties. | 318 * instance and its properties. |
| 427 */ | 319 */ |
| 428 final String publishAs; | 320 final String publishAs; |
| 429 | 321 |
| 430 const Controller({ | 322 const NgController({ |
| 431 children: Directive.COMPILE_CHILDREN, | 323 children: NgAnnotation.COMPILE_CHILDREN, |
| 432 this.publishAs, | 324 this.publishAs, |
| 433 map, | 325 map, |
| 434 module, | |
| 435 selector, | 326 selector, |
| 436 visibility, | 327 visibility, |
| 328 publishTypes : const <Type>[], |
| 437 exportExpressions, | 329 exportExpressions, |
| 438 exportExpressionAttrs | 330 exportExpressionAttrs |
| 439 }) | 331 }) : super(selector: selector, children: children, visibilit
y: visibility, |
| 440 : super(selector: selector, | 332 publishTypes: publishTypes, map: map, |
| 441 children: children, | 333 exportExpressions: exportExpressions, |
| 442 visibility: visibility, | 334 exportExpressionAttrs: exportExpressionAttrs); |
| 443 map: map, | |
| 444 module: module, | |
| 445 exportExpressions: exportExpressions, | |
| 446 exportExpressionAttrs: exportExpressionAttrs); | |
| 447 | 335 |
| 448 Directive _cloneWithNewMap(newMap) => | 336 NgAnnotation cloneWithNewMap(newMap) => |
| 449 new Controller( | 337 new NgController( |
| 450 children: children, | 338 children: children, |
| 451 publishAs: publishAs, | 339 publishAs: publishAs, |
| 452 module: module, | |
| 453 map: newMap, | 340 map: newMap, |
| 454 selector: selector, | 341 selector: selector, |
| 455 visibility: visibility, | 342 visibility: visibility, |
| 343 publishTypes: publishTypes, |
| 456 exportExpressions: exportExpressions, | 344 exportExpressions: exportExpressions, |
| 457 exportExpressionAttrs: exportExpressionAttrs); | 345 exportExpressionAttrs: exportExpressionAttrs); |
| 458 } | 346 } |
| 459 | 347 |
| 460 /** | 348 abstract class AttrFieldAnnotation { |
| 461 * Abstract supper class of [NgAttr], [NgCallback], [NgOneWay], [NgOneWayOneTime
], and [NgTwoWay]. | |
| 462 */ | |
| 463 abstract class DirectiveAnnotation { | |
| 464 /// Element attribute name | |
| 465 final String attrName; | 349 final String attrName; |
| 466 const DirectiveAnnotation(this.attrName); | 350 const AttrFieldAnnotation(this.attrName); |
| 467 /// Element attribute mapping mode: `@`, `=>`, `=>!`, `<=>`, and `&`. | 351 String get mappingSpec; |
| 468 String get _mappingSpec; | |
| 469 } | 352 } |
| 470 | 353 |
| 471 /** | 354 /** |
| 472 * When applied as an annotation on a directive field specifies that | 355 * When applied as an annotation on a directive field specifies that |
| 473 * the field is to be mapped to DOM attribute with the provided [attrName]. | 356 * the field is to be mapped to DOM attribute with the provided [attrName]. |
| 474 * The value of the attribute to be treated as a string, equivalent | 357 * The value of the attribute to be treated as a string, equivalent |
| 475 * to `@` specification. | 358 * to `@` specification. |
| 476 */ | 359 */ |
| 477 @deprecated | 360 class NgAttr extends AttrFieldAnnotation { |
| 478 class NgAttr extends DirectiveAnnotation { | 361 final mappingSpec = '@'; |
| 479 final _mappingSpec = '@'; | |
| 480 const NgAttr(String attrName) : super(attrName); | 362 const NgAttr(String attrName) : super(attrName); |
| 481 } | 363 } |
| 482 | 364 |
| 483 /** | 365 /** |
| 484 * When applied as an annotation on a directive field specifies that | 366 * When applied as an annotation on a directive field specifies that |
| 485 * the field is to be mapped to DOM attribute with the provided [attrName]. | 367 * the field is to be mapped to DOM attribute with the provided [attrName]. |
| 486 * The value of the attribute to be treated as a one-way expression, equivalent | 368 * The value of the attribute to be treated as a one-way expession, equivalent |
| 487 * to `=>` specification. | 369 * to `=>` specification. |
| 488 */ | 370 */ |
| 489 @deprecated | 371 class NgOneWay extends AttrFieldAnnotation { |
| 490 class NgOneWay extends DirectiveAnnotation { | 372 final mappingSpec = '=>'; |
| 491 final _mappingSpec = '=>'; | |
| 492 const NgOneWay(String attrName) : super(attrName); | 373 const NgOneWay(String attrName) : super(attrName); |
| 493 } | 374 } |
| 494 | 375 |
| 495 /** | 376 /** |
| 496 * When applied as an annotation on a directive field specifies that | 377 * When applied as an annotation on a directive field specifies that |
| 497 * the field is to be mapped to DOM attribute with the provided [attrName]. | 378 * the field is to be mapped to DOM attribute with the provided [attrName]. |
| 498 * The value of the attribute to be treated as a one time one-way expression, | 379 * The value of the attribute to be treated as a one time one-way expession, |
| 499 * equivalent to `=>!` specification. | 380 * equivalent to `=>!` specification. |
| 500 */ | 381 */ |
| 501 @deprecated | 382 class NgOneWayOneTime extends AttrFieldAnnotation { |
| 502 class NgOneWayOneTime extends DirectiveAnnotation { | 383 final mappingSpec = '=>!'; |
| 503 final _mappingSpec = '=>!'; | |
| 504 const NgOneWayOneTime(String attrName) : super(attrName); | 384 const NgOneWayOneTime(String attrName) : super(attrName); |
| 505 } | 385 } |
| 506 | 386 |
| 507 /** | 387 /** |
| 508 * When applied as an annotation on a directive field specifies that | 388 * When applied as an annotation on a directive field specifies that |
| 509 * the field is to be mapped to DOM attribute with the provided [attrName]. | 389 * the field is to be mapped to DOM attribute with the provided [attrName]. |
| 510 * The value of the attribute to be treated as a two-way expression, | 390 * The value of the attribute to be treated as a two-way expession, |
| 511 * equivalent to `<=>` specification. | 391 * equivalent to `<=>` specification. |
| 512 */ | 392 */ |
| 513 @deprecated | 393 class NgTwoWay extends AttrFieldAnnotation { |
| 514 class NgTwoWay extends DirectiveAnnotation { | 394 final mappingSpec = '<=>'; |
| 515 final _mappingSpec = '<=>'; | |
| 516 const NgTwoWay(String attrName) : super(attrName); | 395 const NgTwoWay(String attrName) : super(attrName); |
| 517 } | 396 } |
| 518 | 397 |
| 519 /** | 398 /** |
| 520 * When applied as an annotation on a directive field specifies that | 399 * When applied as an annotation on a directive field specifies that |
| 521 * the field is to be mapped to DOM attribute with the provided [attrName]. | 400 * the field is to be mapped to DOM attribute with the provided [attrName]. |
| 522 * The value of the attribute to be treated as a callback expression, | 401 * The value of the attribute to be treated as a callback expession, |
| 523 * equivalent to `&` specification. | 402 * equivalent to `&` specification. |
| 524 */ | 403 */ |
| 525 @deprecated | 404 class NgCallback extends AttrFieldAnnotation { |
| 526 class NgCallback extends DirectiveAnnotation { | 405 final mappingSpec = '&'; |
| 527 final _mappingSpec = '&'; | |
| 528 const NgCallback(String attrName) : super(attrName); | 406 const NgCallback(String attrName) : super(attrName); |
| 529 } | 407 } |
| 530 | 408 |
| 531 /** | 409 /** |
| 532 * A directives or components may chose to implements [AttachAware].[attach] met
hod. | 410 * Implementing directives or components [attach] method will be called when |
| 533 * If implemented the method will be called when the next scope digest occurs af
ter | 411 * the next scope digest occurs after component instantiation. It is guaranteed |
| 534 * component instantiation. It is guaranteed that when [attach] is invoked, that
all | 412 * that when [attach] is invoked, that all attribute mappings have already |
| 535 * attribute mappings have already been processed. | 413 * been processed. |
| 536 */ | 414 */ |
| 537 abstract class AttachAware { | 415 abstract class NgAttachAware { |
| 538 void attach(); | 416 void attach(); |
| 539 } | 417 } |
| 540 | 418 |
| 541 /** | 419 /** |
| 542 * A directives or components may chose to implements [DetachAware].[detach] met
hod. | 420 * Implementing directives or components [detach] method will be called when |
| 543 * If implemented the method will be called when the next associated scope is de
stroyed. | 421 * the associated scope is destroyed. |
| 544 */ | 422 */ |
| 545 abstract class DetachAware { | 423 abstract class NgDetachAware { |
| 546 void detach(); | 424 void detach(); |
| 547 } | 425 } |
| 548 | 426 |
| 549 /** | |
| 550 * Use @[Formatter] annotation to register a new formatter. A formatter is a cla
ss | |
| 551 * with a [call] method (a callable function). | |
| 552 * | |
| 553 * Usage: | |
| 554 * | |
| 555 * // Declaration | |
| 556 * @Formatter(name:'myFilter') | |
| 557 * class MyFilter { | |
| 558 * call(valueToFilter, optArg1, optArg2) { | |
| 559 * return ...; | |
| 560 * } | |
| 561 * } | |
| 562 * | |
| 563 * | |
| 564 * // Registration | |
| 565 * var module = ...; | |
| 566 * module.type(MyFilter); | |
| 567 * | |
| 568 * | |
| 569 * <!-- Usage --> | |
| 570 * <span>{{something | myFilter:arg1:arg2}}</span> | |
| 571 */ | |
| 572 class Formatter { | |
| 573 final String name; | |
| 574 | |
| 575 const Formatter({this.name}); | |
| 576 | |
| 577 int get hashCode => name.hashCode; | |
| 578 bool operator==(other) => name == other.name; | |
| 579 | |
| 580 toString() => 'Formatter: $name'; | |
| 581 } | |
| OLD | NEW |