refactor(change_detector): made change detection responsible for processing events
Closes #3666
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {BaseException, Json} from 'angular2/src/facade/lang';
|
||||
import {CodegenNameUtil} from './codegen_name_util';
|
||||
import {codify, combineGeneratedStrings} from './codegen_facade';
|
||||
import {codify, combineGeneratedStrings, rawString} from './codegen_facade';
|
||||
import {ProtoRecord, RecordType} from './proto_record';
|
||||
|
||||
/**
|
||||
@@ -12,14 +12,28 @@ export class CodegenLogicUtil {
|
||||
|
||||
/**
|
||||
* Generates a statement which updates the local variable representing `protoRec` with the current
|
||||
* value of the record.
|
||||
* value of the record. Used by property bindings.
|
||||
*/
|
||||
genUpdateCurrentValue(protoRec: ProtoRecord): string {
|
||||
genPropertyBindingEvalValue(protoRec: ProtoRecord): string {
|
||||
return this.genEvalValue(protoRec, idx => this._names.getLocalName(idx),
|
||||
this._names.getLocalsAccessorName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a statement which updates the local variable representing `protoRec` with the current
|
||||
* value of the record. Used by event bindings.
|
||||
*/
|
||||
genEventBindingEvalValue(eventRecord: any, protoRec: ProtoRecord): string {
|
||||
return this.genEvalValue(protoRec, idx => this._names.getEventLocalName(eventRecord, idx),
|
||||
"locals");
|
||||
}
|
||||
|
||||
private genEvalValue(protoRec: ProtoRecord, getLocalName: Function,
|
||||
localsAccessor: string): string {
|
||||
var context = (protoRec.contextIndex == -1) ?
|
||||
this._names.getDirectiveName(protoRec.directiveIndex) :
|
||||
this._names.getLocalName(protoRec.contextIndex);
|
||||
var argString =
|
||||
ListWrapper.map(protoRec.args, (arg) => this._names.getLocalName(arg)).join(", ");
|
||||
getLocalName(protoRec.contextIndex);
|
||||
var argString = ListWrapper.map(protoRec.args, (arg) => getLocalName(arg)).join(", ");
|
||||
|
||||
var rhs: string;
|
||||
switch (protoRec.mode) {
|
||||
@@ -31,7 +45,7 @@ export class CodegenLogicUtil {
|
||||
rhs = codify(protoRec.funcOrValue);
|
||||
break;
|
||||
|
||||
case RecordType.PROPERTY:
|
||||
case RecordType.PROPERTY_READ:
|
||||
rhs = `${context}.${protoRec.name}`;
|
||||
break;
|
||||
|
||||
@@ -39,8 +53,12 @@ export class CodegenLogicUtil {
|
||||
rhs = `${this._utilName}.isValueBlank(${context}) ? null : ${context}.${protoRec.name}`;
|
||||
break;
|
||||
|
||||
case RecordType.PROPERTY_WRITE:
|
||||
rhs = `${context}.${protoRec.name} = ${getLocalName(protoRec.args[0])}`;
|
||||
break;
|
||||
|
||||
case RecordType.LOCAL:
|
||||
rhs = `${this._names.getLocalsAccessorName()}.get('${protoRec.name}')`;
|
||||
rhs = `${localsAccessor}.get(${rawString(protoRec.name)})`;
|
||||
break;
|
||||
|
||||
case RecordType.INVOKE_METHOD:
|
||||
@@ -68,16 +86,25 @@ export class CodegenLogicUtil {
|
||||
rhs = this._genInterpolation(protoRec);
|
||||
break;
|
||||
|
||||
case RecordType.KEYED_ACCESS:
|
||||
rhs = `${context}[${this._names.getLocalName(protoRec.args[0])}]`;
|
||||
case RecordType.KEYED_READ:
|
||||
rhs = `${context}[${getLocalName(protoRec.args[0])}]`;
|
||||
break;
|
||||
|
||||
case RecordType.KEYED_WRITE:
|
||||
rhs = `${context}[${getLocalName(protoRec.args[0])}] = ${getLocalName(protoRec.args[1])}`;
|
||||
break;
|
||||
|
||||
case RecordType.CHAIN:
|
||||
rhs = 'null';
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new BaseException(`Unknown operation ${protoRec.mode}`);
|
||||
}
|
||||
return `${this._names.getLocalName(protoRec.selfIndex)} = ${rhs};`;
|
||||
return `${getLocalName(protoRec.selfIndex)} = ${rhs};`;
|
||||
}
|
||||
|
||||
|
||||
_genInterpolation(protoRec: ProtoRecord): string {
|
||||
var iVals = [];
|
||||
for (var i = 0; i < protoRec.args.length; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user