Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: third_party/pkg/angular/lib/directive/ng_switch.dart

Issue 256553002: Revert "Update all Angular libs (run update_all.sh)." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 part of angular.directive; 1 part of angular.directive;
2 2
3 /** 3 /**
4 * The ngSwitch directive is used to conditionally swap DOM structure on your 4 * The ngSwitch directive is used to conditionally swap DOM structure on your
5 * template based on a scope expression. Elements within ngSwitch but without 5 * template based on a scope expression. Elements within ngSwitch but without
6 * ngSwitchWhen or ngSwitchDefault directives will be preserved at the location 6 * ngSwitchWhen or ngSwitchDefault directives will be preserved at the location
7 * as specified in the template. 7 * as specified in the template.
8 * 8 *
9 * The directive itself works similar to ngInclude, however, instead of 9 * The directive itself works similar to ngInclude, however, instead of
10 * downloading template code (or loading it from the template cache), ngSwitch 10 * downloading template code (or loading it from the template cache), ngSwitch
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 * <button ng-click="selection=''">Show default</button> 42 * <button ng-click="selection=''">Show default</button>
43 * <tt>selection={{selection}}</tt> 43 * <tt>selection={{selection}}</tt>
44 * <hr/> 44 * <hr/>
45 * <div ng-switch="selection"> 45 * <div ng-switch="selection">
46 * <div ng-switch-when="settings">Settings Div</div> 46 * <div ng-switch-when="settings">Settings Div</div>
47 * <div ng-switch-when="home">Home Span</div> 47 * <div ng-switch-when="home">Home Span</div>
48 * <div ng-switch-default>default</div> 48 * <div ng-switch-default>default</div>
49 * </div> 49 * </div>
50 * </div> 50 * </div>
51 */ 51 */
52 @Decorator( 52 @NgDirective(
53 selector: '[ng-switch]', 53 selector: '[ng-switch]',
54 map: const { 54 map: const {
55 'ng-switch': '=>value', 55 'ng-switch': '=>value',
56 'change': '&onChange' 56 'change': '&onChange'
57 }, 57 },
58 visibility: Directive.DIRECT_CHILDREN_VISIBILITY) 58 visibility: NgDirective.DIRECT_CHILDREN_VISIBILITY)
59 class NgSwitch { 59 class NgSwitchDirective {
60 Map<String, List<_Case>> cases = new Map<String, List<_Case>>(); 60 Map<String, List<_Case>> cases = new Map<String, List<_Case>>();
61 List<_ViewScopePair> currentViews = <_ViewScopePair>[]; 61 List<_BlockScopePair> currentBlocks = <_BlockScopePair>[];
62 Function onChange; 62 Function onChange;
63 final Scope scope; 63 final Scope scope;
64 64
65 NgSwitch(this.scope) { 65 NgSwitchDirective(this.scope) {
66 cases['?'] = <_Case>[]; 66 cases['?'] = <_Case>[];
67 } 67 }
68 68
69 addCase(String value, ViewPort anchor, BoundViewFactory viewFactory) { 69 addCase(String value, BlockHole anchor, BoundBlockFactory blockFactory) {
70 cases.putIfAbsent(value, () => <_Case>[]); 70 cases.putIfAbsent(value, () => <_Case>[]);
71 cases[value].add(new _Case(anchor, viewFactory)); 71 cases[value].add(new _Case(anchor, blockFactory));
72 } 72 }
73 73
74 set value(val) { 74 set value(val) {
75 currentViews 75 currentBlocks
76 ..forEach((_ViewScopePair pair) { 76 ..forEach((_BlockScopePair pair) {
77 pair.port.remove(pair.view); 77 pair.block.remove();
78 pair.scope.destroy(); 78 pair.scope.destroy();
79 }) 79 })
80 ..clear(); 80 ..clear();
81 81
82 val = '!$val'; 82 val = '!$val';
83 (cases.containsKey(val) ? cases[val] : cases['?']) 83 (cases.containsKey(val) ? cases[val] : cases['?'])
84 .forEach((_Case caze) { 84 .forEach((_Case caze) {
85 Scope childScope = scope.createChild(new PrototypeMap(scope.context)); 85 Scope childScope = scope.createChild(new PrototypeMap(scope.context));
86 var view = caze.viewFactory(childScope); 86 var block = caze.blockFactory(childScope)..insertAfter(caze.anchor);
87 caze.anchor.insert(view); 87 currentBlocks.add(new _BlockScopePair(block, childScope));
88 currentViews.add(new _ViewScopePair(view, caze.anchor,
89 childScope));
90 }); 88 });
91 if (onChange != null) { 89 if (onChange != null) {
92 onChange(); 90 onChange();
93 } 91 }
94 } 92 }
95 } 93 }
96 94
97 class _ViewScopePair { 95 class _BlockScopePair {
98 final View view; 96 final Block block;
99 final ViewPort port;
100 final Scope scope; 97 final Scope scope;
101 98
102 _ViewScopePair(this.view, this.port, this.scope); 99 _BlockScopePair(this.block, this.scope);
103 } 100 }
104 101
105 class _Case { 102 class _Case {
106 final ViewPort anchor; 103 final BlockHole anchor;
107 final BoundViewFactory viewFactory; 104 final BoundBlockFactory blockFactory;
108 105
109 _Case(this.anchor, this.viewFactory); 106 _Case(this.anchor, this.blockFactory);
110 } 107 }
111 108
112 @Decorator( 109 @NgDirective(
113 selector: '[ng-switch-when]', 110 selector: '[ng-switch-when]',
114 children: Directive.TRANSCLUDE_CHILDREN, 111 children: NgAnnotation.TRANSCLUDE_CHILDREN,
115 map: const {'.': '@value'}) 112 map: const {'.': '@value'})
116 class NgSwitchWhen { 113 class NgSwitchWhenDirective {
117 final NgSwitch ngSwitch; 114 final NgSwitchDirective ngSwitch;
118 final ViewPort port; 115 final BlockHole hole;
119 final BoundViewFactory viewFactory; 116 final BoundBlockFactory blockFactory;
120 final Scope scope; 117 final Scope scope;
121 118
122 NgSwitchWhen(this.ngSwitch, this.port, this.viewFactory, this.scope); 119 NgSwitchWhenDirective(this.ngSwitch, this.hole, this.blockFactory, this.scope) ;
123 120
124 set value(String value) => ngSwitch.addCase('!$value', port, viewFactory); 121 set value(String value) => ngSwitch.addCase('!$value', hole, blockFactory);
125 } 122 }
126 123
127 @Decorator( 124
128 children: Directive.TRANSCLUDE_CHILDREN, 125 @NgDirective(
126 children: NgAnnotation.TRANSCLUDE_CHILDREN,
129 selector: '[ng-switch-default]') 127 selector: '[ng-switch-default]')
130 class NgSwitchDefault { 128 class NgSwitchDefaultDirective {
131 129
132 NgSwitchDefault(NgSwitch ngSwitch, ViewPort port, 130 NgSwitchDefaultDirective(NgSwitchDirective ngSwitch, BlockHole hole,
133 BoundViewFactory viewFactory, Scope scope) { 131 BoundBlockFactory blockFactory, Scope scope) {
134 ngSwitch.addCase('?', port, viewFactory); 132 ngSwitch.addCase('?', hole, blockFactory);
135 } 133 }
136 } 134 }
OLDNEW
« no previous file with comments | « third_party/pkg/angular/lib/directive/ng_style.dart ('k') | third_party/pkg/angular/lib/directive/ng_template.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698