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