2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
2016-04-28 17:50:03 -07:00
|
|
|
import {ChangeDetectionStrategy, ViewEncapsulation} from '@angular/core';
|
|
|
|
|
2016-10-24 09:58:52 -07:00
|
|
|
import {createEnumExpression} from '../compiler_util/identifier_util';
|
2016-10-26 16:58:35 -07:00
|
|
|
import {Identifiers} from '../identifiers';
|
2016-06-08 16:38:52 -07:00
|
|
|
import * as o from '../output/output_ast';
|
2016-08-30 18:07:40 -07:00
|
|
|
import {ChangeDetectorStatus, ViewType} from '../private_import_core';
|
|
|
|
|
2016-01-06 14:13:44 -08:00
|
|
|
export class ViewTypeEnum {
|
|
|
|
static fromValue(value: ViewType): o.Expression {
|
2016-10-24 09:58:52 -07:00
|
|
|
return createEnumExpression(Identifiers.ViewType, value);
|
2016-01-06 14:13:44 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ViewEncapsulationEnum {
|
|
|
|
static fromValue(value: ViewEncapsulation): o.Expression {
|
2016-10-24 09:58:52 -07:00
|
|
|
return createEnumExpression(Identifiers.ViewEncapsulation, value);
|
2016-01-06 14:13:44 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ChangeDetectionStrategyEnum {
|
|
|
|
static fromValue(value: ChangeDetectionStrategy): o.Expression {
|
2016-10-24 09:58:52 -07:00
|
|
|
return createEnumExpression(Identifiers.ChangeDetectionStrategy, value);
|
2016-01-06 14:13:44 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-27 20:00:30 -07:00
|
|
|
export class ChangeDetectorStatusEnum {
|
|
|
|
static fromValue(value: ChangeDetectorStatusEnum): o.Expression {
|
2016-10-24 09:58:52 -07:00
|
|
|
return createEnumExpression(Identifiers.ChangeDetectorStatus, value);
|
2016-06-27 20:00:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-06 14:13:44 -08:00
|
|
|
export class ViewConstructorVars {
|
2016-04-18 13:24:42 -07:00
|
|
|
static viewUtils = o.variable('viewUtils');
|
2016-11-01 09:35:03 -07:00
|
|
|
static parentView = o.variable('parentView');
|
|
|
|
static parentIndex = o.variable('parentIndex');
|
|
|
|
static parentElement = o.variable('parentElement');
|
2016-01-06 14:13:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
export class ViewProperties {
|
|
|
|
static renderer = o.THIS_EXPR.prop('renderer');
|
2016-04-18 13:24:42 -07:00
|
|
|
static viewUtils = o.THIS_EXPR.prop('viewUtils');
|
refactor(compiler): generate less code for bindings to DOM elements
Detailed changes:
- remove `UNINITIALIZED`, initialize change detection fields with `undefined`.
* we use `view.numberOfChecks === 0` now everywhere
as indicator whether we are in the first change detection cycle
(previously we used this only in a couple of places).
* we keep the initialization itself as change detection get slower without it.
- remove passing around `throwOnChange` in various generated calls,
and store it on the view as property instead.
- change generated code for bindings to DOM elements as follows:
Before:
```
var currVal_10 = self.context.bgColor;
if (jit_checkBinding15(self.throwOnChange,self._expr_10,currVal_10)) {
self.renderer.setElementStyle(self._el_0,'backgroundColor',((self.viewUtils.sanitizer.sanitize(jit_21,currVal_10) == null)? null: self.viewUtils.sanitizer.sanitize(jit_21,currVal_10).toString()));
self._expr_10 = currVal_10;
}
var currVal_11 = jit_inlineInterpolate16(1,' ',self.context.data.value,' ');
if (jit_checkBinding15(self.throwOnChange,self._expr_11,currVal_11)) {
self.renderer.setText(self._text_1,currVal_11);
self._expr_11 = currVal_11;
}
```,
After:
```
var currVal_10 = self.context.bgColor;
jit_checkRenderStyle14(self,self._el_0,'backgroundColor',null,self._expr_10,self._expr_10=currVal_10,false,jit_21);
var currVal_11 = jit_inlineInterpolate15(1,' ',self.context.data.value,' ');
jit_checkRenderText16(self,self._text_1,self._expr_11,self._expr_11=currVal_11,false);
```
Performance impact:
- None seen (checked against internal latency lab)
Part of #13651
2016-12-29 15:03:55 -08:00
|
|
|
static throwOnChange = o.THIS_EXPR.prop('throwOnChange');
|
2016-01-06 14:13:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
export class InjectMethodVars {
|
|
|
|
static token = o.variable('token');
|
|
|
|
static requestNodeIndex = o.variable('requestNodeIndex');
|
|
|
|
static notFoundResult = o.variable('notFoundResult');
|
|
|
|
}
|