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

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

Issue 180843004: Revert revision 33053 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 @NgDirective( 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: NgDirective.DIRECT_CHILDREN_VISIBILITY) 58 visibility: NgDirective.DIRECT_CHILDREN_VISIBILITY
59 )
59 class NgSwitchDirective { 60 class NgSwitchDirective {
60 Map<String, List<_Case>> cases = new Map<String, List<_Case>>(); 61 Map<String, List<_Case>> cases = new Map<String, List<_Case>>();
61 List<_BlockScopePair> currentBlocks = <_BlockScopePair>[]; 62 List<_BlockScopePair> currentBlocks = <_BlockScopePair>[];
62 Function onChange; 63 Function onChange;
63 final Scope scope; 64 Scope scope;
64 65
65 NgSwitchDirective(this.scope) { 66 NgSwitchDirective(this.scope) {
66 cases['?'] = <_Case>[]; 67 cases['?'] = <_Case>[];
67 } 68 }
68 69
69 addCase(String value, BlockHole anchor, BoundBlockFactory blockFactory) { 70 addCase(String value, BlockHole anchor, BoundBlockFactory blockFactory) {
70 cases.putIfAbsent(value, () => <_Case>[]); 71 cases.putIfAbsent(value, () => <_Case>[]);
71 cases[value].add(new _Case(anchor, blockFactory)); 72 cases[value].add(new _Case(anchor, blockFactory));
72 } 73 }
73 74
74 set value(val) { 75 set value(val) {
75 currentBlocks 76 currentBlocks
76 ..forEach((_BlockScopePair pair) { 77 ..forEach((_BlockScopePair pair) {
77 pair.block.remove(); 78 pair.block.remove();
78 pair.scope.destroy(); 79 pair.scope.$destroy();
79 }) 80 })
80 ..clear(); 81 ..clear();
81 82
82 val = '!$val'; 83 val = '!$val';
83 (cases.containsKey(val) ? cases[val] : cases['?']) 84 (cases.containsKey(val) ? cases[val] : cases['?'])
84 .forEach((_Case caze) { 85 .forEach((_Case caze) {
85 Scope childScope = scope.createChild(new PrototypeMap(scope.context)); 86 Scope childScope = scope.$new();
86 var block = caze.blockFactory(childScope)..insertAfter(caze.anchor); 87 var block = caze.blockFactory(childScope)
88 ..insertAfter(caze.anchor);
87 currentBlocks.add(new _BlockScopePair(block, childScope)); 89 currentBlocks.add(new _BlockScopePair(block, childScope));
88 }); 90 });
89 if (onChange != null) { 91 if (onChange != null) {
90 onChange(); 92 onChange();
91 } 93 }
92 } 94 }
93 } 95 }
94 96
95 class _BlockScopePair { 97 class _BlockScopePair {
96 final Block block; 98 final Block block;
97 final Scope scope; 99 final Scope scope;
98 100
99 _BlockScopePair(this.block, this.scope); 101 _BlockScopePair(this.block, this.scope);
100 } 102 }
101 103
102 class _Case { 104 class _Case {
103 final BlockHole anchor; 105 final BlockHole anchor;
104 final BoundBlockFactory blockFactory; 106 final BoundBlockFactory blockFactory;
105 107
106 _Case(this.anchor, this.blockFactory); 108 _Case(this.anchor, this.blockFactory);
107 } 109 }
108 110
109 @NgDirective( 111 @NgDirective(
110 selector: '[ng-switch-when]', 112 selector: '[ng-switch-when]',
111 children: NgAnnotation.TRANSCLUDE_CHILDREN, 113 children: NgAnnotation.TRANSCLUDE_CHILDREN,
112 map: const {'.': '@value'}) 114 map: const {
115 '.': '@value'
116 }
117 )
113 class NgSwitchWhenDirective { 118 class NgSwitchWhenDirective {
114 final NgSwitchDirective ngSwitch; 119 final NgSwitchDirective ngSwitch;
115 final BlockHole hole; 120 final BlockHole hole;
116 final BoundBlockFactory blockFactory; 121 final BoundBlockFactory blockFactory;
117 final Scope scope; 122 final Scope scope;
118 123
119 NgSwitchWhenDirective(this.ngSwitch, this.hole, this.blockFactory, this.scope) ; 124 NgSwitchWhenDirective(this.ngSwitch, this.hole, this.blockFactory, this.scope) ;
120 125
121 set value(String value) => ngSwitch.addCase('!$value', hole, blockFactory); 126 set value(String value) =>
127 ngSwitch.addCase('!$value', hole, blockFactory);
122 } 128 }
123 129
124 130
125 @NgDirective( 131 @NgDirective(
126 children: NgAnnotation.TRANSCLUDE_CHILDREN, 132 children: NgAnnotation.TRANSCLUDE_CHILDREN,
127 selector: '[ng-switch-default]') 133 selector: '[ng-switch-default]'
134 )
128 class NgSwitchDefaultDirective { 135 class NgSwitchDefaultDirective {
129 136
130 NgSwitchDefaultDirective(NgSwitchDirective ngSwitch, BlockHole hole, 137 NgSwitchDefaultDirective(NgSwitchDirective ngSwitch, BlockHole hole,
131 BoundBlockFactory blockFactory, Scope scope) { 138 BoundBlockFactory blockFactory, Scope scope) {
132 ngSwitch.addCase('?', hole, blockFactory); 139 ngSwitch.addCase('?', hole, blockFactory);
133 } 140 }
134 } 141 }
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