parent
c320240086
commit
d8c5ab232c
|
@ -25,7 +25,7 @@ export class CodegenLogicUtil {
|
||||||
* value of the record. Used by property bindings.
|
* value of the record. Used by property bindings.
|
||||||
*/
|
*/
|
||||||
genPropertyBindingEvalValue(protoRec: ProtoRecord): string {
|
genPropertyBindingEvalValue(protoRec: ProtoRecord): string {
|
||||||
return this.genEvalValue(protoRec, idx => this._names.getLocalName(idx),
|
return this._genEvalValue(protoRec, idx => this._names.getLocalName(idx),
|
||||||
this._names.getLocalsAccessorName());
|
this._names.getLocalsAccessorName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,11 +34,11 @@ export class CodegenLogicUtil {
|
||||||
* value of the record. Used by event bindings.
|
* value of the record. Used by event bindings.
|
||||||
*/
|
*/
|
||||||
genEventBindingEvalValue(eventRecord: any, protoRec: ProtoRecord): string {
|
genEventBindingEvalValue(eventRecord: any, protoRec: ProtoRecord): string {
|
||||||
return this.genEvalValue(protoRec, idx => this._names.getEventLocalName(eventRecord, idx),
|
return this._genEvalValue(protoRec, idx => this._names.getEventLocalName(eventRecord, idx),
|
||||||
"locals");
|
"locals");
|
||||||
}
|
}
|
||||||
|
|
||||||
private genEvalValue(protoRec: ProtoRecord, getLocalName: Function,
|
private _genEvalValue(protoRec: ProtoRecord, getLocalName: Function,
|
||||||
localsAccessor: string): string {
|
localsAccessor: string): string {
|
||||||
var context = (protoRec.contextIndex == -1) ?
|
var context = (protoRec.contextIndex == -1) ?
|
||||||
this._names.getDirectiveName(protoRec.directiveIndex) :
|
this._names.getDirectiveName(protoRec.directiveIndex) :
|
||||||
|
|
|
@ -44,17 +44,17 @@ export class CodegenNameUtil {
|
||||||
_sanitizedNames: string[];
|
_sanitizedNames: string[];
|
||||||
_sanitizedEventNames: Map<EventBinding, string[]>;
|
_sanitizedEventNames: Map<EventBinding, string[]>;
|
||||||
|
|
||||||
constructor(private records: ProtoRecord[], private eventBindings: EventBinding[],
|
constructor(private _records: ProtoRecord[], private _eventBindings: EventBinding[],
|
||||||
private directiveRecords: any[], private utilName: string) {
|
private _directiveRecords: any[], private _utilName: string) {
|
||||||
this._sanitizedNames = ListWrapper.createFixedSize(this.records.length + 1);
|
this._sanitizedNames = ListWrapper.createFixedSize(this._records.length + 1);
|
||||||
this._sanitizedNames[CONTEXT_INDEX] = _CONTEXT_ACCESSOR;
|
this._sanitizedNames[CONTEXT_INDEX] = _CONTEXT_ACCESSOR;
|
||||||
for (var i = 0, iLen = this.records.length; i < iLen; ++i) {
|
for (var i = 0, iLen = this._records.length; i < iLen; ++i) {
|
||||||
this._sanitizedNames[i + 1] = sanitizeName(`${this.records[i].name}${i}`);
|
this._sanitizedNames[i + 1] = sanitizeName(`${this._records[i].name}${i}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._sanitizedEventNames = new Map();
|
this._sanitizedEventNames = new Map();
|
||||||
for (var ebIndex = 0; ebIndex < eventBindings.length; ++ebIndex) {
|
for (var ebIndex = 0; ebIndex < _eventBindings.length; ++ebIndex) {
|
||||||
var eb = eventBindings[ebIndex];
|
var eb = _eventBindings[ebIndex];
|
||||||
var names = [_CONTEXT_ACCESSOR];
|
var names = [_CONTEXT_ACCESSOR];
|
||||||
for (var i = 0, iLen = eb.records.length; i < iLen; ++i) {
|
for (var i = 0, iLen = eb.records.length; i < iLen; ++i) {
|
||||||
names.push(sanitizeName(`${eb.records[i].name}${i}_${ebIndex}`));
|
names.push(sanitizeName(`${eb.records[i].name}${i}_${ebIndex}`));
|
||||||
|
@ -99,7 +99,7 @@ export class CodegenNameUtil {
|
||||||
if (i == CONTEXT_INDEX) {
|
if (i == CONTEXT_INDEX) {
|
||||||
declarations.push(`${this.getLocalName(i)} = ${this.getFieldName(i)}`);
|
declarations.push(`${this.getLocalName(i)} = ${this.getFieldName(i)}`);
|
||||||
} else {
|
} else {
|
||||||
var rec = this.records[i - 1];
|
var rec = this._records[i - 1];
|
||||||
if (rec.argumentToPureFunction) {
|
if (rec.argumentToPureFunction) {
|
||||||
var changeName = this.getChangeName(i);
|
var changeName = this.getChangeName(i);
|
||||||
declarations.push(`${this.getLocalName(i)},${changeName}`);
|
declarations.push(`${this.getLocalName(i)},${changeName}`);
|
||||||
|
@ -138,20 +138,20 @@ export class CodegenNameUtil {
|
||||||
getAllFieldNames(): string[] {
|
getAllFieldNames(): string[] {
|
||||||
var fieldList = [];
|
var fieldList = [];
|
||||||
for (var k = 0, kLen = this.getFieldCount(); k < kLen; ++k) {
|
for (var k = 0, kLen = this.getFieldCount(); k < kLen; ++k) {
|
||||||
if (k === 0 || this.records[k - 1].shouldBeChecked()) {
|
if (k === 0 || this._records[k - 1].shouldBeChecked()) {
|
||||||
fieldList.push(this.getFieldName(k));
|
fieldList.push(this.getFieldName(k));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0, iLen = this.records.length; i < iLen; ++i) {
|
for (var i = 0, iLen = this._records.length; i < iLen; ++i) {
|
||||||
var rec = this.records[i];
|
var rec = this._records[i];
|
||||||
if (rec.isPipeRecord()) {
|
if (rec.isPipeRecord()) {
|
||||||
fieldList.push(this.getPipeName(rec.selfIndex));
|
fieldList.push(this.getPipeName(rec.selfIndex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var j = 0, jLen = this.directiveRecords.length; j < jLen; ++j) {
|
for (var j = 0, jLen = this._directiveRecords.length; j < jLen; ++j) {
|
||||||
var dRec = this.directiveRecords[j];
|
var dRec = this._directiveRecords[j];
|
||||||
fieldList.push(this.getDirectiveName(dRec.directiveIndex));
|
fieldList.push(this.getDirectiveName(dRec.directiveIndex));
|
||||||
if (!dRec.isDefaultChangeDetection()) {
|
if (!dRec.isDefaultChangeDetection()) {
|
||||||
fieldList.push(this.getDetectorName(dRec.directiveIndex));
|
fieldList.push(this.getDetectorName(dRec.directiveIndex));
|
||||||
|
@ -169,7 +169,7 @@ export class CodegenNameUtil {
|
||||||
if (ListWrapper.isEmpty(fields)) return '';
|
if (ListWrapper.isEmpty(fields)) return '';
|
||||||
|
|
||||||
// At least one assignment.
|
// At least one assignment.
|
||||||
fields.push(`${this.utilName}.uninitialized;`);
|
fields.push(`${this._utilName}.uninitialized;`);
|
||||||
return ListWrapper.join(fields, ' = ');
|
return ListWrapper.join(fields, ' = ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,9 +179,9 @@ export class CodegenNameUtil {
|
||||||
genPipeOnDestroy(): string {
|
genPipeOnDestroy(): string {
|
||||||
return ListWrapper.join(
|
return ListWrapper.join(
|
||||||
ListWrapper.map(
|
ListWrapper.map(
|
||||||
ListWrapper.filter(this.records, (r) => { return r.isPipeRecord(); }),
|
ListWrapper.filter(this._records, (r) => { return r.isPipeRecord(); }),
|
||||||
(r) => {
|
(r) => {
|
||||||
return `${this.utilName}.callPipeOnDestroy(${this.getPipeName(r.selfIndex)});`;
|
return `${this._utilName}.callPipeOnDestroy(${this.getPipeName(r.selfIndex)});`;
|
||||||
}),
|
}),
|
||||||
'\n');
|
'\n');
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,12 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
|
||||||
|
|
||||||
constructor(id: string, dispatcher: any, numberOfPropertyProtoRecords: number,
|
constructor(id: string, dispatcher: any, numberOfPropertyProtoRecords: number,
|
||||||
propertyBindingTargets: BindingTarget[], directiveIndices: DirectiveIndex[],
|
propertyBindingTargets: BindingTarget[], directiveIndices: DirectiveIndex[],
|
||||||
strategy: ChangeDetectionStrategy, private records: ProtoRecord[],
|
strategy: ChangeDetectionStrategy, private _records: ProtoRecord[],
|
||||||
private eventBindings: EventBinding[], private directiveRecords: DirectiveRecord[],
|
private _eventBindings: EventBinding[], private _directiveRecords: DirectiveRecord[],
|
||||||
private genConfig: ChangeDetectorGenConfig) {
|
private _genConfig: ChangeDetectorGenConfig) {
|
||||||
super(id, dispatcher, numberOfPropertyProtoRecords, propertyBindingTargets, directiveIndices,
|
super(id, dispatcher, numberOfPropertyProtoRecords, propertyBindingTargets, directiveIndices,
|
||||||
strategy);
|
strategy);
|
||||||
var len = records.length + 1;
|
var len = _records.length + 1;
|
||||||
this.values = ListWrapper.createFixedSize(len);
|
this.values = ListWrapper.createFixedSize(len);
|
||||||
this.localPipes = ListWrapper.createFixedSize(len);
|
this.localPipes = ListWrapper.createFixedSize(len);
|
||||||
this.prevContexts = ListWrapper.createFixedSize(len);
|
this.prevContexts = ListWrapper.createFixedSize(len);
|
||||||
|
@ -80,7 +80,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
|
||||||
}
|
}
|
||||||
|
|
||||||
_matchingEventBindings(eventName: string, elIndex: number): EventBinding[] {
|
_matchingEventBindings(eventName: string, elIndex: number): EventBinding[] {
|
||||||
return ListWrapper.filter(this.eventBindings,
|
return ListWrapper.filter(this._eventBindings,
|
||||||
eb => eb.eventName == eventName && eb.elIndex === elIndex);
|
eb => eb.eventName == eventName && eb.elIndex === elIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
|
||||||
checkNoChanges(): void { this.runDetectChanges(true); }
|
checkNoChanges(): void { this.runDetectChanges(true); }
|
||||||
|
|
||||||
detectChangesInRecordsInternal(throwOnChange: boolean) {
|
detectChangesInRecordsInternal(throwOnChange: boolean) {
|
||||||
var protos = this.records;
|
var protos = this._records;
|
||||||
|
|
||||||
var changes = null;
|
var changes = null;
|
||||||
var isChanged = false;
|
var isChanged = false;
|
||||||
|
@ -162,12 +162,12 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
|
||||||
}
|
}
|
||||||
|
|
||||||
_firstInBinding(r: ProtoRecord): boolean {
|
_firstInBinding(r: ProtoRecord): boolean {
|
||||||
var prev = ChangeDetectionUtil.protoByIndex(this.records, r.selfIndex - 1);
|
var prev = ChangeDetectionUtil.protoByIndex(this._records, r.selfIndex - 1);
|
||||||
return isBlank(prev) || prev.bindingRecord !== r.bindingRecord;
|
return isBlank(prev) || prev.bindingRecord !== r.bindingRecord;
|
||||||
}
|
}
|
||||||
|
|
||||||
afterContentLifecycleCallbacksInternal() {
|
afterContentLifecycleCallbacksInternal() {
|
||||||
var dirs = this.directiveRecords;
|
var dirs = this._directiveRecords;
|
||||||
for (var i = dirs.length - 1; i >= 0; --i) {
|
for (var i = dirs.length - 1; i >= 0; --i) {
|
||||||
var dir = dirs[i];
|
var dir = dirs[i];
|
||||||
if (dir.callAfterContentInit && !this.alreadyChecked) {
|
if (dir.callAfterContentInit && !this.alreadyChecked) {
|
||||||
|
@ -181,7 +181,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
|
||||||
}
|
}
|
||||||
|
|
||||||
afterViewLifecycleCallbacksInternal() {
|
afterViewLifecycleCallbacksInternal() {
|
||||||
var dirs = this.directiveRecords;
|
var dirs = this._directiveRecords;
|
||||||
for (var i = dirs.length - 1; i >= 0; --i) {
|
for (var i = dirs.length - 1; i >= 0; --i) {
|
||||||
var dir = dirs[i];
|
var dir = dirs[i];
|
||||||
if (dir.callAfterViewInit && !this.alreadyChecked) {
|
if (dir.callAfterViewInit && !this.alreadyChecked) {
|
||||||
|
@ -201,7 +201,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
|
||||||
bindingRecord.setter(this._getDirectiveFor(directiveIndex), change.currentValue);
|
bindingRecord.setter(this._getDirectiveFor(directiveIndex), change.currentValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.genConfig.logBindingUpdate) {
|
if (this._genConfig.logBindingUpdate) {
|
||||||
super.logBindingUpdate(change.currentValue);
|
super.logBindingUpdate(change.currentValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,19 +42,19 @@ export class DynamicProtoChangeDetector implements ProtoChangeDetector {
|
||||||
_eventBindingRecords: EventBinding[];
|
_eventBindingRecords: EventBinding[];
|
||||||
_directiveIndices: DirectiveIndex[];
|
_directiveIndices: DirectiveIndex[];
|
||||||
|
|
||||||
constructor(private definition: ChangeDetectorDefinition) {
|
constructor(private _definition: ChangeDetectorDefinition) {
|
||||||
this._propertyBindingRecords = createPropertyRecords(definition);
|
this._propertyBindingRecords = createPropertyRecords(_definition);
|
||||||
this._eventBindingRecords = createEventRecords(definition);
|
this._eventBindingRecords = createEventRecords(_definition);
|
||||||
this._propertyBindingTargets = this.definition.bindingRecords.map(b => b.target);
|
this._propertyBindingTargets = this._definition.bindingRecords.map(b => b.target);
|
||||||
this._directiveIndices = this.definition.directiveRecords.map(d => d.directiveIndex);
|
this._directiveIndices = this._definition.directiveRecords.map(d => d.directiveIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
instantiate(dispatcher: any): ChangeDetector {
|
instantiate(dispatcher: any): ChangeDetector {
|
||||||
return new DynamicChangeDetector(
|
return new DynamicChangeDetector(
|
||||||
this.definition.id, dispatcher, this._propertyBindingRecords.length,
|
this._definition.id, dispatcher, this._propertyBindingRecords.length,
|
||||||
this._propertyBindingTargets, this._directiveIndices, this.definition.strategy,
|
this._propertyBindingTargets, this._directiveIndices, this._definition.strategy,
|
||||||
this._propertyBindingRecords, this._eventBindingRecords, this.definition.directiveRecords,
|
this._propertyBindingRecords, this._eventBindingRecords, this._definition.directiveRecords,
|
||||||
this.definition.genConfig);
|
this._definition.genConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,13 +40,13 @@ export class NgFor {
|
||||||
_ngForOf: any;
|
_ngForOf: any;
|
||||||
private _differ: IterableDiffer;
|
private _differ: IterableDiffer;
|
||||||
|
|
||||||
constructor(private viewContainer: ViewContainerRef, private templateRef: TemplateRef,
|
constructor(private _viewContainer: ViewContainerRef, private _templateRef: TemplateRef,
|
||||||
private iterableDiffers: IterableDiffers, private cdr: ChangeDetectorRef) {}
|
private _iterableDiffers: IterableDiffers, private _cdr: ChangeDetectorRef) {}
|
||||||
|
|
||||||
set ngForOf(value: any) {
|
set ngForOf(value: any) {
|
||||||
this._ngForOf = value;
|
this._ngForOf = value;
|
||||||
if (isBlank(this._differ) && isPresent(value)) {
|
if (isBlank(this._differ) && isPresent(value)) {
|
||||||
this._differ = this.iterableDiffers.find(value).create(this.cdr);
|
this._differ = this._iterableDiffers.find(value).create(this._cdr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,19 +67,19 @@ export class NgFor {
|
||||||
changes.forEachMovedItem((movedRecord) =>
|
changes.forEachMovedItem((movedRecord) =>
|
||||||
recordViewTuples.push(new RecordViewTuple(movedRecord, null)));
|
recordViewTuples.push(new RecordViewTuple(movedRecord, null)));
|
||||||
|
|
||||||
var insertTuples = NgFor.bulkRemove(recordViewTuples, this.viewContainer);
|
var insertTuples = NgFor.bulkRemove(recordViewTuples, this._viewContainer);
|
||||||
|
|
||||||
changes.forEachAddedItem((addedRecord) =>
|
changes.forEachAddedItem((addedRecord) =>
|
||||||
insertTuples.push(new RecordViewTuple(addedRecord, null)));
|
insertTuples.push(new RecordViewTuple(addedRecord, null)));
|
||||||
|
|
||||||
NgFor.bulkInsert(insertTuples, this.viewContainer, this.templateRef);
|
NgFor.bulkInsert(insertTuples, this._viewContainer, this._templateRef);
|
||||||
|
|
||||||
for (var i = 0; i < insertTuples.length; i++) {
|
for (var i = 0; i < insertTuples.length; i++) {
|
||||||
this._perViewChange(insertTuples[i].view, insertTuples[i].record);
|
this._perViewChange(insertTuples[i].view, insertTuples[i].record);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0, ilen = this.viewContainer.length; i < ilen; i++) {
|
for (var i = 0, ilen = this._viewContainer.length; i < ilen; i++) {
|
||||||
this.viewContainer.get(i).setLocal('last', i === ilen - 1);
|
this._viewContainer.get(i).setLocal('last', i === ilen - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ class _ArrayLogger {
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ExceptionHandler {
|
export class ExceptionHandler {
|
||||||
constructor(private logger: any, private rethrowException: boolean = true) {}
|
constructor(private _logger: any, private _rethrowException: boolean = true) {}
|
||||||
|
|
||||||
static exceptionToString(exception: any, stackTrace: any = null, reason: string = null): string {
|
static exceptionToString(exception: any, stackTrace: any = null, reason: string = null): string {
|
||||||
var l = new _ArrayLogger();
|
var l = new _ArrayLogger();
|
||||||
|
@ -47,36 +47,36 @@ export class ExceptionHandler {
|
||||||
var originalStack = this._findOriginalStack(exception);
|
var originalStack = this._findOriginalStack(exception);
|
||||||
var context = this._findContext(exception);
|
var context = this._findContext(exception);
|
||||||
|
|
||||||
this.logger.logGroup(`EXCEPTION: ${exception}`);
|
this._logger.logGroup(`EXCEPTION: ${exception}`);
|
||||||
|
|
||||||
if (isPresent(stackTrace) && isBlank(originalStack)) {
|
if (isPresent(stackTrace) && isBlank(originalStack)) {
|
||||||
this.logger.logError("STACKTRACE:");
|
this._logger.logError("STACKTRACE:");
|
||||||
this.logger.logError(this._longStackTrace(stackTrace));
|
this._logger.logError(this._longStackTrace(stackTrace));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPresent(reason)) {
|
if (isPresent(reason)) {
|
||||||
this.logger.logError(`REASON: ${reason}`);
|
this._logger.logError(`REASON: ${reason}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPresent(originalException)) {
|
if (isPresent(originalException)) {
|
||||||
this.logger.logError(`ORIGINAL EXCEPTION: ${originalException}`);
|
this._logger.logError(`ORIGINAL EXCEPTION: ${originalException}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPresent(originalStack)) {
|
if (isPresent(originalStack)) {
|
||||||
this.logger.logError("ORIGINAL STACKTRACE:");
|
this._logger.logError("ORIGINAL STACKTRACE:");
|
||||||
this.logger.logError(this._longStackTrace(originalStack));
|
this._logger.logError(this._longStackTrace(originalStack));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPresent(context)) {
|
if (isPresent(context)) {
|
||||||
this.logger.logError("ERROR CONTEXT:");
|
this._logger.logError("ERROR CONTEXT:");
|
||||||
this.logger.logError(context);
|
this._logger.logError(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.logGroupEnd();
|
this._logger.logGroupEnd();
|
||||||
|
|
||||||
// We rethrow exceptions, so operations like 'bootstrap' will result in an error
|
// We rethrow exceptions, so operations like 'bootstrap' will result in an error
|
||||||
// when an exception happens. If we do not rethrow, bootstrap will always succeed.
|
// when an exception happens. If we do not rethrow, bootstrap will always succeed.
|
||||||
if (this.rethrowException) throw exception;
|
if (this._rethrowException) throw exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
_longStackTrace(stackTrace: any): any {
|
_longStackTrace(stackTrace: any): any {
|
||||||
|
|
|
@ -110,5 +110,5 @@ export class DatePipe implements PipeTransform {
|
||||||
return DateFormatter.format(value, defaultLocale, pattern);
|
return DateFormatter.format(value, defaultLocale, pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
private supports(obj: any): boolean { return isDate(obj) || isNumber(obj); }
|
supports(obj: any): boolean { return isDate(obj) || isNumber(obj); }
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,30 +31,34 @@ import {setProperty} from './shared';
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
export class CheckboxControlValueAccessor implements ControlValueAccessor {
|
export class CheckboxControlValueAccessor implements ControlValueAccessor {
|
||||||
private cd: NgControl;
|
private _cd: NgControl;
|
||||||
onChange = (_) => {};
|
onChange = (_) => {};
|
||||||
onTouched = () => {};
|
onTouched = () => {};
|
||||||
|
|
||||||
constructor(@Self() cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
|
constructor(@Self() cd: NgControl, private _renderer: Renderer, private _elementRef: ElementRef) {
|
||||||
this.cd = cd;
|
this._cd = cd;
|
||||||
cd.valueAccessor = this;
|
cd.valueAccessor = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeValue(value: any) { setProperty(this.renderer, this.elementRef, "checked", value); }
|
writeValue(value: any) { setProperty(this._renderer, this._elementRef, "checked", value); }
|
||||||
|
|
||||||
get ngClassUntouched(): boolean {
|
get ngClassUntouched(): boolean {
|
||||||
return isPresent(this.cd.control) ? this.cd.control.untouched : false;
|
return isPresent(this._cd.control) ? this._cd.control.untouched : false;
|
||||||
}
|
}
|
||||||
get ngClassTouched(): boolean {
|
get ngClassTouched(): boolean {
|
||||||
return isPresent(this.cd.control) ? this.cd.control.touched : false;
|
return isPresent(this._cd.control) ? this._cd.control.touched : false;
|
||||||
}
|
}
|
||||||
get ngClassPristine(): boolean {
|
get ngClassPristine(): boolean {
|
||||||
return isPresent(this.cd.control) ? this.cd.control.pristine : false;
|
return isPresent(this._cd.control) ? this._cd.control.pristine : false;
|
||||||
|
}
|
||||||
|
get ngClassDirty(): boolean {
|
||||||
|
return isPresent(this._cd.control) ? this._cd.control.dirty : false;
|
||||||
|
}
|
||||||
|
get ngClassValid(): boolean {
|
||||||
|
return isPresent(this._cd.control) ? this._cd.control.valid : false;
|
||||||
}
|
}
|
||||||
get ngClassDirty(): boolean { return isPresent(this.cd.control) ? this.cd.control.dirty : false; }
|
|
||||||
get ngClassValid(): boolean { return isPresent(this.cd.control) ? this.cd.control.valid : false; }
|
|
||||||
get ngClassInvalid(): boolean {
|
get ngClassInvalid(): boolean {
|
||||||
return isPresent(this.cd.control) ? !this.cd.control.valid : false;
|
return isPresent(this._cd.control) ? !this._cd.control.valid : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
registerOnChange(fn: (_: any) => {}): void { this.onChange = fn; }
|
registerOnChange(fn: (_: any) => {}): void { this.onChange = fn; }
|
||||||
|
|
|
@ -32,12 +32,12 @@ import {setProperty} from './shared';
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
export class DefaultValueAccessor implements ControlValueAccessor {
|
export class DefaultValueAccessor implements ControlValueAccessor {
|
||||||
private cd: NgControl;
|
private _cd: NgControl;
|
||||||
onChange = (_) => {};
|
onChange = (_) => {};
|
||||||
onTouched = () => {};
|
onTouched = () => {};
|
||||||
|
|
||||||
constructor(@Self() cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
|
constructor(@Self() cd: NgControl, private _renderer: Renderer, private _elementRef: ElementRef) {
|
||||||
this.cd = cd;
|
this._cd = cd;
|
||||||
cd.valueAccessor = this;
|
cd.valueAccessor = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,22 +45,26 @@ export class DefaultValueAccessor implements ControlValueAccessor {
|
||||||
// both this.value and setProperty are required at the moment
|
// both this.value and setProperty are required at the moment
|
||||||
// remove when a proper imperative API is provided
|
// remove when a proper imperative API is provided
|
||||||
var normalizedValue = isBlank(value) ? '' : value;
|
var normalizedValue = isBlank(value) ? '' : value;
|
||||||
setProperty(this.renderer, this.elementRef, 'value', normalizedValue);
|
setProperty(this._renderer, this._elementRef, 'value', normalizedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
get ngClassUntouched(): boolean {
|
get ngClassUntouched(): boolean {
|
||||||
return isPresent(this.cd.control) ? this.cd.control.untouched : false;
|
return isPresent(this._cd.control) ? this._cd.control.untouched : false;
|
||||||
}
|
}
|
||||||
get ngClassTouched(): boolean {
|
get ngClassTouched(): boolean {
|
||||||
return isPresent(this.cd.control) ? this.cd.control.touched : false;
|
return isPresent(this._cd.control) ? this._cd.control.touched : false;
|
||||||
}
|
}
|
||||||
get ngClassPristine(): boolean {
|
get ngClassPristine(): boolean {
|
||||||
return isPresent(this.cd.control) ? this.cd.control.pristine : false;
|
return isPresent(this._cd.control) ? this._cd.control.pristine : false;
|
||||||
|
}
|
||||||
|
get ngClassDirty(): boolean {
|
||||||
|
return isPresent(this._cd.control) ? this._cd.control.dirty : false;
|
||||||
|
}
|
||||||
|
get ngClassValid(): boolean {
|
||||||
|
return isPresent(this._cd.control) ? this._cd.control.valid : false;
|
||||||
}
|
}
|
||||||
get ngClassDirty(): boolean { return isPresent(this.cd.control) ? this.cd.control.dirty : false; }
|
|
||||||
get ngClassValid(): boolean { return isPresent(this.cd.control) ? this.cd.control.valid : false; }
|
|
||||||
get ngClassInvalid(): boolean {
|
get ngClassInvalid(): boolean {
|
||||||
return isPresent(this.cd.control) ? !this.cd.control.valid : false;
|
return isPresent(this._cd.control) ? !this._cd.control.valid : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
registerOnChange(fn: (_: any) => void): void { this.onChange = fn; }
|
registerOnChange(fn: (_: any) => void): void { this.onChange = fn; }
|
||||||
|
|
|
@ -41,36 +41,40 @@ export class NgSelectOption {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
export class SelectControlValueAccessor implements ControlValueAccessor {
|
export class SelectControlValueAccessor implements ControlValueAccessor {
|
||||||
private cd: NgControl;
|
private _cd: NgControl;
|
||||||
value: string;
|
value: string;
|
||||||
onChange = (_) => {};
|
onChange = (_) => {};
|
||||||
onTouched = () => {};
|
onTouched = () => {};
|
||||||
|
|
||||||
constructor(@Self() cd: NgControl, private renderer: Renderer, private elementRef: ElementRef,
|
constructor(@Self() cd: NgControl, private _renderer: Renderer, private _elementRef: ElementRef,
|
||||||
@Query(NgSelectOption, {descendants: true}) query: QueryList<NgSelectOption>) {
|
@Query(NgSelectOption, {descendants: true}) query: QueryList<NgSelectOption>) {
|
||||||
this.cd = cd;
|
this._cd = cd;
|
||||||
cd.valueAccessor = this;
|
cd.valueAccessor = this;
|
||||||
this._updateValueWhenListOfOptionsChanges(query);
|
this._updateValueWhenListOfOptionsChanges(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
writeValue(value: any) {
|
writeValue(value: any) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
setProperty(this.renderer, this.elementRef, "value", value);
|
setProperty(this._renderer, this._elementRef, "value", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
get ngClassUntouched(): boolean {
|
get ngClassUntouched(): boolean {
|
||||||
return isPresent(this.cd.control) ? this.cd.control.untouched : false;
|
return isPresent(this._cd.control) ? this._cd.control.untouched : false;
|
||||||
}
|
}
|
||||||
get ngClassTouched(): boolean {
|
get ngClassTouched(): boolean {
|
||||||
return isPresent(this.cd.control) ? this.cd.control.touched : false;
|
return isPresent(this._cd.control) ? this._cd.control.touched : false;
|
||||||
}
|
}
|
||||||
get ngClassPristine(): boolean {
|
get ngClassPristine(): boolean {
|
||||||
return isPresent(this.cd.control) ? this.cd.control.pristine : false;
|
return isPresent(this._cd.control) ? this._cd.control.pristine : false;
|
||||||
|
}
|
||||||
|
get ngClassDirty(): boolean {
|
||||||
|
return isPresent(this._cd.control) ? this._cd.control.dirty : false;
|
||||||
|
}
|
||||||
|
get ngClassValid(): boolean {
|
||||||
|
return isPresent(this._cd.control) ? this._cd.control.valid : false;
|
||||||
}
|
}
|
||||||
get ngClassDirty(): boolean { return isPresent(this.cd.control) ? this.cd.control.dirty : false; }
|
|
||||||
get ngClassValid(): boolean { return isPresent(this.cd.control) ? this.cd.control.valid : false; }
|
|
||||||
get ngClassInvalid(): boolean {
|
get ngClassInvalid(): boolean {
|
||||||
return isPresent(this.cd.control) ? !this.cd.control.valid : false;
|
return isPresent(this._cd.control) ? !this._cd.control.valid : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
registerOnChange(fn: () => any): void { this.onChange = fn; }
|
registerOnChange(fn: () => any): void { this.onChange = fn; }
|
||||||
|
|
|
@ -191,7 +191,7 @@ export class PathRecognizer {
|
||||||
specificity: number;
|
specificity: number;
|
||||||
terminal: boolean = true;
|
terminal: boolean = true;
|
||||||
hash: string;
|
hash: string;
|
||||||
private cache: Map<string, ComponentInstruction> = new Map<string, ComponentInstruction>();
|
private _cache: Map<string, ComponentInstruction> = new Map<string, ComponentInstruction>();
|
||||||
|
|
||||||
|
|
||||||
// TODO: cache component instruction instances by params and by ParsedUrl instance
|
// TODO: cache component instruction instances by params and by ParsedUrl instance
|
||||||
|
@ -299,11 +299,11 @@ export class PathRecognizer {
|
||||||
private _getInstruction(urlPath: string, urlParams: string[], _recognizer: PathRecognizer,
|
private _getInstruction(urlPath: string, urlParams: string[], _recognizer: PathRecognizer,
|
||||||
params: StringMap<string, any>): ComponentInstruction {
|
params: StringMap<string, any>): ComponentInstruction {
|
||||||
var hashKey = urlPath + '?' + urlParams.join('?');
|
var hashKey = urlPath + '?' + urlParams.join('?');
|
||||||
if (this.cache.has(hashKey)) {
|
if (this._cache.has(hashKey)) {
|
||||||
return this.cache.get(hashKey);
|
return this._cache.get(hashKey);
|
||||||
}
|
}
|
||||||
var instruction = new ComponentInstruction(urlPath, urlParams, _recognizer, params);
|
var instruction = new ComponentInstruction(urlPath, urlParams, _recognizer, params);
|
||||||
this.cache.set(hashKey, instruction);
|
this._cache.set(hashKey, instruction);
|
||||||
|
|
||||||
return instruction;
|
return instruction;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,19 +74,19 @@ function matchUrlSegment(str: string): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UrlParser {
|
export class UrlParser {
|
||||||
private remaining: string;
|
private _remaining: string;
|
||||||
|
|
||||||
peekStartsWith(str: string): boolean { return this.remaining.startsWith(str); }
|
peekStartsWith(str: string): boolean { return this._remaining.startsWith(str); }
|
||||||
|
|
||||||
capture(str: string): void {
|
capture(str: string): void {
|
||||||
if (!this.remaining.startsWith(str)) {
|
if (!this._remaining.startsWith(str)) {
|
||||||
throw new BaseException(`Expected "${str}".`);
|
throw new BaseException(`Expected "${str}".`);
|
||||||
}
|
}
|
||||||
this.remaining = this.remaining.substring(str.length);
|
this._remaining = this._remaining.substring(str.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
parse(url: string): Url {
|
parse(url: string): Url {
|
||||||
this.remaining = url;
|
this._remaining = url;
|
||||||
if (url == '' || url == '/') {
|
if (url == '' || url == '/') {
|
||||||
return new Url('');
|
return new Url('');
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ export class UrlParser {
|
||||||
if (this.peekStartsWith('/')) {
|
if (this.peekStartsWith('/')) {
|
||||||
this.capture('/');
|
this.capture('/');
|
||||||
}
|
}
|
||||||
var path = matchUrlSegment(this.remaining);
|
var path = matchUrlSegment(this._remaining);
|
||||||
this.capture(path);
|
this.capture(path);
|
||||||
|
|
||||||
var aux = [];
|
var aux = [];
|
||||||
|
@ -123,13 +123,13 @@ export class UrlParser {
|
||||||
|
|
||||||
// segment + (matrix params) + (aux segments)
|
// segment + (matrix params) + (aux segments)
|
||||||
parseSegment(): Url {
|
parseSegment(): Url {
|
||||||
if (this.remaining.length == 0) {
|
if (this._remaining.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (this.peekStartsWith('/')) {
|
if (this.peekStartsWith('/')) {
|
||||||
this.capture('/');
|
this.capture('/');
|
||||||
}
|
}
|
||||||
var path = matchUrlSegment(this.remaining);
|
var path = matchUrlSegment(this._remaining);
|
||||||
this.capture(path);
|
this.capture(path);
|
||||||
|
|
||||||
var matrixParams = null;
|
var matrixParams = null;
|
||||||
|
@ -152,7 +152,7 @@ export class UrlParser {
|
||||||
var params = {};
|
var params = {};
|
||||||
this.capture('?');
|
this.capture('?');
|
||||||
this.parseParam(params);
|
this.parseParam(params);
|
||||||
while (this.remaining.length > 0 && this.peekStartsWith('&')) {
|
while (this._remaining.length > 0 && this.peekStartsWith('&')) {
|
||||||
this.capture('&');
|
this.capture('&');
|
||||||
this.parseParam(params);
|
this.parseParam(params);
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ export class UrlParser {
|
||||||
|
|
||||||
parseMatrixParams(): StringMap<string, any> {
|
parseMatrixParams(): StringMap<string, any> {
|
||||||
var params = {};
|
var params = {};
|
||||||
while (this.remaining.length > 0 && this.peekStartsWith(';')) {
|
while (this._remaining.length > 0 && this.peekStartsWith(';')) {
|
||||||
this.capture(';');
|
this.capture(';');
|
||||||
this.parseParam(params);
|
this.parseParam(params);
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ export class UrlParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
parseParam(params: StringMap<string, any>): void {
|
parseParam(params: StringMap<string, any>): void {
|
||||||
var key = matchUrlSegment(this.remaining);
|
var key = matchUrlSegment(this._remaining);
|
||||||
if (isBlank(key)) {
|
if (isBlank(key)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ export class UrlParser {
|
||||||
var value: any = true;
|
var value: any = true;
|
||||||
if (this.peekStartsWith('=')) {
|
if (this.peekStartsWith('=')) {
|
||||||
this.capture('=');
|
this.capture('=');
|
||||||
var valueMatch = matchUrlSegment(this.remaining);
|
var valueMatch = matchUrlSegment(this._remaining);
|
||||||
if (isPresent(valueMatch)) {
|
if (isPresent(valueMatch)) {
|
||||||
value = valueMatch;
|
value = valueMatch;
|
||||||
this.capture(value);
|
this.capture(value);
|
||||||
|
@ -191,7 +191,7 @@ export class UrlParser {
|
||||||
var routes = [];
|
var routes = [];
|
||||||
this.capture('(');
|
this.capture('(');
|
||||||
|
|
||||||
while (!this.peekStartsWith(')') && this.remaining.length > 0) {
|
while (!this.peekStartsWith(')') && this._remaining.length > 0) {
|
||||||
routes.push(this.parseSegment());
|
routes.push(this.parseSegment());
|
||||||
if (this.peekStartsWith('//')) {
|
if (this.peekStartsWith('//')) {
|
||||||
this.capture('//');
|
this.capture('//');
|
||||||
|
|
|
@ -49,8 +49,8 @@ export function main() {
|
||||||
|
|
||||||
@Directive({selector: '[lifecycle-dir]', lifecycle: [LifecycleEvent.DoCheck]})
|
@Directive({selector: '[lifecycle-dir]', lifecycle: [LifecycleEvent.DoCheck]})
|
||||||
class LifecycleDir {
|
class LifecycleDir {
|
||||||
constructor(private log: Log) {}
|
constructor(private _log: Log) {}
|
||||||
doCheck() { this.log.add("child_doCheck"); }
|
doCheck() { this._log.add("child_doCheck"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -69,21 +69,21 @@ class LifecycleDir {
|
||||||
@View({template: `<div lifecycle-dir></div>`, directives: [LifecycleDir]})
|
@View({template: `<div lifecycle-dir></div>`, directives: [LifecycleDir]})
|
||||||
class LifecycleCmp {
|
class LifecycleCmp {
|
||||||
field;
|
field;
|
||||||
constructor(private log: Log) {}
|
constructor(private _log: Log) {}
|
||||||
|
|
||||||
onChanges(_) { this.log.add("onChanges"); }
|
onChanges(_) { this._log.add("onChanges"); }
|
||||||
|
|
||||||
onInit() { this.log.add("onInit"); }
|
onInit() { this._log.add("onInit"); }
|
||||||
|
|
||||||
doCheck() { this.log.add("doCheck"); }
|
doCheck() { this._log.add("doCheck"); }
|
||||||
|
|
||||||
afterContentInit() { this.log.add("afterContentInit"); }
|
afterContentInit() { this._log.add("afterContentInit"); }
|
||||||
|
|
||||||
afterContentChecked() { this.log.add("afterContentChecked"); }
|
afterContentChecked() { this._log.add("afterContentChecked"); }
|
||||||
|
|
||||||
afterViewInit() { this.log.add("afterViewInit"); }
|
afterViewInit() { this._log.add("afterViewInit"); }
|
||||||
|
|
||||||
afterViewChecked() { this.log.add("afterViewChecked"); }
|
afterViewChecked() { this._log.add("afterViewChecked"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: 'my-comp'})
|
@Component({selector: 'my-comp'})
|
||||||
|
|
|
@ -217,16 +217,16 @@ export function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MockStep implements CompileStep {
|
export class MockStep implements CompileStep {
|
||||||
constructor(private processElementClosure: Function,
|
constructor(private _processElementClosure: Function,
|
||||||
private processStyleClosure: Function = null) {}
|
private _processStyleClosure: Function = null) {}
|
||||||
processElement(parent: CompileElement, current: CompileElement, control: CompileControl) {
|
processElement(parent: CompileElement, current: CompileElement, control: CompileControl) {
|
||||||
if (isPresent(this.processElementClosure)) {
|
if (isPresent(this._processElementClosure)) {
|
||||||
this.processElementClosure(parent, current, control);
|
this._processElementClosure(parent, current, control);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
processStyle(style: string): string {
|
processStyle(style: string): string {
|
||||||
if (isPresent(this.processStyleClosure)) {
|
if (isPresent(this._processStyleClosure)) {
|
||||||
return this.processStyleClosure(style);
|
return this._processStyleClosure(style);
|
||||||
} else {
|
} else {
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,9 +33,9 @@ class OrderItem {
|
||||||
|
|
||||||
class Order {
|
class Order {
|
||||||
constructor(public orderId: number, public customerName: string, public limit: number,
|
constructor(public orderId: number, public customerName: string, public limit: number,
|
||||||
private dataService: DataService) {}
|
private _dataService: DataService) {}
|
||||||
|
|
||||||
get items(): OrderItem[] { return this.dataService.itemsFor(this); }
|
get items(): OrderItem[] { return this._dataService.itemsFor(this); }
|
||||||
get total(): number { return this.items.map(i => i.total).reduce((a, b) => a + b); }
|
get total(): number { return this.items.map(i => i.total).reduce((a, b) => a + b); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,8 +113,8 @@ class DataService {
|
||||||
class OrderListComponent {
|
class OrderListComponent {
|
||||||
orders: Order[];
|
orders: Order[];
|
||||||
|
|
||||||
constructor(private service: DataService) { this.orders = service.orders; }
|
constructor(private _service: DataService) { this.orders = _service.orders; }
|
||||||
select(order: Order): void { this.service.currentOrder = order; }
|
select(order: Order): void { this._service.currentOrder = order; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -182,13 +182,13 @@ class OrderItemComponent {
|
||||||
directives: [FORM_DIRECTIVES, OrderItemComponent, NgFor, NgIf]
|
directives: [FORM_DIRECTIVES, OrderItemComponent, NgFor, NgIf]
|
||||||
})
|
})
|
||||||
class OrderDetailsComponent {
|
class OrderDetailsComponent {
|
||||||
constructor(private service: DataService) {}
|
constructor(private _service: DataService) {}
|
||||||
|
|
||||||
get order(): Order { return this.service.currentOrder; }
|
get order(): Order { return this._service.currentOrder; }
|
||||||
|
|
||||||
deleteItem(item: OrderItem): void { this.service.deleteItem(item); }
|
deleteItem(item: OrderItem): void { this._service.deleteItem(item); }
|
||||||
|
|
||||||
addItem(): void { this.service.addItemForOrder(this.order); }
|
addItem(): void { this._service.addItemForOrder(this.order); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: 'order-management-app', viewBindings: [DataService]})
|
@Component({selector: 'order-management-app', viewBindings: [DataService]})
|
||||||
|
|
|
@ -115,8 +115,8 @@ class DataService {
|
||||||
directives: [FORM_DIRECTIVES]
|
directives: [FORM_DIRECTIVES]
|
||||||
})
|
})
|
||||||
class FullNameComponent {
|
class FullNameComponent {
|
||||||
constructor(private service: DataService) {}
|
constructor(private _service: DataService) {}
|
||||||
get person(): Person { return this.service.currentPerson; }
|
get person(): Person { return this._service.currentPerson; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: 'person-detail-cmp'})
|
@Component({selector: 'person-detail-cmp'})
|
||||||
|
@ -163,8 +163,8 @@ class FullNameComponent {
|
||||||
directives: [FORM_DIRECTIVES, NgIf]
|
directives: [FORM_DIRECTIVES, NgIf]
|
||||||
})
|
})
|
||||||
class PersonsDetailComponent {
|
class PersonsDetailComponent {
|
||||||
constructor(private service: DataService) {}
|
constructor(private _service: DataService) {}
|
||||||
get person(): Person { return this.service.currentPerson; }
|
get person(): Person { return this._service.currentPerson; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: 'persons-cmp'})
|
@Component({selector: 'persons-cmp'})
|
||||||
|
@ -186,9 +186,9 @@ class PersonsDetailComponent {
|
||||||
class PersonsComponent {
|
class PersonsComponent {
|
||||||
persons: Person[];
|
persons: Person[];
|
||||||
|
|
||||||
constructor(private service: DataService) { this.persons = service.persons; }
|
constructor(private _service: DataService) { this.persons = _service.persons; }
|
||||||
|
|
||||||
select(person: Person): void { this.service.currentPerson = person; }
|
select(person: Person): void { this._service.currentPerson = person; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue