ng_switch.js
9.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Directive, Host, Input, TemplateRef, ViewContainerRef } from '@angular/core';
export var SwitchView = (function () {
/**
* @param {?} _viewContainerRef
* @param {?} _templateRef
*/
function SwitchView(_viewContainerRef, _templateRef) {
this._viewContainerRef = _viewContainerRef;
this._templateRef = _templateRef;
this._created = false;
}
/**
* @return {?}
*/
SwitchView.prototype.create = function () {
this._created = true;
this._viewContainerRef.createEmbeddedView(this._templateRef);
};
/**
* @return {?}
*/
SwitchView.prototype.destroy = function () {
this._created = false;
this._viewContainerRef.clear();
};
/**
* @param {?} created
* @return {?}
*/
SwitchView.prototype.enforceState = function (created) {
if (created && !this._created) {
this.create();
}
else if (!created && this._created) {
this.destroy();
}
};
return SwitchView;
}());
function SwitchView_tsickle_Closure_declarations() {
/** @type {?} */
SwitchView.prototype._created;
/** @type {?} */
SwitchView.prototype._viewContainerRef;
/** @type {?} */
SwitchView.prototype._templateRef;
}
/**
* \@ngModule CommonModule
*
* \@whatItDoes Adds / removes DOM sub-trees when the nest match expressions matches the switch
* expression.
*
* \@howToUse
* ```
* <container-element [ngSwitch]="switch_expression">
* <some-element *ngSwitchCase="match_expression_1">...</some-element>
* <some-element *ngSwitchCase="match_expression_2">...</some-element>
* <some-other-element *ngSwitchCase="match_expression_3">...</some-other-element>
* <ng-container *ngSwitchCase="match_expression_3">
* <!-- use a ng-container to group multiple root nodes -->
* <inner-element></inner-element>
* <inner-other-element></inner-other-element>
* </ng-container>
* <some-element *ngSwitchDefault>...</some-element>
* </container-element>
* ```
* \@description
*
* `NgSwitch` stamps out nested views when their match expression value matches the value of the
* switch expression.
*
* In other words:
* - you define a container element (where you place the directive with a switch expression on the
* `[ngSwitch]="..."` attribute)
* - you define inner views inside the `NgSwitch` and place a `*ngSwitchCase` attribute on the view
* root elements.
*
* Elements within `NgSwitch` but outside of a `NgSwitchCase` or `NgSwitchDefault` directives will
* be preserved at the location.
*
* The `ngSwitchCase` directive informs the parent `NgSwitch` of which view to display when the
* expression is evaluated.
* When no matching expression is found on a `ngSwitchCase` view, the `ngSwitchDefault` view is
* stamped out.
*
* \@stable
*/
export var NgSwitch = (function () {
function NgSwitch() {
this._defaultUsed = false;
this._caseCount = 0;
this._lastCaseCheckIndex = 0;
this._lastCasesMatched = false;
}
Object.defineProperty(NgSwitch.prototype, "ngSwitch", {
/**
* @param {?} newValue
* @return {?}
*/
set: function (newValue) {
this._ngSwitch = newValue;
if (this._caseCount === 0) {
this._updateDefaultCases(true);
}
},
enumerable: true,
configurable: true
});
/**
* \@internal
* @return {?}
*/
NgSwitch.prototype._addCase = function () { return this._caseCount++; };
/**
* \@internal
* @param {?} view
* @return {?}
*/
NgSwitch.prototype._addDefault = function (view) {
if (!this._defaultViews) {
this._defaultViews = [];
}
this._defaultViews.push(view);
};
/**
* \@internal
* @param {?} value
* @return {?}
*/
NgSwitch.prototype._matchCase = function (value) {
var /** @type {?} */ matched = value == this._ngSwitch;
this._lastCasesMatched = this._lastCasesMatched || matched;
this._lastCaseCheckIndex++;
if (this._lastCaseCheckIndex === this._caseCount) {
this._updateDefaultCases(!this._lastCasesMatched);
this._lastCaseCheckIndex = 0;
this._lastCasesMatched = false;
}
return matched;
};
/**
* @param {?} useDefault
* @return {?}
*/
NgSwitch.prototype._updateDefaultCases = function (useDefault) {
if (this._defaultViews && useDefault !== this._defaultUsed) {
this._defaultUsed = useDefault;
for (var /** @type {?} */ i = 0; i < this._defaultViews.length; i++) {
var /** @type {?} */ defaultView = this._defaultViews[i];
defaultView.enforceState(useDefault);
}
}
};
NgSwitch.decorators = [
{ type: Directive, args: [{ selector: '[ngSwitch]' },] },
];
/** @nocollapse */
NgSwitch.ctorParameters = function () { return []; };
NgSwitch.propDecorators = {
'ngSwitch': [{ type: Input },],
};
return NgSwitch;
}());
function NgSwitch_tsickle_Closure_declarations() {
/** @type {?} */
NgSwitch.decorators;
/**
* @nocollapse
* @type {?}
*/
NgSwitch.ctorParameters;
/** @type {?} */
NgSwitch.propDecorators;
/** @type {?} */
NgSwitch.prototype._defaultViews;
/** @type {?} */
NgSwitch.prototype._defaultUsed;
/** @type {?} */
NgSwitch.prototype._caseCount;
/** @type {?} */
NgSwitch.prototype._lastCaseCheckIndex;
/** @type {?} */
NgSwitch.prototype._lastCasesMatched;
/** @type {?} */
NgSwitch.prototype._ngSwitch;
}
/**
* \@ngModule CommonModule
*
* \@whatItDoes Creates a view that will be added/removed from the parent {\@link NgSwitch} when the
* given expression evaluate to respectively the same/different value as the switch
* expression.
*
* \@howToUse
* ```
* <container-element [ngSwitch]="switch_expression">
* <some-element *ngSwitchCase="match_expression_1">...</some-element>
* </container-element>
* ```
* \@description
*
* Insert the sub-tree when the expression evaluates to the same value as the enclosing switch
* expression.
*
* If multiple match expressions match the switch expression value, all of them are displayed.
*
* See {\@link NgSwitch} for more details and example.
*
* \@stable
*/
export var NgSwitchCase = (function () {
/**
* @param {?} viewContainer
* @param {?} templateRef
* @param {?} ngSwitch
*/
function NgSwitchCase(viewContainer, templateRef, ngSwitch) {
this.ngSwitch = ngSwitch;
ngSwitch._addCase();
this._view = new SwitchView(viewContainer, templateRef);
}
/**
* @return {?}
*/
NgSwitchCase.prototype.ngDoCheck = function () { this._view.enforceState(this.ngSwitch._matchCase(this.ngSwitchCase)); };
NgSwitchCase.decorators = [
{ type: Directive, args: [{ selector: '[ngSwitchCase]' },] },
];
/** @nocollapse */
NgSwitchCase.ctorParameters = function () { return [
{ type: ViewContainerRef, },
{ type: TemplateRef, },
{ type: NgSwitch, decorators: [{ type: Host },] },
]; };
NgSwitchCase.propDecorators = {
'ngSwitchCase': [{ type: Input },],
};
return NgSwitchCase;
}());
function NgSwitchCase_tsickle_Closure_declarations() {
/** @type {?} */
NgSwitchCase.decorators;
/**
* @nocollapse
* @type {?}
*/
NgSwitchCase.ctorParameters;
/** @type {?} */
NgSwitchCase.propDecorators;
/** @type {?} */
NgSwitchCase.prototype._view;
/** @type {?} */
NgSwitchCase.prototype.ngSwitchCase;
/** @type {?} */
NgSwitchCase.prototype.ngSwitch;
}
/**
* \@ngModule CommonModule
* \@whatItDoes Creates a view that is added to the parent {\@link NgSwitch} when no case expressions
* match the
* switch expression.
*
* \@howToUse
* ```
* <container-element [ngSwitch]="switch_expression">
* <some-element *ngSwitchCase="match_expression_1">...</some-element>
* <some-other-element *ngSwitchDefault>...</some-other-element>
* </container-element>
* ```
*
* \@description
*
* Insert the sub-tree when no case expressions evaluate to the same value as the enclosing switch
* expression.
*
* See {\@link NgSwitch} for more details and example.
*
* \@stable
*/
export var NgSwitchDefault = (function () {
/**
* @param {?} viewContainer
* @param {?} templateRef
* @param {?} ngSwitch
*/
function NgSwitchDefault(viewContainer, templateRef, ngSwitch) {
ngSwitch._addDefault(new SwitchView(viewContainer, templateRef));
}
NgSwitchDefault.decorators = [
{ type: Directive, args: [{ selector: '[ngSwitchDefault]' },] },
];
/** @nocollapse */
NgSwitchDefault.ctorParameters = function () { return [
{ type: ViewContainerRef, },
{ type: TemplateRef, },
{ type: NgSwitch, decorators: [{ type: Host },] },
]; };
return NgSwitchDefault;
}());
function NgSwitchDefault_tsickle_Closure_declarations() {
/** @type {?} */
NgSwitchDefault.decorators;
/**
* @nocollapse
* @type {?}
*/
NgSwitchDefault.ctorParameters;
}
//# sourceMappingURL=ng_switch.js.map