Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,17 @@ if (${TEMP_LOCAL} instanceof ContextWithVariableBindings) {
`;
}

function invokeMethodTemplate(name:string, args:string, context:string, newValue:string) {
return `
${TEMP_LOCAL} = ${UTIL}.findContext("${name}", ${context});
if (${TEMP_LOCAL} instanceof ContextWithVariableBindings) {
${newValue} = ${TEMP_LOCAL}.get('${name}').apply(null, [${args}]);
} else {
${newValue} = ${context}.${name}(${args});
}
`;
}

function localDefinitionsTemplate(names:List):string {
return names.map((n) => `var ${n};`).join("\n");
}
Expand Down Expand Up @@ -366,7 +377,11 @@ export class ChangeDetectorJITGenerator {
}

case RECORD_TYPE_INVOKE_METHOD:
return assignmentTemplate(newValue, `${context}.${r.name}(${args})`);
if (r.contextIndex == 0) { // only the first property read can be a local
return invokeMethodTemplate(r.name, args, context, newValue);
} else {
return assignmentTemplate(newValue, `${context}.${r.name}(${args})`);
}

case RECORD_TYPE_INVOKE_CLOSURE:
return assignmentTemplate(newValue, `${context}(${args})`);
Expand Down
12 changes: 10 additions & 2 deletions modules/angular2/src/change_detection/dynamic_change_detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,16 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
break;

case RECORD_TYPE_INVOKE_METHOD:
var methodInvoker:Function = proto.funcOrValue;
return methodInvoker(this._readContext(proto), this._readArgs(proto));
var context = this._readContext(proto);
var args = this._readArgs(proto);
var c = ChangeDetectionUtil.findContext(proto.name, context);
if (c instanceof ContextWithVariableBindings) {
return FunctionWrapper.apply(c.get(proto.name), args);
} else {
var methodInvoker:Function = proto.funcOrValue;
return methodInvoker(c, args);
}
break;

case RECORD_TYPE_KEYED_ACCESS:
var arg = this._readArgs(proto)[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ export function main() {
.toEqual(['key=value']);
});

it('should invoke a function from ContextWithVariableBindings', () => {
var locals = new ContextWithVariableBindings(null,
MapWrapper.createFromPairs([["key", () => "value"]]));

expect(executeWatch('key', 'key()', locals))
.toEqual(['key=value']);
});

it('should handle nested ContextWithVariableBindings', () => {
var nested = new ContextWithVariableBindings(null,
MapWrapper.createFromPairs([["key", "value"]]));
Expand Down