refactor(view): separate context and locals
This commit is contained in:
parent
70c875ee14
commit
a16954d3a5
|
@ -1,8 +1,8 @@
|
||||||
export {AST} from './src/change_detection/parser/ast';
|
export {AST} from './src/change_detection/parser/ast';
|
||||||
export {Lexer} from './src/change_detection/parser/lexer';
|
export {Lexer} from './src/change_detection/parser/lexer';
|
||||||
export {Parser} from './src/change_detection/parser/parser';
|
export {Parser} from './src/change_detection/parser/parser';
|
||||||
export {ContextWithVariableBindings}
|
export {Locals}
|
||||||
from './src/change_detection/parser/context_with_variable_bindings';
|
from './src/change_detection/parser/locals';
|
||||||
export {ExpressionChangedAfterItHasBeenChecked, ChangeDetectionError}
|
export {ExpressionChangedAfterItHasBeenChecked, ChangeDetectionError}
|
||||||
from './src/change_detection/exceptions';
|
from './src/change_detection/exceptions';
|
||||||
export {ChangeRecord, ChangeDispatcher, ChangeDetector,
|
export {ChangeRecord, ChangeDispatcher, ChangeDetector,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import {isPresent, isBlank, BaseException, Type} from 'angular2/src/facade/lang';
|
import {isPresent, isBlank, BaseException, Type} from 'angular2/src/facade/lang';
|
||||||
import {List, ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
import {List, ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
||||||
|
|
||||||
import {ContextWithVariableBindings} from './parser/context_with_variable_bindings';
|
|
||||||
import {AbstractChangeDetector} from './abstract_change_detector';
|
import {AbstractChangeDetector} from './abstract_change_detector';
|
||||||
import {ChangeDetectionUtil} from './change_detection_util';
|
import {ChangeDetectionUtil} from './change_detection_util';
|
||||||
|
|
||||||
|
@ -9,6 +8,7 @@ import {
|
||||||
ProtoRecord,
|
ProtoRecord,
|
||||||
RECORD_TYPE_SELF,
|
RECORD_TYPE_SELF,
|
||||||
RECORD_TYPE_PROPERTY,
|
RECORD_TYPE_PROPERTY,
|
||||||
|
RECORD_TYPE_LOCAL,
|
||||||
RECORD_TYPE_INVOKE_METHOD,
|
RECORD_TYPE_INVOKE_METHOD,
|
||||||
RECORD_TYPE_CONST,
|
RECORD_TYPE_CONST,
|
||||||
RECORD_TYPE_INVOKE_CLOSURE,
|
RECORD_TYPE_INVOKE_CLOSURE,
|
||||||
|
@ -44,13 +44,7 @@ import {
|
||||||
* var temp;
|
* var temp;
|
||||||
* var context = this.context;
|
* var context = this.context;
|
||||||
*
|
*
|
||||||
* temp = ChangeDetectionUtil.findContext("address", context);
|
* address0 = context.address;
|
||||||
* if (temp instanceof ContextWithVariableBindings) {
|
|
||||||
* address0 = temp.get('address');
|
|
||||||
* } else {
|
|
||||||
* address0 = temp.address;
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* if (address0 !== this.address0) {
|
* if (address0 !== this.address0) {
|
||||||
* this.address0 = address0;
|
* this.address0 = address0;
|
||||||
* }
|
* }
|
||||||
|
@ -70,14 +64,16 @@ import {
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* ChangeDetector0.prototype.hydrate = function(context) {
|
* ChangeDetector0.prototype.hydrate = function(context, locals) {
|
||||||
* this.context = context;
|
* this.context = context;
|
||||||
|
* this.locals = locals;
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* ChangeDetector0.prototype.dehydrate = function(context) {
|
* ChangeDetector0.prototype.dehydrate = function(context) {
|
||||||
* this.context = ChangeDetectionUtil.unitialized();
|
* this.context = ChangeDetectionUtil.unitialized();
|
||||||
* this.address0 = ChangeDetectionUtil.unitialized();
|
* this.address0 = ChangeDetectionUtil.unitialized();
|
||||||
* this.city1 = ChangeDetectionUtil.unitialized();
|
* this.city1 = ChangeDetectionUtil.unitialized();
|
||||||
|
* this.locals = null;
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* ChangeDetector0.prototype.hydrated = function() {
|
* ChangeDetector0.prototype.hydrated = function() {
|
||||||
|
@ -99,8 +95,10 @@ var UTIL = "ChangeDetectionUtil";
|
||||||
var DISPATCHER_ACCESSOR = "this.dispatcher";
|
var DISPATCHER_ACCESSOR = "this.dispatcher";
|
||||||
var PIPE_REGISTRY_ACCESSOR = "this.pipeRegistry";
|
var PIPE_REGISTRY_ACCESSOR = "this.pipeRegistry";
|
||||||
var PROTOS_ACCESSOR = "this.protos";
|
var PROTOS_ACCESSOR = "this.protos";
|
||||||
|
var CONTEXT_ACCESSOR = "this.context";
|
||||||
var CHANGE_LOCAL = "change";
|
var CHANGE_LOCAL = "change";
|
||||||
var CHANGES_LOCAL = "changes";
|
var CHANGES_LOCAL = "changes";
|
||||||
|
var LOCALS_ACCESSOR = "this.locals";
|
||||||
var TEMP_LOCAL = "temp";
|
var TEMP_LOCAL = "temp";
|
||||||
|
|
||||||
function typeTemplate(type:string, cons:string, detectChanges:string, setContext:string):string {
|
function typeTemplate(type:string, cons:string, detectChanges:string, setContext:string):string {
|
||||||
|
@ -135,15 +133,17 @@ function pipeOnDestroyTemplate(pipeNames:List) {
|
||||||
|
|
||||||
function hydrateTemplate(type:string, fieldsDefinitions:string, pipeOnDestroy:string):string {
|
function hydrateTemplate(type:string, fieldsDefinitions:string, pipeOnDestroy:string):string {
|
||||||
return `
|
return `
|
||||||
${type}.prototype.hydrate = function(context) {
|
${type}.prototype.hydrate = function(context, locals) {
|
||||||
this.context = context;
|
${CONTEXT_ACCESSOR} = context;
|
||||||
|
${LOCALS_ACCESSOR} = locals;
|
||||||
}
|
}
|
||||||
${type}.prototype.dehydrate = function() {
|
${type}.prototype.dehydrate = function() {
|
||||||
${pipeOnDestroy}
|
${pipeOnDestroy}
|
||||||
${fieldsDefinitions}
|
${fieldsDefinitions}
|
||||||
|
${LOCALS_ACCESSOR} = null;
|
||||||
}
|
}
|
||||||
${type}.prototype.hydrated = function() {
|
${type}.prototype.hydrated = function() {
|
||||||
return this.context !== ${UTIL}.unitialized();
|
return ${CONTEXT_ACCESSOR} !== ${UTIL}.unitialized();
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ var ${TEMP_LOCAL};
|
||||||
var ${CHANGE_LOCAL};
|
var ${CHANGE_LOCAL};
|
||||||
var ${CHANGES_LOCAL} = null;
|
var ${CHANGES_LOCAL} = null;
|
||||||
|
|
||||||
context = this.context;
|
context = ${CONTEXT_ACCESSOR};
|
||||||
${records}
|
${records}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@ -216,17 +216,6 @@ function assignmentTemplate(field:string, value:string) {
|
||||||
return `${field} = ${value};`;
|
return `${field} = ${value};`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function propertyReadTemplate(name:string, context:string, newValue:string) {
|
|
||||||
return `
|
|
||||||
${TEMP_LOCAL} = ${UTIL}.findContext("${name}", ${context});
|
|
||||||
if (${TEMP_LOCAL} instanceof ContextWithVariableBindings) {
|
|
||||||
${newValue} = ${TEMP_LOCAL}.get('${name}');
|
|
||||||
} else {
|
|
||||||
${newValue} = ${TEMP_LOCAL}.${name};
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function invokeMethodTemplate(name:string, args:string, context:string, newValue:string) {
|
function invokeMethodTemplate(name:string, args:string, context:string, newValue:string) {
|
||||||
return `
|
return `
|
||||||
${TEMP_LOCAL} = ${UTIL}.findContext("${name}", ${context});
|
${TEMP_LOCAL} = ${UTIL}.findContext("${name}", ${context});
|
||||||
|
@ -306,7 +295,7 @@ export class ChangeDetectorJITGenerator {
|
||||||
|
|
||||||
generate():Function {
|
generate():Function {
|
||||||
var text = typeTemplate(this.typeName, this.genConstructor(), this.genDetectChanges(), this.genHydrate());
|
var text = typeTemplate(this.typeName, this.genConstructor(), this.genDetectChanges(), this.genHydrate());
|
||||||
return new Function('AbstractChangeDetector', 'ChangeDetectionUtil', 'ContextWithVariableBindings', 'protos', text)(AbstractChangeDetector, ChangeDetectionUtil, ContextWithVariableBindings, this.records);
|
return new Function('AbstractChangeDetector', 'ChangeDetectionUtil', 'protos', text)(AbstractChangeDetector, ChangeDetectionUtil, this.records);
|
||||||
}
|
}
|
||||||
|
|
||||||
genConstructor():string {
|
genConstructor():string {
|
||||||
|
@ -403,18 +392,13 @@ export class ChangeDetectorJITGenerator {
|
||||||
return `${newValue} = ${this.genLiteral(r.funcOrValue)}`;
|
return `${newValue} = ${this.genLiteral(r.funcOrValue)}`;
|
||||||
|
|
||||||
case RECORD_TYPE_PROPERTY:
|
case RECORD_TYPE_PROPERTY:
|
||||||
if (r.contextIndex == 0) { // only the first property read can be a local
|
return assignmentTemplate(newValue, `${context}.${r.name}`);
|
||||||
return propertyReadTemplate(r.name, context, newValue);
|
|
||||||
} else {
|
case RECORD_TYPE_LOCAL:
|
||||||
return assignmentTemplate(newValue, `${context}.${r.name}`);
|
return assignmentTemplate(newValue, `${LOCALS_ACCESSOR}.get('${r.name}')`);
|
||||||
}
|
|
||||||
|
|
||||||
case RECORD_TYPE_INVOKE_METHOD:
|
case RECORD_TYPE_INVOKE_METHOD:
|
||||||
if (r.contextIndex == 0) { // only the first property read can be a local
|
return assignmentTemplate(newValue, `${context}.${r.name}(${args})`);
|
||||||
return invokeMethodTemplate(r.name, args, context, newValue);
|
|
||||||
} else {
|
|
||||||
return assignmentTemplate(newValue, `${context}.${r.name}(${args})`);
|
|
||||||
}
|
|
||||||
|
|
||||||
case RECORD_TYPE_INVOKE_CLOSURE:
|
case RECORD_TYPE_INVOKE_CLOSURE:
|
||||||
return assignmentTemplate(newValue, `${context}(${args})`);
|
return assignmentTemplate(newValue, `${context}(${args})`);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import {isPresent, isBlank, BaseException, Type} from 'angular2/src/facade/lang';
|
import {isPresent, isBlank, BaseException, Type} from 'angular2/src/facade/lang';
|
||||||
import {List, ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
import {List, ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
||||||
import {ContextWithVariableBindings} from './parser/context_with_variable_bindings';
|
|
||||||
import {ProtoRecord} from './proto_record';
|
import {ProtoRecord} from './proto_record';
|
||||||
import {ExpressionChangedAfterItHasBeenChecked} from './exceptions';
|
import {ExpressionChangedAfterItHasBeenChecked} from './exceptions';
|
||||||
import {NO_CHANGE} from './pipes/pipe';
|
import {NO_CHANGE} from './pipes/pipe';
|
||||||
|
@ -144,16 +143,6 @@ export class ChangeDetectionUtil {
|
||||||
return obj[args[0]];
|
return obj[args[0]];
|
||||||
}
|
}
|
||||||
|
|
||||||
static findContext(name:string, c){
|
|
||||||
while (c instanceof ContextWithVariableBindings) {
|
|
||||||
if (c.hasBinding(name)) {
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
c = c.parent;
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
static noChangeMarker(value):boolean {
|
static noChangeMarker(value):boolean {
|
||||||
return value === NO_CHANGE;
|
return value === NO_CHANGE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import {isPresent, isBlank, BaseException, FunctionWrapper} from 'angular2/src/facade/lang';
|
import {isPresent, isBlank, BaseException, FunctionWrapper} from 'angular2/src/facade/lang';
|
||||||
import {List, ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
import {List, ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
||||||
import {ContextWithVariableBindings} from './parser/context_with_variable_bindings';
|
|
||||||
|
|
||||||
import {AbstractChangeDetector} from './abstract_change_detector';
|
import {AbstractChangeDetector} from './abstract_change_detector';
|
||||||
import {PipeRegistry} from './pipes/pipe_registry';
|
import {PipeRegistry} from './pipes/pipe_registry';
|
||||||
|
@ -11,6 +10,7 @@ import {
|
||||||
ProtoRecord,
|
ProtoRecord,
|
||||||
RECORD_TYPE_SELF,
|
RECORD_TYPE_SELF,
|
||||||
RECORD_TYPE_PROPERTY,
|
RECORD_TYPE_PROPERTY,
|
||||||
|
RECORD_TYPE_LOCAL,
|
||||||
RECORD_TYPE_INVOKE_METHOD,
|
RECORD_TYPE_INVOKE_METHOD,
|
||||||
RECORD_TYPE_CONST,
|
RECORD_TYPE_CONST,
|
||||||
RECORD_TYPE_INVOKE_CLOSURE,
|
RECORD_TYPE_INVOKE_CLOSURE,
|
||||||
|
@ -26,6 +26,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
|
||||||
dispatcher:any;
|
dispatcher:any;
|
||||||
pipeRegistry;
|
pipeRegistry;
|
||||||
|
|
||||||
|
locals:any;
|
||||||
values:List;
|
values:List;
|
||||||
changes:List;
|
changes:List;
|
||||||
pipes:List;
|
pipes:List;
|
||||||
|
@ -47,12 +48,14 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
|
||||||
ListWrapper.fill(this.pipes, null);
|
ListWrapper.fill(this.pipes, null);
|
||||||
ListWrapper.fill(this.prevContexts, uninitialized);
|
ListWrapper.fill(this.prevContexts, uninitialized);
|
||||||
ListWrapper.fill(this.changes, false);
|
ListWrapper.fill(this.changes, false);
|
||||||
|
this.locals = null;
|
||||||
|
|
||||||
this.protos = protoRecords;
|
this.protos = protoRecords;
|
||||||
}
|
}
|
||||||
|
|
||||||
hydrate(context:any) {
|
hydrate(context:any, locals:any) {
|
||||||
this.values[0] = context;
|
this.values[0] = context;
|
||||||
|
this.locals = locals;
|
||||||
}
|
}
|
||||||
|
|
||||||
dehydrate() {
|
dehydrate() {
|
||||||
|
@ -61,6 +64,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
|
||||||
ListWrapper.fill(this.changes, false);
|
ListWrapper.fill(this.changes, false);
|
||||||
ListWrapper.fill(this.pipes, null);
|
ListWrapper.fill(this.pipes, null);
|
||||||
ListWrapper.fill(this.prevContexts, uninitialized);
|
ListWrapper.fill(this.prevContexts, uninitialized);
|
||||||
|
this.locals = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_destroyPipes() {
|
_destroyPipes() {
|
||||||
|
@ -143,26 +147,15 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
|
||||||
|
|
||||||
case RECORD_TYPE_PROPERTY:
|
case RECORD_TYPE_PROPERTY:
|
||||||
var context = this._readContext(proto);
|
var context = this._readContext(proto);
|
||||||
var c = ChangeDetectionUtil.findContext(proto.name, context);
|
return proto.funcOrValue(context);
|
||||||
if (c instanceof ContextWithVariableBindings) {
|
|
||||||
return c.get(proto.name);
|
case RECORD_TYPE_LOCAL:
|
||||||
} else {
|
return this.locals.get(proto.name);
|
||||||
var propertyGetter:Function = proto.funcOrValue;
|
|
||||||
return propertyGetter(c);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RECORD_TYPE_INVOKE_METHOD:
|
case RECORD_TYPE_INVOKE_METHOD:
|
||||||
var context = this._readContext(proto);
|
var context = this._readContext(proto);
|
||||||
var args = this._readArgs(proto);
|
var args = this._readArgs(proto);
|
||||||
var c = ChangeDetectionUtil.findContext(proto.name, context);
|
return proto.funcOrValue(context, args);
|
||||||
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:
|
case RECORD_TYPE_KEYED_ACCESS:
|
||||||
var arg = this._readArgs(proto)[0];
|
var arg = this._readArgs(proto)[0];
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import {List} from 'angular2/src/facade/collection';
|
import {List} from 'angular2/src/facade/collection';
|
||||||
|
import {Locals} from './parser/locals';
|
||||||
|
|
||||||
export class ChangeRecord {
|
export class ChangeRecord {
|
||||||
bindingMemento:any;
|
bindingMemento:any;
|
||||||
|
@ -55,7 +56,7 @@ export class ChangeDetector {
|
||||||
addChild(cd:ChangeDetector) {}
|
addChild(cd:ChangeDetector) {}
|
||||||
removeChild(cd:ChangeDetector) {}
|
removeChild(cd:ChangeDetector) {}
|
||||||
remove() {}
|
remove() {}
|
||||||
hydrate(context:any) {}
|
hydrate(context:any, locals:Locals) {}
|
||||||
dehydrate() {}
|
dehydrate() {}
|
||||||
markPathToRootAsCheckOnce() {}
|
markPathToRootAsCheckOnce() {}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
import {autoConvertAdd, isBlank, isPresent, FunctionWrapper, BaseException} from "angular2/src/facade/lang";
|
import {autoConvertAdd, isBlank, isPresent, FunctionWrapper, BaseException} from "angular2/src/facade/lang";
|
||||||
import {List, Map, ListWrapper, StringMapWrapper} from "angular2/src/facade/collection";
|
import {List, Map, ListWrapper, StringMapWrapper} from "angular2/src/facade/collection";
|
||||||
import {ContextWithVariableBindings} from "./context_with_variable_bindings";
|
|
||||||
|
|
||||||
export class AST {
|
export class AST {
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
throw new BaseException("Not supported");
|
throw new BaseException("Not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +10,7 @@ export class AST {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
assign(context, value) {
|
assign(context, locals, value) {
|
||||||
throw new BaseException("Not supported");
|
throw new BaseException("Not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +23,7 @@ export class AST {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EmptyExpr extends AST {
|
export class EmptyExpr extends AST {
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +33,7 @@ export class EmptyExpr extends AST {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ImplicitReceiver extends AST {
|
export class ImplicitReceiver extends AST {
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,10 +52,10 @@ export class Chain extends AST {
|
||||||
this.expressions = expressions;
|
this.expressions = expressions;
|
||||||
}
|
}
|
||||||
|
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
var result;
|
var result;
|
||||||
for (var i = 0; i < this.expressions.length; i++) {
|
for (var i = 0; i < this.expressions.length; i++) {
|
||||||
var last = this.expressions[i].eval(context);
|
var last = this.expressions[i].eval(context, locals);
|
||||||
if (isPresent(last)) result = last;
|
if (isPresent(last)) result = last;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -78,11 +77,11 @@ export class Conditional extends AST {
|
||||||
this.falseExp = falseExp;
|
this.falseExp = falseExp;
|
||||||
}
|
}
|
||||||
|
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
if(this.condition.eval(context)) {
|
if(this.condition.eval(context, locals)) {
|
||||||
return this.trueExp.eval(context);
|
return this.trueExp.eval(context, locals);
|
||||||
} else {
|
} else {
|
||||||
return this.falseExp.eval(context);
|
return this.falseExp.eval(context, locals);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,34 +103,29 @@ export class AccessMember extends AST {
|
||||||
this.setter = setter;
|
this.setter = setter;
|
||||||
}
|
}
|
||||||
|
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
var evaluatedContext = this.receiver.eval(context);
|
if (this.receiver instanceof ImplicitReceiver &&
|
||||||
|
isPresent(locals) && locals.contains(this.name)) {
|
||||||
while (evaluatedContext instanceof ContextWithVariableBindings) {
|
return locals.get(this.name);
|
||||||
if (evaluatedContext.hasBinding(this.name)) {
|
} else {
|
||||||
return evaluatedContext.get(this.name);
|
var evaluatedReceiver = this.receiver.eval(context, locals);
|
||||||
}
|
return this.getter(evaluatedReceiver);
|
||||||
evaluatedContext = evaluatedContext.parent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.getter(evaluatedContext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get isAssignable() {
|
get isAssignable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
assign(context, value) {
|
assign(context, locals, value) {
|
||||||
var evaluatedContext = this.receiver.eval(context);
|
var evaluatedContext = this.receiver.eval(context, locals);
|
||||||
|
|
||||||
while (evaluatedContext instanceof ContextWithVariableBindings) {
|
if (this.receiver instanceof ImplicitReceiver &&
|
||||||
if (evaluatedContext.hasBinding(this.name)) {
|
isPresent(locals) && locals.contains(this.name)) {
|
||||||
throw new BaseException(`Cannot reassign a variable binding ${this.name}`)
|
throw new BaseException(`Cannot reassign a variable binding ${this.name}`);
|
||||||
}
|
} else {
|
||||||
evaluatedContext = evaluatedContext.parent;
|
return this.setter(evaluatedContext, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.setter(evaluatedContext, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
visit(visitor) {
|
visit(visitor) {
|
||||||
|
@ -148,9 +142,9 @@ export class KeyedAccess extends AST {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
var obj = this.obj.eval(context);
|
var obj = this.obj.eval(context, locals);
|
||||||
var key = this.key.eval(context);
|
var key = this.key.eval(context, locals);
|
||||||
return obj[key];
|
return obj[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,9 +152,9 @@ export class KeyedAccess extends AST {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
assign(context, value) {
|
assign(context, locals, value) {
|
||||||
var obj = this.obj.eval(context);
|
var obj = this.obj.eval(context, locals);
|
||||||
var key = this.key.eval(context);
|
var key = this.key.eval(context, locals);
|
||||||
obj[key] = value;
|
obj[key] = value;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -193,7 +187,7 @@ export class LiteralPrimitive extends AST {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,8 +203,8 @@ export class LiteralArray extends AST {
|
||||||
this.expressions = expressions;
|
this.expressions = expressions;
|
||||||
}
|
}
|
||||||
|
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
return ListWrapper.map(this.expressions, (e) => e.eval(context));
|
return ListWrapper.map(this.expressions, (e) => e.eval(context, locals));
|
||||||
}
|
}
|
||||||
|
|
||||||
visit(visitor) {
|
visit(visitor) {
|
||||||
|
@ -227,10 +221,10 @@ export class LiteralMap extends AST {
|
||||||
this.values = values;
|
this.values = values;
|
||||||
}
|
}
|
||||||
|
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
var res = StringMapWrapper.create();
|
var res = StringMapWrapper.create();
|
||||||
for(var i = 0; i < this.keys.length; ++i) {
|
for(var i = 0; i < this.keys.length; ++i) {
|
||||||
StringMapWrapper.set(res, this.keys[i], this.values[i].eval(context));
|
StringMapWrapper.set(res, this.keys[i], this.values[i].eval(context, locals));
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -249,7 +243,7 @@ export class Interpolation extends AST {
|
||||||
this.expressions = expressions;
|
this.expressions = expressions;
|
||||||
}
|
}
|
||||||
|
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
throw new BaseException("evaluating an Interpolation is not supported");
|
throw new BaseException("evaluating an Interpolation is not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,13 +263,13 @@ export class Binary extends AST {
|
||||||
this.right = right;
|
this.right = right;
|
||||||
}
|
}
|
||||||
|
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
var left = this.left.eval(context);
|
var left = this.left.eval(context, locals);
|
||||||
switch (this.operation) {
|
switch (this.operation) {
|
||||||
case '&&': return left && this.right.eval(context);
|
case '&&': return left && this.right.eval(context, locals);
|
||||||
case '||': return left || this.right.eval(context);
|
case '||': return left || this.right.eval(context, locals);
|
||||||
}
|
}
|
||||||
var right = this.right.eval(context);
|
var right = this.right.eval(context, locals);
|
||||||
|
|
||||||
switch (this.operation) {
|
switch (this.operation) {
|
||||||
case '+' : return left + right;
|
case '+' : return left + right;
|
||||||
|
@ -307,8 +301,8 @@ export class PrefixNot extends AST {
|
||||||
this.expression = expression;
|
this.expression = expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
return !this.expression.eval(context);
|
return !this.expression.eval(context, locals);
|
||||||
}
|
}
|
||||||
|
|
||||||
visit(visitor) {
|
visit(visitor) {
|
||||||
|
@ -325,8 +319,8 @@ export class Assignment extends AST {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
return this.target.assign(context, this.value.eval(context));
|
return this.target.assign(context, locals, this.value.eval(context, locals));
|
||||||
}
|
}
|
||||||
|
|
||||||
visit(visitor) {
|
visit(visitor) {
|
||||||
|
@ -347,19 +341,16 @@ export class MethodCall extends AST {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
var evaluatedContext = this.receiver.eval(context);
|
var evaluatedArgs = evalList(context, locals, this.args);
|
||||||
var evaluatedArgs = evalList(context, this.args);
|
if (this.receiver instanceof ImplicitReceiver &&
|
||||||
|
isPresent(locals) && locals.contains(this.name)) {
|
||||||
while (evaluatedContext instanceof ContextWithVariableBindings) {
|
var fn = locals.get(this.name);
|
||||||
if (evaluatedContext.hasBinding(this.name)) {
|
return FunctionWrapper.apply(fn, evaluatedArgs);
|
||||||
var fn = evaluatedContext.get(this.name);
|
} else {
|
||||||
return FunctionWrapper.apply(fn, evaluatedArgs);
|
var evaluatedReceiver = this.receiver.eval(context, locals);
|
||||||
}
|
return this.fn(evaluatedReceiver, evaluatedArgs);
|
||||||
evaluatedContext = evaluatedContext.parent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.fn(evaluatedContext, evaluatedArgs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
visit(visitor) {
|
visit(visitor) {
|
||||||
|
@ -376,12 +367,12 @@ export class FunctionCall extends AST {
|
||||||
this.args = args;
|
this.args = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
var obj = this.target.eval(context);
|
var obj = this.target.eval(context, locals);
|
||||||
if (! (obj instanceof Function)) {
|
if (! (obj instanceof Function)) {
|
||||||
throw new BaseException(`${obj} is not a function`);
|
throw new BaseException(`${obj} is not a function`);
|
||||||
}
|
}
|
||||||
return FunctionWrapper.apply(obj, evalList(context, this.args));
|
return FunctionWrapper.apply(obj, evalList(context, locals, this.args));
|
||||||
}
|
}
|
||||||
|
|
||||||
visit(visitor) {
|
visit(visitor) {
|
||||||
|
@ -400,16 +391,16 @@ export class ASTWithSource extends AST {
|
||||||
this.ast = ast;
|
this.ast = ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
eval(context) {
|
eval(context, locals) {
|
||||||
return this.ast.eval(context);
|
return this.ast.eval(context, locals);
|
||||||
}
|
}
|
||||||
|
|
||||||
get isAssignable() {
|
get isAssignable() {
|
||||||
return this.ast.isAssignable;
|
return this.ast.isAssignable;
|
||||||
}
|
}
|
||||||
|
|
||||||
assign(context, value) {
|
assign(context, locals, value) {
|
||||||
return this.ast.assign(context, value);
|
return this.ast.assign(context, locals, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
visit(visitor) {
|
visit(visitor) {
|
||||||
|
@ -454,12 +445,19 @@ export class AstVisitor {
|
||||||
visitPrefixNot(ast:PrefixNot) {}
|
visitPrefixNot(ast:PrefixNot) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _evalListCache = [[],[0],[0,0],[0,0,0],[0,0,0,0],[0,0,0,0,0]];
|
var _evalListCache = [[],[0],[0,0],[0,0,0],[0,0,0,0],[0,0,0,0,0],
|
||||||
function evalList(context, exps:List){
|
[0,0,0,0,0,0], [0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0],
|
||||||
|
[0,0,0,0,0,0,0,0,0]];
|
||||||
|
|
||||||
|
function evalList(context, locals, exps:List){
|
||||||
var length = exps.length;
|
var length = exps.length;
|
||||||
|
if (length > 10) {
|
||||||
|
throw new BaseException("Cannot have more than 10 argument");
|
||||||
|
}
|
||||||
|
|
||||||
var result = _evalListCache[length];
|
var result = _evalListCache[length];
|
||||||
for (var i = 0; i < length; i++) {
|
for (var i = 0; i < length; i++) {
|
||||||
result[i] = exps[i].eval(context);
|
result[i] = exps[i].eval(context, locals);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
import {MapWrapper} from 'angular2/src/facade/collection';
|
|
||||||
import {BaseException} from 'angular2/src/facade/lang';
|
|
||||||
|
|
||||||
export class ContextWithVariableBindings {
|
|
||||||
parent:any;
|
|
||||||
/// varBindings' keys are read-only. adding/removing keys is not supported.
|
|
||||||
varBindings:Map;
|
|
||||||
|
|
||||||
constructor(parent:any, varBindings:Map) {
|
|
||||||
this.parent = parent;
|
|
||||||
this.varBindings = varBindings;
|
|
||||||
}
|
|
||||||
|
|
||||||
hasBinding(name:string):boolean {
|
|
||||||
return MapWrapper.contains(this.varBindings, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
get(name:string) {
|
|
||||||
return MapWrapper.get(this.varBindings, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
set(name:string, value) {
|
|
||||||
// TODO(rado): consider removing this check if we can guarantee this is not
|
|
||||||
// exposed to the public API.
|
|
||||||
if (this.hasBinding(name)) {
|
|
||||||
MapWrapper.set(this.varBindings, name, value);
|
|
||||||
} else {
|
|
||||||
throw new BaseException(
|
|
||||||
'VariableBindings do not support setting of new keys post-construction.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
clearValues() {
|
|
||||||
MapWrapper.clearValues(this.varBindings);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
import {isPresent, BaseException} from 'angular2/src/facade/lang';
|
||||||
|
import {ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
|
||||||
|
|
||||||
|
export class Locals {
|
||||||
|
parent:Locals;
|
||||||
|
current:Map;
|
||||||
|
|
||||||
|
constructor(parent:Locals, current:Map) {
|
||||||
|
this.parent = parent;
|
||||||
|
this.current = current;
|
||||||
|
}
|
||||||
|
|
||||||
|
contains(name:string):boolean {
|
||||||
|
if (MapWrapper.contains(this.current, name)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPresent(this.parent)) {
|
||||||
|
return this.parent.contains(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
get(name:string) {
|
||||||
|
if (MapWrapper.contains(this.current, name)) {
|
||||||
|
return MapWrapper.get(this.current, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPresent(this.parent)) {
|
||||||
|
return this.parent.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new BaseException(`Cannot find '${name}'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
set(name:string, value) {
|
||||||
|
// TODO(rado): consider removing this check if we can guarantee this is not
|
||||||
|
// exposed to the public API.
|
||||||
|
// TODO: vsavkin maybe it should check only the local map
|
||||||
|
if (MapWrapper.contains(this.current, name)) {
|
||||||
|
MapWrapper.set(this.current, name, value);
|
||||||
|
} else {
|
||||||
|
throw new BaseException('Setting of new keys post-construction is not supported.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clearValues() {
|
||||||
|
MapWrapper.clearValues(this.current);
|
||||||
|
}
|
||||||
|
}
|
|
@ -34,6 +34,7 @@ import {
|
||||||
ProtoRecord,
|
ProtoRecord,
|
||||||
RECORD_TYPE_SELF,
|
RECORD_TYPE_SELF,
|
||||||
RECORD_TYPE_PROPERTY,
|
RECORD_TYPE_PROPERTY,
|
||||||
|
RECORD_TYPE_LOCAL,
|
||||||
RECORD_TYPE_INVOKE_METHOD,
|
RECORD_TYPE_INVOKE_METHOD,
|
||||||
RECORD_TYPE_CONST,
|
RECORD_TYPE_CONST,
|
||||||
RECORD_TYPE_INVOKE_CLOSURE,
|
RECORD_TYPE_INVOKE_CLOSURE,
|
||||||
|
@ -45,7 +46,7 @@ import {
|
||||||
|
|
||||||
export class ProtoChangeDetector {
|
export class ProtoChangeDetector {
|
||||||
addAst(ast:AST, bindingMemento:any, directiveMemento:any = null){}
|
addAst(ast:AST, bindingMemento:any, directiveMemento:any = null){}
|
||||||
instantiate(dispatcher:any, bindingRecords:List):ChangeDetector{
|
instantiate(dispatcher:any, bindingRecords:List, variableBindings:List):ChangeDetector{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,16 +72,16 @@ export class DynamicProtoChangeDetector extends ProtoChangeDetector {
|
||||||
this._pipeRegistry = pipeRegistry;
|
this._pipeRegistry = pipeRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
instantiate(dispatcher:any, bindingRecords:List) {
|
instantiate(dispatcher:any, bindingRecords:List, variableBindings:List) {
|
||||||
this._createRecordsIfNecessary(bindingRecords);
|
this._createRecordsIfNecessary(bindingRecords, variableBindings);
|
||||||
return new DynamicChangeDetector(dispatcher, this._pipeRegistry, this._records);
|
return new DynamicChangeDetector(dispatcher, this._pipeRegistry, this._records);
|
||||||
}
|
}
|
||||||
|
|
||||||
_createRecordsIfNecessary(bindingRecords:List) {
|
_createRecordsIfNecessary(bindingRecords:List, variableBindings:List) {
|
||||||
if (isBlank(this._records)) {
|
if (isBlank(this._records)) {
|
||||||
var recordBuilder = new ProtoRecordBuilder();
|
var recordBuilder = new ProtoRecordBuilder();
|
||||||
ListWrapper.forEach(bindingRecords, (r) => {
|
ListWrapper.forEach(bindingRecords, (r) => {
|
||||||
recordBuilder.addAst(r.ast, r.bindingMemento, r.directiveMemento);
|
recordBuilder.addAst(r.ast, r.bindingMemento, r.directiveMemento, variableBindings);
|
||||||
});
|
});
|
||||||
this._records = coalesce(recordBuilder.records);
|
this._records = coalesce(recordBuilder.records);
|
||||||
}
|
}
|
||||||
|
@ -98,16 +99,16 @@ export class JitProtoChangeDetector extends ProtoChangeDetector {
|
||||||
this._factory = null;
|
this._factory = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
instantiate(dispatcher:any, bindingRecords:List) {
|
instantiate(dispatcher:any, bindingRecords:List, variableBindings:List) {
|
||||||
this._createFactoryIfNecessary(bindingRecords);
|
this._createFactoryIfNecessary(bindingRecords, variableBindings);
|
||||||
return this._factory(dispatcher, this._pipeRegistry);
|
return this._factory(dispatcher, this._pipeRegistry);
|
||||||
}
|
}
|
||||||
|
|
||||||
_createFactoryIfNecessary(bindingRecords:List) {
|
_createFactoryIfNecessary(bindingRecords:List, variableBindings:List) {
|
||||||
if (isBlank(this._factory)) {
|
if (isBlank(this._factory)) {
|
||||||
var recordBuilder = new ProtoRecordBuilder();
|
var recordBuilder = new ProtoRecordBuilder();
|
||||||
ListWrapper.forEach(bindingRecords, (r) => {
|
ListWrapper.forEach(bindingRecords, (r) => {
|
||||||
recordBuilder.addAst(r.ast, r.bindingMemento, r.directiveMemento);
|
recordBuilder.addAst(r.ast, r.bindingMemento, r.directiveMemento, variableBindings);
|
||||||
});
|
});
|
||||||
var c = _jitProtoChangeDetectorClassCounter++;
|
var c = _jitProtoChangeDetectorClassCounter++;
|
||||||
var records = coalesce(recordBuilder.records);
|
var records = coalesce(recordBuilder.records);
|
||||||
|
@ -124,13 +125,13 @@ class ProtoRecordBuilder {
|
||||||
this.records = [];
|
this.records = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
addAst(ast:AST, bindingMemento:any, directiveMemento:any = null) {
|
addAst(ast:AST, bindingMemento:any, directiveMemento:any = null, variableBindings:List = null) {
|
||||||
var last = ListWrapper.last(this.records);
|
var last = ListWrapper.last(this.records);
|
||||||
if (isPresent(last) && last.directiveMemento == directiveMemento) {
|
if (isPresent(last) && last.directiveMemento == directiveMemento) {
|
||||||
last.lastInDirective = false;
|
last.lastInDirective = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pr = _ConvertAstIntoProtoRecords.convert(ast, bindingMemento, directiveMemento, this.records.length);
|
var pr = _ConvertAstIntoProtoRecords.convert(ast, bindingMemento, directiveMemento, this.records.length, variableBindings);
|
||||||
if (! ListWrapper.isEmpty(pr)) {
|
if (! ListWrapper.isEmpty(pr)) {
|
||||||
var last = ListWrapper.last(pr);
|
var last = ListWrapper.last(pr);
|
||||||
last.lastInBinding = true;
|
last.lastInBinding = true;
|
||||||
|
@ -145,19 +146,21 @@ class _ConvertAstIntoProtoRecords {
|
||||||
protoRecords:List;
|
protoRecords:List;
|
||||||
bindingMemento:any;
|
bindingMemento:any;
|
||||||
directiveMemento:any;
|
directiveMemento:any;
|
||||||
|
variableBindings:List;
|
||||||
contextIndex:number;
|
contextIndex:number;
|
||||||
expressionAsString:string;
|
expressionAsString:string;
|
||||||
|
|
||||||
constructor(bindingMemento:any, directiveMemento:any, contextIndex:number, expressionAsString:string) {
|
constructor(bindingMemento:any, directiveMemento:any, contextIndex:number, expressionAsString:string, variableBindings:List) {
|
||||||
this.protoRecords = [];
|
this.protoRecords = [];
|
||||||
this.bindingMemento = bindingMemento;
|
this.bindingMemento = bindingMemento;
|
||||||
this.directiveMemento = directiveMemento;
|
this.directiveMemento = directiveMemento;
|
||||||
this.contextIndex = contextIndex;
|
this.contextIndex = contextIndex;
|
||||||
this.expressionAsString = expressionAsString;
|
this.expressionAsString = expressionAsString;
|
||||||
|
this.variableBindings = variableBindings;
|
||||||
}
|
}
|
||||||
|
|
||||||
static convert(ast:AST, bindingMemento:any, directiveMemento:any, contextIndex:number) {
|
static convert(ast:AST, bindingMemento:any, directiveMemento:any, contextIndex:number, variableBindings:List) {
|
||||||
var c = new _ConvertAstIntoProtoRecords(bindingMemento, directiveMemento, contextIndex, ast.toString());
|
var c = new _ConvertAstIntoProtoRecords(bindingMemento, directiveMemento, contextIndex, ast.toString(), variableBindings);
|
||||||
ast.visit(c);
|
ast.visit(c);
|
||||||
return c.protoRecords;
|
return c.protoRecords;
|
||||||
}
|
}
|
||||||
|
@ -178,13 +181,22 @@ class _ConvertAstIntoProtoRecords {
|
||||||
|
|
||||||
visitAccessMember(ast:AccessMember) {
|
visitAccessMember(ast:AccessMember) {
|
||||||
var receiver = ast.receiver.visit(this);
|
var receiver = ast.receiver.visit(this);
|
||||||
return this._addRecord(RECORD_TYPE_PROPERTY, ast.name, ast.getter, [], null, receiver);
|
if (isPresent(this.variableBindings) && ListWrapper.contains(this.variableBindings, ast.name)) {
|
||||||
|
return this._addRecord(RECORD_TYPE_LOCAL, ast.name, ast.name, [], null, receiver);
|
||||||
|
} else {
|
||||||
|
return this._addRecord(RECORD_TYPE_PROPERTY, ast.name, ast.getter, [], null, receiver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
visitMethodCall(ast:MethodCall) {
|
visitMethodCall(ast:MethodCall) {;
|
||||||
var receiver = ast.receiver.visit(this);
|
var receiver = ast.receiver.visit(this);
|
||||||
var args = this._visitAll(ast.args);
|
var args = this._visitAll(ast.args);
|
||||||
return this._addRecord(RECORD_TYPE_INVOKE_METHOD, ast.name, ast.fn, args, null, receiver);
|
if (isPresent(this.variableBindings) && ListWrapper.contains(this.variableBindings, ast.name)) {
|
||||||
|
var target = this._addRecord(RECORD_TYPE_LOCAL, ast.name, ast.name, [], null, receiver);
|
||||||
|
return this._addRecord(RECORD_TYPE_INVOKE_CLOSURE, "closure", null, args, null, target);
|
||||||
|
} else {
|
||||||
|
return this._addRecord(RECORD_TYPE_INVOKE_METHOD, ast.name, ast.fn, args, null, receiver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
visitFunctionCall(ast:FunctionCall) {
|
visitFunctionCall(ast:FunctionCall) {
|
||||||
|
|
|
@ -4,9 +4,10 @@ export const RECORD_TYPE_SELF = 0;
|
||||||
export const RECORD_TYPE_CONST = 1;
|
export const RECORD_TYPE_CONST = 1;
|
||||||
export const RECORD_TYPE_PRIMITIVE_OP = 2;
|
export const RECORD_TYPE_PRIMITIVE_OP = 2;
|
||||||
export const RECORD_TYPE_PROPERTY = 3;
|
export const RECORD_TYPE_PROPERTY = 3;
|
||||||
export const RECORD_TYPE_INVOKE_METHOD = 4;
|
export const RECORD_TYPE_LOCAL = 4;
|
||||||
export const RECORD_TYPE_INVOKE_CLOSURE = 5;
|
export const RECORD_TYPE_INVOKE_METHOD = 5;
|
||||||
export const RECORD_TYPE_KEYED_ACCESS = 6;
|
export const RECORD_TYPE_INVOKE_CLOSURE = 6;
|
||||||
|
export const RECORD_TYPE_KEYED_ACCESS = 7;
|
||||||
export const RECORD_TYPE_PIPE = 8;
|
export const RECORD_TYPE_PIPE = 8;
|
||||||
export const RECORD_TYPE_INTERPOLATE = 9;
|
export const RECORD_TYPE_INTERPOLATE = 9;
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ function _injectorBindings(appComponentType): List<Binding> {
|
||||||
// the angular application. Thus the context and lightDomInjector are
|
// the angular application. Thus the context and lightDomInjector are
|
||||||
// empty.
|
// empty.
|
||||||
var view = appProtoView.instantiate(null, eventManager);
|
var view = appProtoView.instantiate(null, eventManager);
|
||||||
view.hydrate(injector, null, null, new Object());
|
view.hydrate(injector, null, null, new Object(), null);
|
||||||
return view;
|
return view;
|
||||||
});
|
});
|
||||||
}, [ChangeDetection, Compiler, Injector, appElementToken, appComponentAnnotatedTypeToken,
|
}, [ChangeDetection, Compiler, Injector, appElementToken, appComponentAnnotatedTypeToken,
|
||||||
|
|
|
@ -35,7 +35,8 @@ export class ProtoViewBuilder extends CompileStep {
|
||||||
if (current.isViewRoot) {
|
if (current.isViewRoot) {
|
||||||
var protoChangeDetector = this.changeDetection.createProtoChangeDetector('dummy');
|
var protoChangeDetector = this.changeDetection.createProtoChangeDetector('dummy');
|
||||||
inheritedProtoView = new ProtoView(current.element, protoChangeDetector,
|
inheritedProtoView = new ProtoView(current.element, protoChangeDetector,
|
||||||
this._shadowDomStrategy);
|
this._shadowDomStrategy, this._getParentProtoView(parent));
|
||||||
|
|
||||||
if (isPresent(parent)) {
|
if (isPresent(parent)) {
|
||||||
if (isPresent(parent.inheritedElementBinder.nestedProtoView)) {
|
if (isPresent(parent.inheritedElementBinder.nestedProtoView)) {
|
||||||
throw new BaseException('Only one nested view per element is allowed');
|
throw new BaseException('Only one nested view per element is allowed');
|
||||||
|
@ -55,16 +56,20 @@ export class ProtoViewBuilder extends CompileStep {
|
||||||
inheritedProtoView = parent.inheritedProtoView;
|
inheritedProtoView = parent.inheritedProtoView;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The view's contextWithLocals needs to have a full set of variable names at construction time
|
// The view's locals needs to have a full set of variable names at construction time
|
||||||
// in order to prevent new variables from being set later in the lifecycle. Since we don't want
|
// in order to prevent new variables from being set later in the lifecycle. Since we don't want
|
||||||
// to actually create variable bindings for the $implicit bindings, add to the
|
// to actually create variable bindings for the $implicit bindings, add to the
|
||||||
// protoContextLocals manually.
|
// protoLocals manually.
|
||||||
if (isPresent(current.variableBindings)) {
|
if (isPresent(current.variableBindings)) {
|
||||||
MapWrapper.forEach(current.variableBindings, (mappedName, varName) => {
|
MapWrapper.forEach(current.variableBindings, (mappedName, varName) => {
|
||||||
MapWrapper.set(inheritedProtoView.protoContextLocals, mappedName, null);
|
MapWrapper.set(inheritedProtoView.protoLocals, mappedName, null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
current.inheritedProtoView = inheritedProtoView;
|
current.inheritedProtoView = inheritedProtoView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getParentProtoView(parent:CompileElement) {
|
||||||
|
return isPresent(parent) ? parent.inheritedProtoView : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||||
import {Promise} from 'angular2/src/facade/async';
|
import {Promise} from 'angular2/src/facade/async';
|
||||||
import {ListWrapper, MapWrapper, Map, StringMapWrapper, List} from 'angular2/src/facade/collection';
|
import {ListWrapper, MapWrapper, Map, StringMapWrapper, List} from 'angular2/src/facade/collection';
|
||||||
import {AST, ContextWithVariableBindings, ChangeDispatcher, ProtoChangeDetector, ChangeDetector,
|
import {AST, Locals, ChangeDispatcher, ProtoChangeDetector, ChangeDetector,
|
||||||
ChangeRecord, BindingRecord, uninitialized} from 'angular2/change_detection';
|
ChangeRecord, BindingRecord, uninitialized} from 'angular2/change_detection';
|
||||||
|
|
||||||
import {ProtoElementInjector, ElementInjector, PreBuiltObjects} from './element_injector';
|
import {ProtoElementInjector, ElementInjector, PreBuiltObjects} from './element_injector';
|
||||||
|
@ -47,9 +47,9 @@ export class View {
|
||||||
lightDoms: List<LightDom>;
|
lightDoms: List<LightDom>;
|
||||||
proto: ProtoView;
|
proto: ProtoView;
|
||||||
context: any;
|
context: any;
|
||||||
contextWithLocals:ContextWithVariableBindings;
|
locals:Locals;
|
||||||
|
|
||||||
constructor(proto:ProtoView, nodes:List, protoContextLocals:Map) {
|
constructor(proto:ProtoView, nodes:List, protoLocals:Map) {
|
||||||
this.proto = proto;
|
this.proto = proto;
|
||||||
this.nodes = nodes;
|
this.nodes = nodes;
|
||||||
this.changeDetector = null;
|
this.changeDetector = null;
|
||||||
|
@ -63,9 +63,7 @@ export class View {
|
||||||
this.preBuiltObjects = null;
|
this.preBuiltObjects = null;
|
||||||
this.lightDoms = null;
|
this.lightDoms = null;
|
||||||
this.context = null;
|
this.context = null;
|
||||||
this.contextWithLocals = (MapWrapper.size(protoContextLocals) > 0)
|
this.locals = new Locals(null, MapWrapper.clone(protoLocals)); //TODO optimize this
|
||||||
? new ContextWithVariableBindings(null, MapWrapper.clone(protoContextLocals))
|
|
||||||
: null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init(changeDetector:ChangeDetector, elementInjectors:List, rootElementInjectors:List, textNodes: List, bindElements:List,
|
init(changeDetector:ChangeDetector, elementInjectors:List, rootElementInjectors:List, textNodes: List, bindElements:List,
|
||||||
|
@ -88,29 +86,22 @@ export class View {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var templateName = MapWrapper.get(this.proto.variableBindings, contextName);
|
var templateName = MapWrapper.get(this.proto.variableBindings, contextName);
|
||||||
this.context.set(templateName, value);
|
this.locals.set(templateName, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
hydrated() {
|
hydrated() {
|
||||||
return isPresent(this.context);
|
return isPresent(this.context);
|
||||||
}
|
}
|
||||||
|
|
||||||
_hydrateContext(newContext) {
|
_hydrateContext(newContext, locals) {
|
||||||
if (isPresent(this.contextWithLocals)) {
|
this.context = newContext;
|
||||||
this.contextWithLocals.parent = newContext;
|
this.locals.parent = locals;
|
||||||
this.context = this.contextWithLocals;
|
this.changeDetector.hydrate(this.context, this.locals);
|
||||||
} else {
|
|
||||||
this.context = newContext;
|
|
||||||
}
|
|
||||||
// TODO(tbosch): if we have a contextWithLocals we actually only need to
|
|
||||||
// set the contextWithLocals once. Would it be faster to always use a contextWithLocals
|
|
||||||
// even if we don't have locals and not update the recordRange here?
|
|
||||||
this.changeDetector.hydrate(this.context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_dehydrateContext() {
|
_dehydrateContext() {
|
||||||
if (isPresent(this.contextWithLocals)) {
|
if (isPresent(this.locals)) {
|
||||||
this.contextWithLocals.clearValues();
|
this.locals.clearValues();
|
||||||
}
|
}
|
||||||
this.context = null;
|
this.context = null;
|
||||||
this.changeDetector.dehydrate();
|
this.changeDetector.dehydrate();
|
||||||
|
@ -133,9 +124,9 @@ export class View {
|
||||||
* tree.
|
* tree.
|
||||||
*/
|
*/
|
||||||
hydrate(appInjector: Injector, hostElementInjector: ElementInjector, hostLightDom: LightDom,
|
hydrate(appInjector: Injector, hostElementInjector: ElementInjector, hostLightDom: LightDom,
|
||||||
context: Object) {
|
context: Object, locals:Locals) {
|
||||||
if (this.hydrated()) throw new BaseException('The view is already hydrated.');
|
if (this.hydrated()) throw new BaseException('The view is already hydrated.');
|
||||||
this._hydrateContext(context);
|
this._hydrateContext(context, locals);
|
||||||
|
|
||||||
// viewContainers
|
// viewContainers
|
||||||
for (var i = 0; i < this.viewContainers.length; i++) {
|
for (var i = 0; i < this.viewContainers.length; i++) {
|
||||||
|
@ -173,15 +164,15 @@ export class View {
|
||||||
// name.
|
// name.
|
||||||
var exportImplicitName = elementInjector.getExportImplicitName();
|
var exportImplicitName = elementInjector.getExportImplicitName();
|
||||||
if (elementInjector.isExportingComponent()) {
|
if (elementInjector.isExportingComponent()) {
|
||||||
this.context.set(exportImplicitName, elementInjector.getComponent());
|
this.locals.set(exportImplicitName, elementInjector.getComponent());
|
||||||
} else if (elementInjector.isExportingElement()) {
|
} else if (elementInjector.isExportingElement()) {
|
||||||
this.context.set(exportImplicitName, elementInjector.getNgElement().domElement);
|
this.locals.set(exportImplicitName, elementInjector.getNgElement().domElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPresent(componentDirective)) {
|
if (isPresent(componentDirective)) {
|
||||||
this.componentChildViews[componentChildViewIndex++].hydrate(shadowDomAppInjector,
|
this.componentChildViews[componentChildViewIndex++].hydrate(shadowDomAppInjector,
|
||||||
elementInjector, this.lightDoms[i], elementInjector.getComponent());
|
elementInjector, this.lightDoms[i], elementInjector.getComponent(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,7 +285,7 @@ export class ProtoView {
|
||||||
elementBinders:List<ElementBinder>;
|
elementBinders:List<ElementBinder>;
|
||||||
protoChangeDetector:ProtoChangeDetector;
|
protoChangeDetector:ProtoChangeDetector;
|
||||||
variableBindings: Map;
|
variableBindings: Map;
|
||||||
protoContextLocals:Map;
|
protoLocals:Map;
|
||||||
textNodesWithBindingCount:int;
|
textNodesWithBindingCount:int;
|
||||||
elementsWithBindingCount:int;
|
elementsWithBindingCount:int;
|
||||||
instantiateInPlace:boolean;
|
instantiateInPlace:boolean;
|
||||||
|
@ -306,16 +297,19 @@ export class ProtoView {
|
||||||
// List<Map<eventName, handler>>, indexed by binder index
|
// List<Map<eventName, handler>>, indexed by binder index
|
||||||
eventHandlers:List;
|
eventHandlers:List;
|
||||||
bindingRecords:List;
|
bindingRecords:List;
|
||||||
|
parentProtoView:ProtoView;
|
||||||
|
_variableBindings:List;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
template,
|
template,
|
||||||
protoChangeDetector:ProtoChangeDetector,
|
protoChangeDetector:ProtoChangeDetector,
|
||||||
shadowDomStrategy:ShadowDomStrategy) {
|
shadowDomStrategy:ShadowDomStrategy, parentProtoView:ProtoView = null) {
|
||||||
this.element = template;
|
this.element = template;
|
||||||
this.elementBinders = [];
|
this.elementBinders = [];
|
||||||
this.variableBindings = MapWrapper.create();
|
this.variableBindings = MapWrapper.create();
|
||||||
this.protoContextLocals = MapWrapper.create();
|
this.protoLocals = MapWrapper.create();
|
||||||
this.protoChangeDetector = protoChangeDetector;
|
this.protoChangeDetector = protoChangeDetector;
|
||||||
|
this.parentProtoView = parentProtoView;
|
||||||
this.textNodesWithBindingCount = 0;
|
this.textNodesWithBindingCount = 0;
|
||||||
this.elementsWithBindingCount = 0;
|
this.elementsWithBindingCount = 0;
|
||||||
this.instantiateInPlace = false;
|
this.instantiateInPlace = false;
|
||||||
|
@ -327,6 +321,7 @@ export class ProtoView {
|
||||||
this.stylePromises = [];
|
this.stylePromises = [];
|
||||||
this.eventHandlers = [];
|
this.eventHandlers = [];
|
||||||
this.bindingRecords = [];
|
this.bindingRecords = [];
|
||||||
|
this._variableBindings = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(rado): hostElementInjector should be moved to hydrate phase.
|
// TODO(rado): hostElementInjector should be moved to hydrate phase.
|
||||||
|
@ -342,6 +337,23 @@ export class ProtoView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this work should be done the constructor of ProtoView once we separate
|
||||||
|
// ProtoView and ProtoViewBuilder
|
||||||
|
_getVariableBindings() {
|
||||||
|
if (isPresent(this._variableBindings)) {
|
||||||
|
return this._variableBindings;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._variableBindings = isPresent(this.parentProtoView) ?
|
||||||
|
ListWrapper.clone(this.parentProtoView._getVariableBindings()) : [];
|
||||||
|
|
||||||
|
MapWrapper.forEach(this.protoLocals, (v, local) => {
|
||||||
|
ListWrapper.push(this._variableBindings, local);
|
||||||
|
});
|
||||||
|
|
||||||
|
return this._variableBindings;
|
||||||
|
}
|
||||||
|
|
||||||
_instantiate(hostElementInjector: ElementInjector, eventManager: EventManager): View {
|
_instantiate(hostElementInjector: ElementInjector, eventManager: EventManager): View {
|
||||||
var rootElementClone = this.instantiateInPlace ? this.element : DOM.importIntoDoc(this.element);
|
var rootElementClone = this.instantiateInPlace ? this.element : DOM.importIntoDoc(this.element);
|
||||||
var elementsWithBindingsDynamic;
|
var elementsWithBindingsDynamic;
|
||||||
|
@ -369,9 +381,8 @@ export class ProtoView {
|
||||||
viewNodes = [rootElementClone];
|
viewNodes = [rootElementClone];
|
||||||
}
|
}
|
||||||
|
|
||||||
var view = new View(this, viewNodes, this.protoContextLocals);
|
var view = new View(this, viewNodes, this.protoLocals);
|
||||||
var changeDetector = this.protoChangeDetector.instantiate(view, this.bindingRecords);
|
var changeDetector = this.protoChangeDetector.instantiate(view, this.bindingRecords, this._getVariableBindings());
|
||||||
|
|
||||||
var binders = this.elementBinders;
|
var binders = this.elementBinders;
|
||||||
var elementInjectors = ListWrapper.createFixedSize(binders.length);
|
var elementInjectors = ListWrapper.createFixedSize(binders.length);
|
||||||
var eventHandlers = ListWrapper.createFixedSize(binders.length);
|
var eventHandlers = ListWrapper.createFixedSize(binders.length);
|
||||||
|
@ -514,7 +525,7 @@ export class ProtoView {
|
||||||
} else {
|
} else {
|
||||||
context = view.elementInjectors[injectorIdx].getDirectiveAtIndex(directiveIndex);
|
context = view.elementInjectors[injectorIdx].getDirectiveAtIndex(directiveIndex);
|
||||||
}
|
}
|
||||||
expr.eval(new ContextWithVariableBindings(context, locals));
|
expr.eval(context, new Locals(view.locals, locals));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -522,7 +533,7 @@ export class ProtoView {
|
||||||
|
|
||||||
bindVariable(contextName:string, templateName:string) {
|
bindVariable(contextName:string, templateName:string) {
|
||||||
MapWrapper.set(this.variableBindings, contextName, templateName);
|
MapWrapper.set(this.variableBindings, contextName, templateName);
|
||||||
MapWrapper.set(this.protoContextLocals, templateName, null);
|
MapWrapper.set(this.protoLocals, templateName, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
bindElement(parent:ElementBinder, distanceToParent:int, protoElementInjector:ProtoElementInjector,
|
bindElement(parent:ElementBinder, distanceToParent:int, protoElementInjector:ProtoElementInjector,
|
||||||
|
|
|
@ -85,7 +85,8 @@ export class ViewContainer {
|
||||||
var newView = this.defaultProtoView.instantiate(this.hostElementInjector, this._eventManager);
|
var newView = this.defaultProtoView.instantiate(this.hostElementInjector, this._eventManager);
|
||||||
// insertion must come before hydration so that element injector trees are attached.
|
// insertion must come before hydration so that element injector trees are attached.
|
||||||
this.insert(newView, atIndex);
|
this.insert(newView, atIndex);
|
||||||
newView.hydrate(this.appInjector, this.hostElementInjector, this.hostLightDom, this.parentView.context);
|
newView.hydrate(this.appInjector, this.hostElementInjector, this.hostLightDom,
|
||||||
|
this.parentView.context, this.parentView.locals);
|
||||||
|
|
||||||
// new content tags might have appeared, we need to redistrubute.
|
// new content tags might have appeared, we need to redistrubute.
|
||||||
if (isPresent(this.hostLightDom)) {
|
if (isPresent(this.hostLightDom)) {
|
||||||
|
|
|
@ -5,8 +5,9 @@ import {List, ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/faca
|
||||||
|
|
||||||
import {Parser} from 'angular2/src/change_detection/parser/parser';
|
import {Parser} from 'angular2/src/change_detection/parser/parser';
|
||||||
import {Lexer} from 'angular2/src/change_detection/parser/lexer';
|
import {Lexer} from 'angular2/src/change_detection/parser/lexer';
|
||||||
|
import {Locals} from 'angular2/src/change_detection/parser/locals';
|
||||||
|
|
||||||
import {ChangeDispatcher, DynamicChangeDetector, ChangeDetectionError, ContextWithVariableBindings, BindingRecord,
|
import {ChangeDispatcher, DynamicChangeDetector, ChangeDetectionError, BindingRecord,
|
||||||
PipeRegistry, Pipe, NO_CHANGE, CHECK_ALWAYS, CHECK_ONCE, CHECKED, DETACHED} from 'angular2/change_detection';
|
PipeRegistry, Pipe, NO_CHANGE, CHECK_ALWAYS, CHECK_ONCE, CHECKED, DETACHED} from 'angular2/change_detection';
|
||||||
|
|
||||||
import {ChangeDetectionUtil} from 'angular2/src/change_detection/change_detection_util';
|
import {ChangeDetectionUtil} from 'angular2/src/change_detection/change_detection_util';
|
||||||
|
@ -28,17 +29,29 @@ export function main() {
|
||||||
return parser.parseBinding(exp, location);
|
return parser.parseBinding(exp, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createChangeDetector(memo:string, exp:string, context = null, registry = null) {
|
function convertLocalsToVariableBindings(locals) {
|
||||||
|
var variableBindings = [];
|
||||||
|
var loc = locals;
|
||||||
|
while(isPresent(loc)) {
|
||||||
|
MapWrapper.forEach(loc.current, (v, k) => ListWrapper.push(variableBindings, k));
|
||||||
|
loc = loc.parent;
|
||||||
|
}
|
||||||
|
return variableBindings;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createChangeDetector(memo:string, exp:string, context = null, locals = null, registry = null) {
|
||||||
var pcd = createProtoChangeDetector(registry);
|
var pcd = createProtoChangeDetector(registry);
|
||||||
var dispatcher = new TestDispatcher();
|
var dispatcher = new TestDispatcher();
|
||||||
var cd = pcd.instantiate(dispatcher, [new BindingRecord(ast(exp), memo, memo)]);
|
|
||||||
cd.hydrate(context);
|
var variableBindings = convertLocalsToVariableBindings(locals);
|
||||||
|
var cd = pcd.instantiate(dispatcher, [new BindingRecord(ast(exp), memo, memo)], variableBindings);
|
||||||
|
cd.hydrate(context, locals);
|
||||||
|
|
||||||
return {"changeDetector" : cd, "dispatcher" : dispatcher};
|
return {"changeDetector" : cd, "dispatcher" : dispatcher};
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeWatch(memo:string, exp:string, context = null) {
|
function executeWatch(memo:string, exp:string, context = null, locals = null) {
|
||||||
var res = createChangeDetector(memo, exp, context);
|
var res = createChangeDetector(memo, exp, context, locals);
|
||||||
res["changeDetector"].detectChanges();
|
res["changeDetector"].detectChanges();
|
||||||
return res["dispatcher"].log;
|
return res["dispatcher"].log;
|
||||||
}
|
}
|
||||||
|
@ -180,8 +193,8 @@ export function main() {
|
||||||
var ast = parser.parseInterpolation("B{{a}}A", "location");
|
var ast = parser.parseInterpolation("B{{a}}A", "location");
|
||||||
|
|
||||||
var dispatcher = new TestDispatcher();
|
var dispatcher = new TestDispatcher();
|
||||||
var cd = pcd.instantiate(dispatcher, [new BindingRecord(ast, "memo", "memo")]);
|
var cd = pcd.instantiate(dispatcher, [new BindingRecord(ast, "memo", "memo")], null);
|
||||||
cd.hydrate(new TestData("value"));
|
cd.hydrate(new TestData("value"), null);
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
|
@ -211,7 +224,7 @@ export function main() {
|
||||||
var registry = new FakePipeRegistry('pipe', () => new CountingPipe());
|
var registry = new FakePipeRegistry('pipe', () => new CountingPipe());
|
||||||
|
|
||||||
var person = new Person('bob');
|
var person = new Person('bob');
|
||||||
var c = createChangeDetector('name', 'name | pipe', person, registry);
|
var c = createChangeDetector('name', 'name | pipe', person, null, registry);
|
||||||
var cd = c["changeDetector"];
|
var cd = c["changeDetector"];
|
||||||
var dispatcher = c["dispatcher"];
|
var dispatcher = c["dispatcher"];
|
||||||
|
|
||||||
|
@ -234,7 +247,7 @@ export function main() {
|
||||||
new BindingRecord(ast("1 + 2"), "memo", "1"),
|
new BindingRecord(ast("1 + 2"), "memo", "1"),
|
||||||
new BindingRecord(ast("10 + 20"), "memo", "1"),
|
new BindingRecord(ast("10 + 20"), "memo", "1"),
|
||||||
new BindingRecord(ast("100 + 200"), "memo", "2")
|
new BindingRecord(ast("100 + 200"), "memo", "2")
|
||||||
]);
|
], null);
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
|
@ -248,7 +261,7 @@ export function main() {
|
||||||
new BindingRecord(ast("a()"), "a", "1"),
|
new BindingRecord(ast("a()"), "a", "1"),
|
||||||
new BindingRecord(ast("b()"), "b", "2"),
|
new BindingRecord(ast("b()"), "b", "2"),
|
||||||
new BindingRecord(ast("c()"), "c", "2")
|
new BindingRecord(ast("c()"), "c", "2")
|
||||||
]);
|
], null);
|
||||||
|
|
||||||
var tr = new TestRecord();
|
var tr = new TestRecord();
|
||||||
tr.a = () => {
|
tr.a = () => {
|
||||||
|
@ -263,7 +276,7 @@ export function main() {
|
||||||
dispatcher.logValue('InvokeC');
|
dispatcher.logValue('InvokeC');
|
||||||
return 'c'
|
return 'c'
|
||||||
};
|
};
|
||||||
cd.hydrate(tr);
|
cd.hydrate(tr, null);
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
|
@ -280,8 +293,8 @@ export function main() {
|
||||||
var dispatcher = new TestDispatcher();
|
var dispatcher = new TestDispatcher();
|
||||||
var cd = pcd.instantiate(dispatcher, [
|
var cd = pcd.instantiate(dispatcher, [
|
||||||
new BindingRecord(ast("a"), "a", 1)
|
new BindingRecord(ast("a"), "a", 1)
|
||||||
]);
|
], null);
|
||||||
cd.hydrate(new TestData('value'));
|
cd.hydrate(new TestData('value'), null);
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
cd.checkNoChanges();
|
cd.checkNoChanges();
|
||||||
|
@ -295,8 +308,8 @@ export function main() {
|
||||||
var pcd = createProtoChangeDetector();
|
var pcd = createProtoChangeDetector();
|
||||||
var cd = pcd.instantiate(new TestDispatcher(), [
|
var cd = pcd.instantiate(new TestDispatcher(), [
|
||||||
new BindingRecord(ast("invalidProp", "someComponent"), "a", 1)
|
new BindingRecord(ast("invalidProp", "someComponent"), "a", 1)
|
||||||
]);
|
], null);
|
||||||
cd.hydrate(null);
|
cd.hydrate(null, null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
@ -309,38 +322,38 @@ export function main() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("ContextWithVariableBindings", () => {
|
describe("Locals", () => {
|
||||||
it('should read a field from ContextWithVariableBindings', () => {
|
it('should read a value from locals', () => {
|
||||||
var locals = new ContextWithVariableBindings(null,
|
var locals = new Locals(null,
|
||||||
MapWrapper.createFromPairs([["key", "value"]]));
|
MapWrapper.createFromPairs([["key", "value"]]));
|
||||||
|
|
||||||
expect(executeWatch('key', 'key', locals))
|
expect(executeWatch('key', 'key', null, locals))
|
||||||
.toEqual(['key=value']);
|
.toEqual(['key=value']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should invoke a function from ContextWithVariableBindings', () => {
|
it('should invoke a function from local', () => {
|
||||||
var locals = new ContextWithVariableBindings(null,
|
var locals = new Locals(null,
|
||||||
MapWrapper.createFromPairs([["key", () => "value"]]));
|
MapWrapper.createFromPairs([["key", () => "value"]]));
|
||||||
|
|
||||||
expect(executeWatch('key', 'key()', locals))
|
expect(executeWatch('key', 'key()', null, locals))
|
||||||
.toEqual(['key=value']);
|
.toEqual(['key=value']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle nested ContextWithVariableBindings', () => {
|
it('should handle nested locals', () => {
|
||||||
var nested = new ContextWithVariableBindings(null,
|
var nested = new Locals(null,
|
||||||
MapWrapper.createFromPairs([["key", "value"]]));
|
MapWrapper.createFromPairs([["key", "value"]]));
|
||||||
var locals = new ContextWithVariableBindings(nested, MapWrapper.create());
|
var locals = new Locals(nested, MapWrapper.create());
|
||||||
|
|
||||||
expect(executeWatch('key', 'key', locals))
|
expect(executeWatch('key', 'key', null, locals))
|
||||||
.toEqual(['key=value']);
|
.toEqual(['key=value']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should fall back to a regular field read when ContextWithVariableBindings " +
|
it("should fall back to a regular field read when the locals map" +
|
||||||
"does not have the requested field", () => {
|
"does not have the requested field", () => {
|
||||||
var locals = new ContextWithVariableBindings(new Person("Jim"),
|
var locals = new Locals(null,
|
||||||
MapWrapper.createFromPairs([["key", "value"]]));
|
MapWrapper.createFromPairs([["key", "value"]]));
|
||||||
|
|
||||||
expect(executeWatch('name', 'name', locals))
|
expect(executeWatch('name', 'name', new Person("Jim"), locals))
|
||||||
.toEqual(['name=Jim']);
|
.toEqual(['name=Jim']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -350,10 +363,10 @@ export function main() {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
var protoParent = createProtoChangeDetector();
|
var protoParent = createProtoChangeDetector();
|
||||||
parent = protoParent.instantiate(null, []);
|
parent = protoParent.instantiate(null, [], null);
|
||||||
|
|
||||||
var protoChild = createProtoChangeDetector();
|
var protoChild = createProtoChangeDetector();
|
||||||
child = protoChild.instantiate(null, []);
|
child = protoChild.instantiate(null, [], null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should add children", () => {
|
it("should add children", () => {
|
||||||
|
@ -396,7 +409,7 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should change CHECK_ONCE to CHECKED", () => {
|
it("should change CHECK_ONCE to CHECKED", () => {
|
||||||
var cd = createProtoChangeDetector().instantiate(null, []);
|
var cd = createProtoChangeDetector().instantiate(null, [], null);
|
||||||
cd.mode = CHECK_ONCE;
|
cd.mode = CHECK_ONCE;
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
@ -405,7 +418,7 @@ export function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not change the CHECK_ALWAYS", () => {
|
it("should not change the CHECK_ALWAYS", () => {
|
||||||
var cd = createProtoChangeDetector().instantiate(null, []);
|
var cd = createProtoChangeDetector().instantiate(null, [], null);
|
||||||
cd.mode = CHECK_ALWAYS;
|
cd.mode = CHECK_ALWAYS;
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
@ -416,7 +429,7 @@ export function main() {
|
||||||
|
|
||||||
describe("markPathToRootAsCheckOnce", () => {
|
describe("markPathToRootAsCheckOnce", () => {
|
||||||
function changeDetector(mode, parent) {
|
function changeDetector(mode, parent) {
|
||||||
var cd = createProtoChangeDetector().instantiate(null, []);
|
var cd = createProtoChangeDetector().instantiate(null, [], null);
|
||||||
cd.mode = mode;
|
cd.mode = mode;
|
||||||
if (isPresent(parent)) parent.addChild(cd);
|
if (isPresent(parent)) parent.addChild(cd);
|
||||||
return cd;
|
return cd;
|
||||||
|
@ -448,20 +461,20 @@ export function main() {
|
||||||
var c = createChangeDetector("memo", "name");
|
var c = createChangeDetector("memo", "name");
|
||||||
var cd = c["changeDetector"];
|
var cd = c["changeDetector"];
|
||||||
|
|
||||||
cd.hydrate("some context");
|
cd.hydrate("some context", null);
|
||||||
expect(cd.hydrated()).toBe(true);
|
expect(cd.hydrated()).toBe(true);
|
||||||
|
|
||||||
cd.dehydrate();
|
cd.dehydrate();
|
||||||
expect(cd.hydrated()).toBe(false);
|
expect(cd.hydrated()).toBe(false);
|
||||||
|
|
||||||
cd.hydrate("other context");
|
cd.hydrate("other context", null);
|
||||||
expect(cd.hydrated()).toBe(true);
|
expect(cd.hydrated()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should destroy all active pipes during dehyration", () => {
|
it("should destroy all active pipes during dehyration", () => {
|
||||||
var pipe = new OncePipe();
|
var pipe = new OncePipe();
|
||||||
var registry = new FakePipeRegistry('pipe', () => pipe);
|
var registry = new FakePipeRegistry('pipe', () => pipe);
|
||||||
var c = createChangeDetector("memo", "name | pipe", new Person('bob'), registry);
|
var c = createChangeDetector("memo", "name | pipe", new Person('bob'), null, registry);
|
||||||
var cd = c["changeDetector"];
|
var cd = c["changeDetector"];
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
@ -477,7 +490,7 @@ export function main() {
|
||||||
var registry = new FakePipeRegistry('pipe', () => new CountingPipe());
|
var registry = new FakePipeRegistry('pipe', () => new CountingPipe());
|
||||||
var ctx = new Person("Megatron");
|
var ctx = new Person("Megatron");
|
||||||
|
|
||||||
var c = createChangeDetector("memo", "name | pipe", ctx, registry);
|
var c = createChangeDetector("memo", "name | pipe", ctx, null, registry);
|
||||||
var cd = c["changeDetector"];
|
var cd = c["changeDetector"];
|
||||||
var dispatcher = c["dispatcher"];
|
var dispatcher = c["dispatcher"];
|
||||||
|
|
||||||
|
@ -495,7 +508,7 @@ export function main() {
|
||||||
var registry = new FakePipeRegistry('pipe', () => new OncePipe());
|
var registry = new FakePipeRegistry('pipe', () => new OncePipe());
|
||||||
var ctx = new Person("Megatron");
|
var ctx = new Person("Megatron");
|
||||||
|
|
||||||
var c = createChangeDetector("memo", "name | pipe", ctx, registry);
|
var c = createChangeDetector("memo", "name | pipe", ctx, null, registry);
|
||||||
var cd = c["changeDetector"];
|
var cd = c["changeDetector"];
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
@ -513,7 +526,7 @@ export function main() {
|
||||||
var registry = new FakePipeRegistry('pipe', () => pipe);
|
var registry = new FakePipeRegistry('pipe', () => pipe);
|
||||||
var ctx = new Person("Megatron");
|
var ctx = new Person("Megatron");
|
||||||
|
|
||||||
var c = createChangeDetector("memo", "name | pipe", ctx, registry);
|
var c = createChangeDetector("memo", "name | pipe", ctx, null, registry);
|
||||||
var cd = c["changeDetector"];
|
var cd = c["changeDetector"];
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
@ -528,7 +541,7 @@ export function main() {
|
||||||
var registry = new FakePipeRegistry('pipe', () => new IdentityPipe())
|
var registry = new FakePipeRegistry('pipe', () => new IdentityPipe())
|
||||||
var ctx = new Person("Megatron");
|
var ctx = new Person("Megatron");
|
||||||
|
|
||||||
var c = createChangeDetector("memo", "name | pipe", ctx, registry);
|
var c = createChangeDetector("memo", "name | pipe", ctx, null, registry);
|
||||||
var cd = c["changeDetector"];
|
var cd = c["changeDetector"];
|
||||||
var dispatcher = c["dispatcher"];
|
var dispatcher = c["dispatcher"];
|
||||||
|
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
import {ddescribe, describe, it, xit, iit, expect, beforeEach} from 'angular2/test_lib';
|
|
||||||
|
|
||||||
import {ContextWithVariableBindings} from 'angular2/src/change_detection/parser/context_with_variable_bindings';
|
|
||||||
|
|
||||||
import {BaseException, isBlank, isPresent} from 'angular2/src/facade/lang';
|
|
||||||
import {MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
|
|
||||||
|
|
||||||
export function main() {
|
|
||||||
describe('ContextWithVariableBindings', () => {
|
|
||||||
var locals;
|
|
||||||
beforeEach(() => {
|
|
||||||
locals = new ContextWithVariableBindings(null,
|
|
||||||
MapWrapper.createFromPairs([['key', 'value'], ['nullKey', null]]));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should support getting values', () => {
|
|
||||||
expect(locals.get('key')).toBe('value');
|
|
||||||
|
|
||||||
var notPresentValue = locals.get('notPresent');
|
|
||||||
expect(isPresent(notPresentValue)).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should support checking if key is persent', () => {
|
|
||||||
expect(locals.hasBinding('key')).toBe(true);
|
|
||||||
expect(locals.hasBinding('nullKey')).toBe(true);
|
|
||||||
expect(locals.hasBinding('notPresent')).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should support setting persent keys', () => {
|
|
||||||
locals.set('key', 'bar');
|
|
||||||
expect(locals.get('key')).toBe('bar');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not support setting keys that are not present already', () => {
|
|
||||||
expect(() => locals.set('notPresent', 'bar')).toThrowError();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should clearValues', () => {
|
|
||||||
locals.clearValues();
|
|
||||||
expect(locals.get('key')).toBe(null);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
import {ddescribe, describe, it, xit, iit, expect, beforeEach} from 'angular2/test_lib';
|
||||||
|
|
||||||
|
import {Locals} from 'angular2/src/change_detection/parser/locals';
|
||||||
|
|
||||||
|
import {MapWrapper} from 'angular2/src/facade/collection';
|
||||||
|
|
||||||
|
export function main() {
|
||||||
|
describe('Locals', () => {
|
||||||
|
var locals;
|
||||||
|
beforeEach(() => {
|
||||||
|
locals = new Locals(null,
|
||||||
|
MapWrapper.createFromPairs([['key', 'value'], ['nullKey', null]]));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should support getting values', () => {
|
||||||
|
expect(locals.get('key')).toBe('value');
|
||||||
|
expect(() => locals.get('notPresent')).toThrowError(new RegExp("Cannot find"));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should support checking if key is present', () => {
|
||||||
|
expect(locals.contains('key')).toBe(true);
|
||||||
|
expect(locals.contains('nullKey')).toBe(true);
|
||||||
|
expect(locals.contains('notPresent')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should support setting keys', () => {
|
||||||
|
locals.set('key', 'bar');
|
||||||
|
expect(locals.get('key')).toBe('bar');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not support setting keys that are not present already', () => {
|
||||||
|
expect(() => locals.set('notPresent', 'bar')).toThrowError();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should clearValues', () => {
|
||||||
|
locals.clearValues();
|
||||||
|
expect(locals.get('key')).toBe(null);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ import {reflector} from 'angular2/src/reflection/reflection';
|
||||||
import {MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
|
import {MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
|
||||||
import {Parser} from 'angular2/src/change_detection/parser/parser';
|
import {Parser} from 'angular2/src/change_detection/parser/parser';
|
||||||
import {Lexer} from 'angular2/src/change_detection/parser/lexer';
|
import {Lexer} from 'angular2/src/change_detection/parser/lexer';
|
||||||
import {ContextWithVariableBindings} from 'angular2/src/change_detection/parser/context_with_variable_bindings';
|
import {Locals} from 'angular2/src/change_detection/parser/locals';
|
||||||
import {Pipe, LiteralPrimitive} from 'angular2/src/change_detection/parser/ast';
|
import {Pipe, LiteralPrimitive} from 'angular2/src/change_detection/parser/ast';
|
||||||
|
|
||||||
class TestData {
|
class TestData {
|
||||||
|
@ -55,21 +55,27 @@ export function main() {
|
||||||
return createParser().addPipes(ast, pipes);
|
return createParser().addPipes(ast, pipes);
|
||||||
}
|
}
|
||||||
|
|
||||||
function expectEval(text, passedInContext = null) {
|
function emptyLocals() {
|
||||||
var c = isBlank(passedInContext) ? td() : passedInContext;
|
return new Locals(null, MapWrapper.create());
|
||||||
return expect(parseAction(text).eval(c));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function expectEvalError(text, passedInContext = null) {
|
function expectEval(text, passedInContext = null, passedInLocals = null) {
|
||||||
var c = isBlank(passedInContext) ? td() : passedInContext;
|
var c = isBlank(passedInContext) ? td() : passedInContext;
|
||||||
return expect(() => parseAction(text).eval(c));
|
var l = isBlank(passedInLocals) ? emptyLocals() : passedInLocals;
|
||||||
|
return expect(parseAction(text).eval(c, l));
|
||||||
|
}
|
||||||
|
|
||||||
|
function expectEvalError(text, passedInContext = null, passedInLocals = null) {
|
||||||
|
var c = isBlank(passedInContext) ? td() : passedInContext;
|
||||||
|
var l = isBlank(passedInLocals) ? emptyLocals() : passedInLocals;
|
||||||
|
return expect(() => parseAction(text).eval(c, l));
|
||||||
}
|
}
|
||||||
|
|
||||||
function evalAsts(asts, passedInContext = null) {
|
function evalAsts(asts, passedInContext = null) {
|
||||||
var c = isBlank(passedInContext) ? td() : passedInContext;
|
var c = isBlank(passedInContext) ? td() : passedInContext;
|
||||||
var res = [];
|
var res = [];
|
||||||
for (var i=0; i<asts.length; i++) {
|
for (var i=0; i<asts.length; i++) {
|
||||||
ListWrapper.push(res, asts[i].eval(c));
|
ListWrapper.push(res, asts[i].eval(c, emptyLocals()));
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -188,23 +194,23 @@ export function main() {
|
||||||
expectEvalError('x."foo"').toThrowError(new RegExp('identifier or keyword'));
|
expectEvalError('x."foo"').toThrowError(new RegExp('identifier or keyword'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should read a field from ContextWithVariableBindings", () => {
|
it("should read a field from Locals", () => {
|
||||||
var locals = new ContextWithVariableBindings(null,
|
var locals = new Locals(null,
|
||||||
MapWrapper.createFromPairs([["key", "value"]]));
|
MapWrapper.createFromPairs([["key", "value"]]));
|
||||||
expectEval("key", locals).toEqual("value");
|
expectEval("key", null, locals).toEqual("value");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle nested ContextWithVariableBindings", () => {
|
it("should handle nested Locals", () => {
|
||||||
var nested = new ContextWithVariableBindings(null,
|
var nested = new Locals(null,
|
||||||
MapWrapper.createFromPairs([["key", "value"]]));
|
MapWrapper.createFromPairs([["key", "value"]]));
|
||||||
var locals = new ContextWithVariableBindings(nested, MapWrapper.create());
|
var locals = new Locals(nested, MapWrapper.create());
|
||||||
expectEval("key", locals).toEqual("value");
|
expectEval("key", null, locals).toEqual("value");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should fall back to a regular field read when ContextWithVariableBindings "+
|
it("should fall back to a regular field read when Locals "+
|
||||||
"does not have the requested field", () => {
|
"does not have the requested field", () => {
|
||||||
var locals = new ContextWithVariableBindings(td(999), MapWrapper.create());
|
var locals = new Locals(null, MapWrapper.create());
|
||||||
expectEval("a", locals).toEqual(999);
|
expectEval("a", td(999), locals).toEqual(999);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -216,25 +222,26 @@ export function main() {
|
||||||
expectEval("fn().add(1,2)", td(0, 0, td())).toEqual(3);
|
expectEval("fn().add(1,2)", td(0, 0, td())).toEqual(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should throw when more than 10 arguments', () => {
|
||||||
|
expectEvalError("fn(1,2,3,4,5,6,7,8,9,10,11)").toThrowError(new RegExp('more than'));
|
||||||
|
});
|
||||||
|
|
||||||
it('should throw when no method', () => {
|
it('should throw when no method', () => {
|
||||||
expectEvalError("blah()").toThrowError();
|
expectEvalError("blah()").toThrowError();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should evaluate a method from ContextWithVariableBindings', () => {
|
it('should evaluate a method from Locals', () => {
|
||||||
var context = new ContextWithVariableBindings(
|
var locals = new Locals(
|
||||||
td(0, 0, 'parent'),
|
null,
|
||||||
MapWrapper.createFromPairs([['fn', () => 'child']])
|
MapWrapper.createFromPairs([['fn', () => 'child']])
|
||||||
);
|
);
|
||||||
expectEval("fn()", context).toEqual('child');
|
expectEval("fn()", td(0, 0, 'parent'), locals).toEqual('child');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fall back to the parent context when ContextWithVariableBindings does not ' +
|
it('should fall back to the parent context when Locals does not ' +
|
||||||
'have the requested method', () => {
|
'have the requested method', () => {
|
||||||
var context = new ContextWithVariableBindings(
|
var locals = new Locals(null, MapWrapper.create());
|
||||||
td(0, 0, 'parent'),
|
expectEval("fn()", td(0, 0, 'parent'), locals).toEqual('parent');
|
||||||
MapWrapper.create()
|
|
||||||
);
|
|
||||||
expectEval("fn()", context).toEqual('parent');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -314,14 +321,14 @@ export function main() {
|
||||||
|
|
||||||
it('should reassign when no variable binding with the given name', () => {
|
it('should reassign when no variable binding with the given name', () => {
|
||||||
var context = td();
|
var context = td();
|
||||||
var locals = new ContextWithVariableBindings(context, MapWrapper.create());
|
var locals = new Locals(null, MapWrapper.create());
|
||||||
expectEval('a = 200', locals).toEqual(200);
|
expectEval('a = 200', context, locals).toEqual(200);
|
||||||
expect(context.a).toEqual(200);
|
expect(context.a).toEqual(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when reassigning a variable binding', () => {
|
it('should throw when reassigning a variable binding', () => {
|
||||||
var locals = new ContextWithVariableBindings(null, MapWrapper.createFromPairs([["key", "value"]]));
|
var locals = new Locals(null, MapWrapper.createFromPairs([["key", "value"]]));
|
||||||
expectEvalError('key = 200', locals).toThrowError(new RegExp("Cannot reassign a variable binding"));
|
expectEvalError('key = 200', null, locals).toThrowError(new RegExp("Cannot reassign a variable binding"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -346,7 +353,7 @@ export function main() {
|
||||||
|
|
||||||
it('should pass exceptions', () => {
|
it('should pass exceptions', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
parseAction('a()').eval(td(() => {throw new BaseException("boo to you")}));
|
parseAction('a()').eval(td(() => {throw new BaseException("boo to you")}), emptyLocals());
|
||||||
}).toThrowError('boo to you');
|
}).toThrowError('boo to you');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -579,9 +586,8 @@ export function main() {
|
||||||
|
|
||||||
describe('wrapLiteralPrimitive', () => {
|
describe('wrapLiteralPrimitive', () => {
|
||||||
it('should wrap a literal primitive', () => {
|
it('should wrap a literal primitive', () => {
|
||||||
expect(createParser().wrapLiteralPrimitive("foo", null).eval(null)).toEqual("foo");
|
expect(createParser().wrapLiteralPrimitive("foo", null).eval(null, emptyLocals())).toEqual("foo");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ export function main() {
|
||||||
function createView(pv) {
|
function createView(pv) {
|
||||||
ctx = new MyComp();
|
ctx = new MyComp();
|
||||||
view = pv.instantiate(null, null);
|
view = pv.instantiate(null, null);
|
||||||
view.hydrate(new Injector([]), null, null, ctx);
|
view.hydrate(new Injector([]), null, null, ctx, null);
|
||||||
cd = view.changeDetector;
|
cd = view.changeDetector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ export function main() {
|
||||||
ctx.ctxProp = 'a';
|
ctx.ctxProp = 'a';
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
var comp = view.contextWithLocals.get("comp");
|
var comp = view.locals.get("comp");
|
||||||
|
|
||||||
// it is doubled twice: once in the binding, second time in the bind config
|
// it is doubled twice: once in the binding, second time in the bind config
|
||||||
expect(comp.prop).toEqual('aaaa');
|
expect(comp.prop).toEqual('aaaa');
|
||||||
|
@ -345,8 +345,8 @@ export function main() {
|
||||||
compiler.compile(MyComp).then((pv) => {
|
compiler.compile(MyComp).then((pv) => {
|
||||||
createView(pv);
|
createView(pv);
|
||||||
|
|
||||||
expect(view.contextWithLocals).not.toBe(null);
|
expect(view.locals).not.toBe(null);
|
||||||
expect(view.contextWithLocals.get('alice')).toBeAnInstanceOf(ChildComp);
|
expect(view.locals.get('alice')).toBeAnInstanceOf(ChildComp);
|
||||||
|
|
||||||
async.done();
|
async.done();
|
||||||
})
|
})
|
||||||
|
@ -361,10 +361,10 @@ export function main() {
|
||||||
compiler.compile(MyComp).then((pv) => {
|
compiler.compile(MyComp).then((pv) => {
|
||||||
createView(pv);
|
createView(pv);
|
||||||
|
|
||||||
expect(view.contextWithLocals).not.toBe(null);
|
expect(view.locals).not.toBe(null);
|
||||||
expect(view.contextWithLocals.get('alice')).toBeAnInstanceOf(ChildComp);
|
expect(view.locals.get('alice')).toBeAnInstanceOf(ChildComp);
|
||||||
expect(view.contextWithLocals.get('bob')).toBeAnInstanceOf(ChildComp);
|
expect(view.locals.get('bob')).toBeAnInstanceOf(ChildComp);
|
||||||
expect(view.contextWithLocals.get('alice')).not.toBe(view.contextWithLocals.get('bob'));
|
expect(view.locals.get('alice')).not.toBe(view.locals.get('bob'));
|
||||||
|
|
||||||
async.done();
|
async.done();
|
||||||
})
|
})
|
||||||
|
@ -379,8 +379,8 @@ export function main() {
|
||||||
compiler.compile(MyComp).then((pv) => {
|
compiler.compile(MyComp).then((pv) => {
|
||||||
createView(pv);
|
createView(pv);
|
||||||
|
|
||||||
expect(view.contextWithLocals).not.toBe(null);
|
expect(view.locals).not.toBe(null);
|
||||||
expect(view.contextWithLocals.get('alice')).toBeAnInstanceOf(ChildComp);
|
expect(view.locals.get('alice')).toBeAnInstanceOf(ChildComp);
|
||||||
|
|
||||||
async.done();
|
async.done();
|
||||||
})
|
})
|
||||||
|
@ -392,9 +392,9 @@ export function main() {
|
||||||
|
|
||||||
compiler.compile(MyComp).then((pv) => {
|
compiler.compile(MyComp).then((pv) => {
|
||||||
createView(pv);
|
createView(pv);
|
||||||
expect(view.contextWithLocals).not.toBe(null);
|
expect(view.locals).not.toBe(null);
|
||||||
|
|
||||||
var value = view.contextWithLocals.get('alice');
|
var value = view.locals.get('alice');
|
||||||
expect(value).not.toBe(null);
|
expect(value).not.toBe(null);
|
||||||
expect(value.tagName.toLowerCase()).toEqual('div');
|
expect(value.tagName.toLowerCase()).toEqual('div');
|
||||||
|
|
||||||
|
@ -411,7 +411,7 @@ export function main() {
|
||||||
compiler.compile(MyComp).then((pv) => {
|
compiler.compile(MyComp).then((pv) => {
|
||||||
createView(pv);
|
createView(pv);
|
||||||
|
|
||||||
var cmp = view.contextWithLocals.get('cmp');
|
var cmp = view.locals.get('cmp');
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
expect(cmp.numberOfChecks).toEqual(1);
|
expect(cmp.numberOfChecks).toEqual(1);
|
||||||
|
@ -436,7 +436,7 @@ export function main() {
|
||||||
compiler.compile(MyComp).then((pv) => {
|
compiler.compile(MyComp).then((pv) => {
|
||||||
createView(pv);
|
createView(pv);
|
||||||
|
|
||||||
var childComponent = view.contextWithLocals.get('child');
|
var childComponent = view.locals.get('child');
|
||||||
expect(childComponent.myParent).toBeAnInstanceOf(SomeDirective);
|
expect(childComponent.myParent).toBeAnInstanceOf(SomeDirective);
|
||||||
|
|
||||||
async.done();
|
async.done();
|
||||||
|
@ -457,7 +457,7 @@ export function main() {
|
||||||
compiler.compile(MyComp).then((pv) => {
|
compiler.compile(MyComp).then((pv) => {
|
||||||
createView(pv);
|
createView(pv);
|
||||||
|
|
||||||
var childComponent = view.contextWithLocals.get('child');
|
var childComponent = view.locals.get('child');
|
||||||
expect(childComponent.myAncestor).toBeAnInstanceOf(SomeDirective);
|
expect(childComponent.myAncestor).toBeAnInstanceOf(SomeDirective);
|
||||||
|
|
||||||
async.done();
|
async.done();
|
||||||
|
@ -479,9 +479,8 @@ export function main() {
|
||||||
createView(pv);
|
createView(pv);
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
// Note: viewContainers is a sparse array!
|
|
||||||
var subview = view.viewContainers[1].get(0);
|
var subview = view.viewContainers[1].get(0);
|
||||||
var childComponent = subview.contextWithLocals.get('child');
|
var childComponent = subview.locals.get('child');
|
||||||
expect(childComponent.myAncestor).toBeAnInstanceOf(SomeDirective);
|
expect(childComponent.myAncestor).toBeAnInstanceOf(SomeDirective);
|
||||||
|
|
||||||
async.done();
|
async.done();
|
||||||
|
|
|
@ -83,7 +83,7 @@ export function main() {
|
||||||
function instantiateView(protoView) {
|
function instantiateView(protoView) {
|
||||||
evalContext = new Context();
|
evalContext = new Context();
|
||||||
view = protoView.instantiate(null, null);
|
view = protoView.instantiate(null, null);
|
||||||
view.hydrate(new Injector([]), null, null, evalContext);
|
view.hydrate(new Injector([]), null, null, evalContext, null);
|
||||||
changeDetector = view.changeDetector;
|
changeDetector = view.changeDetector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,7 +380,7 @@ export function main() {
|
||||||
|
|
||||||
var eventMap = StringMapWrapper.get(pv.elementBinders[0].events, 'event1');
|
var eventMap = StringMapWrapper.get(pv.elementBinders[0].events, 'event1');
|
||||||
var ast = MapWrapper.get(eventMap, -1);
|
var ast = MapWrapper.get(eventMap, -1);
|
||||||
expect(ast.eval(null)).toBe(2);
|
expect(ast.eval(null, null)).toBe(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should bind directive events', () => {
|
it('should bind directive events', () => {
|
||||||
|
@ -399,7 +399,7 @@ export function main() {
|
||||||
var ast = MapWrapper.get(eventMap, 0);
|
var ast = MapWrapper.get(eventMap, 0);
|
||||||
|
|
||||||
var context = new SomeDecoratorWithEvent();
|
var context = new SomeDecoratorWithEvent();
|
||||||
expect(ast.eval(context)).toEqual('onEvent() callback');
|
expect(ast.eval(context, null)).toEqual('onEvent() callback');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should bind directive properties', () => {
|
it('should bind directive properties', () => {
|
||||||
|
@ -539,7 +539,6 @@ class SomeDecoratorDirectiveWithBinding {
|
||||||
events: {'event': 'onEvent($event)'}
|
events: {'event': 'onEvent($event)'}
|
||||||
})
|
})
|
||||||
class SomeDecoratorWithEvent {
|
class SomeDecoratorWithEvent {
|
||||||
// Added here so that we don't have to wrap the content in a ContextWithVariableBindings
|
|
||||||
$event: string;
|
$event: string;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
|
@ -49,6 +49,15 @@ export function main() {
|
||||||
expect(results[1].inheritedElementBinder.nestedProtoView).toBe(results[2].inheritedProtoView);
|
expect(results[1].inheritedElementBinder.nestedProtoView).toBe(results[2].inheritedProtoView);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should set the parent proto view', () => {
|
||||||
|
var element = el('<div viewroot><template><a viewroot></a></template></div>');
|
||||||
|
var results = createPipeline().process(element);
|
||||||
|
|
||||||
|
var parentProtoView = results[1].inheritedProtoView;
|
||||||
|
var nestedProtoView = results[2].inheritedProtoView;
|
||||||
|
expect(nestedProtoView.parentProtoView).toBe(parentProtoView);
|
||||||
|
});
|
||||||
|
|
||||||
it('should bind variables to the nested ProtoView', () => {
|
it('should bind variables to the nested ProtoView', () => {
|
||||||
var element = el('<div viewroot><template var-binding><a viewroot></a></template></div>');
|
var element = el('<div viewroot><template var-binding><a viewroot></a></template></div>');
|
||||||
var results = createPipeline({
|
var results = createPipeline({
|
||||||
|
@ -71,7 +80,7 @@ export function main() {
|
||||||
}).process(element);
|
}).process(element);
|
||||||
|
|
||||||
var protoView = results[0].inheritedProtoView;
|
var protoView = results[0].inheritedProtoView;
|
||||||
expect(protoView.protoContextLocals).toEqual(MapWrapper.createFromStringMap({
|
expect(protoView.protoLocals).toEqual(MapWrapper.createFromStringMap({
|
||||||
'map2': null,
|
'map2': null,
|
||||||
'map1': null
|
'map1': null
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -379,6 +379,6 @@ class MyComp {
|
||||||
|
|
||||||
function createView(pv) {
|
function createView(pv) {
|
||||||
var view = pv.instantiate(null, null);
|
var view = pv.instantiate(null, null);
|
||||||
view.hydrate(new Injector([]), null, null, {});
|
view.hydrate(new Injector([]), null, null, {}, null);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {DynamicProtoChangeDetector, ChangeDetector, Lexer, Parser} from 'angular
|
||||||
|
|
||||||
function createView(nodes) {
|
function createView(nodes) {
|
||||||
var view = new View(null, nodes, MapWrapper.create());
|
var view = new View(null, nodes, MapWrapper.create());
|
||||||
var cd = new DynamicProtoChangeDetector(null).instantiate(view, []);
|
var cd = new DynamicProtoChangeDetector(null).instantiate(view, [], null);
|
||||||
view.init(cd, [], [], [], [], [], [], [], [], []);
|
view.init(cd, [], [], [], [], [], [], [], [], []);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,8 @@ class HydrateAwareFakeView {
|
||||||
return this.isHydrated;
|
return this.isHydrated;
|
||||||
}
|
}
|
||||||
|
|
||||||
hydrate(_, __, ___, ____) {
|
|
||||||
|
hydrate(_, __, ___, ____, _____) {
|
||||||
this.isHydrated = true;
|
this.isHydrated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ export function main() {
|
||||||
function createView(protoView, eventManager: EventManager = null) {
|
function createView(protoView, eventManager: EventManager = null) {
|
||||||
var ctx = new MyEvaluationContext();
|
var ctx = new MyEvaluationContext();
|
||||||
var view = protoView.instantiate(null, eventManager);
|
var view = protoView.instantiate(null, eventManager);
|
||||||
view.hydrate(null, null, null, ctx);
|
view.hydrate(null, null, null, ctx, null);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ export function main() {
|
||||||
|
|
||||||
it('should be able to be hydrated and dehydrated', () => {
|
it('should be able to be hydrated and dehydrated', () => {
|
||||||
var ctx = new Object();
|
var ctx = new Object();
|
||||||
view.hydrate(null, null, null, ctx);
|
view.hydrate(null, null, null, ctx, null);
|
||||||
expect(view.hydrated()).toBe(true);
|
expect(view.hydrated()).toBe(true);
|
||||||
|
|
||||||
view.dehydrate();
|
view.dehydrate();
|
||||||
|
@ -78,7 +78,7 @@ export function main() {
|
||||||
|
|
||||||
it('should hydrate and dehydrate the change detector', () => {
|
it('should hydrate and dehydrate the change detector', () => {
|
||||||
var ctx = new Object();
|
var ctx = new Object();
|
||||||
view.hydrate(null, null, null, ctx);
|
view.hydrate(null, null, null, ctx, null);
|
||||||
expect(view.changeDetector.hydrated()).toBe(true);
|
expect(view.changeDetector.hydrated()).toBe(true);
|
||||||
|
|
||||||
view.dehydrate();
|
view.dehydrate();
|
||||||
|
@ -104,7 +104,7 @@ export function main() {
|
||||||
|
|
||||||
it('should support setting of declared locals', () => {
|
it('should support setting of declared locals', () => {
|
||||||
view.setLocal('context-foo', 'bar');
|
view.setLocal('context-foo', 'bar');
|
||||||
expect(view.context.get('template-foo')).toBe('bar');
|
expect(view.locals.get('template-foo')).toBe('bar');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not throw on undeclared locals', () => {
|
it('should not throw on undeclared locals', () => {
|
||||||
|
@ -114,8 +114,8 @@ export function main() {
|
||||||
it('when dehydrated should set locals to null', () => {
|
it('when dehydrated should set locals to null', () => {
|
||||||
view.setLocal('context-foo', 'bar');
|
view.setLocal('context-foo', 'bar');
|
||||||
view.dehydrate();
|
view.dehydrate();
|
||||||
view.hydrate(null, null, null, new Object());
|
view.hydrate(null, null, null, new Object(), null);
|
||||||
expect(view.context.get('template-foo')).toBe(null);
|
expect(view.locals.get('template-foo')).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when trying to set on dehydrated view', () => {
|
it('should throw when trying to set on dehydrated view', () => {
|
||||||
|
@ -136,7 +136,7 @@ export function main() {
|
||||||
var pv = new ProtoView(templateAwareCreateElement('<div id="1"></div>'),
|
var pv = new ProtoView(templateAwareCreateElement('<div id="1"></div>'),
|
||||||
new DynamicProtoChangeDetector(null), null);
|
new DynamicProtoChangeDetector(null), null);
|
||||||
var view = pv.instantiate(null, null);
|
var view = pv.instantiate(null, null);
|
||||||
view.hydrate(null, null, null, null);
|
view.hydrate(null, null, null, null, null);
|
||||||
expect(view.nodes.length).toBe(1);
|
expect(view.nodes.length).toBe(1);
|
||||||
expect(DOM.getAttribute(view.nodes[0], 'id')).toEqual('1');
|
expect(DOM.getAttribute(view.nodes[0], 'id')).toEqual('1');
|
||||||
});
|
});
|
||||||
|
@ -150,7 +150,7 @@ export function main() {
|
||||||
pv.bindElementProperty(parser.parseBinding('a', null), 'prop', reflector.setter('prop'));
|
pv.bindElementProperty(parser.parseBinding('a', null), 'prop', reflector.setter('prop'));
|
||||||
|
|
||||||
var view = pv.instantiate(null, null);
|
var view = pv.instantiate(null, null);
|
||||||
view.hydrate(null, null, null, null);
|
view.hydrate(null, null, null, null, null);
|
||||||
expect(view.bindElements.length).toEqual(1);
|
expect(view.bindElements.length).toEqual(1);
|
||||||
expect(view.bindElements[0]).toBe(view.nodes[0]);
|
expect(view.bindElements[0]).toBe(view.nodes[0]);
|
||||||
});
|
});
|
||||||
|
@ -162,7 +162,7 @@ export function main() {
|
||||||
pv.bindElementProperty(parser.parseBinding('b', null), 'a', reflector.setter('a'));
|
pv.bindElementProperty(parser.parseBinding('b', null), 'a', reflector.setter('a'));
|
||||||
|
|
||||||
var view = pv.instantiate(null, null);
|
var view = pv.instantiate(null, null);
|
||||||
view.hydrate(null, null, null, null);
|
view.hydrate(null, null, null, null, null);
|
||||||
expect(view.bindElements.length).toEqual(1);
|
expect(view.bindElements.length).toEqual(1);
|
||||||
expect(view.bindElements[0]).toBe(view.nodes[0].childNodes[1]);
|
expect(view.bindElements[0]).toBe(view.nodes[0].childNodes[1]);
|
||||||
});
|
});
|
||||||
|
@ -179,7 +179,7 @@ export function main() {
|
||||||
pv.bindTextNode(2, parser.parseBinding('b', null));
|
pv.bindTextNode(2, parser.parseBinding('b', null));
|
||||||
|
|
||||||
var view = pv.instantiate(null, null);
|
var view = pv.instantiate(null, null);
|
||||||
view.hydrate(null, null, null, null);
|
view.hydrate(null, null, null, null, null);
|
||||||
expect(view.textNodes.length).toEqual(2);
|
expect(view.textNodes.length).toEqual(2);
|
||||||
expect(view.textNodes[0]).toBe(view.nodes[0].childNodes[0]);
|
expect(view.textNodes[0]).toBe(view.nodes[0].childNodes[0]);
|
||||||
expect(view.textNodes[1]).toBe(view.nodes[0].childNodes[2]);
|
expect(view.textNodes[1]).toBe(view.nodes[0].childNodes[2]);
|
||||||
|
@ -192,7 +192,7 @@ export function main() {
|
||||||
pv.bindTextNode(0, parser.parseBinding('b', null));
|
pv.bindTextNode(0, parser.parseBinding('b', null));
|
||||||
|
|
||||||
var view = pv.instantiate(null, null);
|
var view = pv.instantiate(null, null);
|
||||||
view.hydrate(null, null, null, null);
|
view.hydrate(null, null, null, null, null);
|
||||||
expect(view.textNodes.length).toEqual(1);
|
expect(view.textNodes.length).toEqual(1);
|
||||||
expect(view.textNodes[0]).toBe(view.nodes[0].childNodes[1].childNodes[0]);
|
expect(view.textNodes[0]).toBe(view.nodes[0].childNodes[1].childNodes[0]);
|
||||||
});
|
});
|
||||||
|
@ -207,7 +207,7 @@ export function main() {
|
||||||
new NativeShadowDomStrategy(null));
|
new NativeShadowDomStrategy(null));
|
||||||
pv.instantiateInPlace = true;
|
pv.instantiateInPlace = true;
|
||||||
var view = pv.instantiate(null, null);
|
var view = pv.instantiate(null, null);
|
||||||
view.hydrate(null, null, null, null);
|
view.hydrate(null, null, null, null, null);
|
||||||
expect(view.nodes[0]).toBe(template);
|
expect(view.nodes[0]).toBe(template);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ export function main() {
|
||||||
var pv = new ProtoView(template, new DynamicProtoChangeDetector(null),
|
var pv = new ProtoView(template, new DynamicProtoChangeDetector(null),
|
||||||
new NativeShadowDomStrategy(null))
|
new NativeShadowDomStrategy(null))
|
||||||
var view = pv.instantiate(null, null);
|
var view = pv.instantiate(null, null);
|
||||||
view.hydrate(null, null, null, null);
|
view.hydrate(null, null, null, null, null);
|
||||||
expect(view.nodes[0]).not.toBe(template);
|
expect(view.nodes[0]).not.toBe(template);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -236,7 +236,7 @@ export function main() {
|
||||||
pv.bindElement(null, 0, new ProtoElementInjector(null, 1, [SomeDirective]));
|
pv.bindElement(null, 0, new ProtoElementInjector(null, 1, [SomeDirective]));
|
||||||
|
|
||||||
var view = pv.instantiate(null, null);
|
var view = pv.instantiate(null, null);
|
||||||
view.hydrate(null, null, null, null);
|
view.hydrate(null, null, null, null, null);
|
||||||
expect(view.elementInjectors.length).toBe(1);
|
expect(view.elementInjectors.length).toBe(1);
|
||||||
expect(view.elementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true);
|
expect(view.elementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true);
|
||||||
});
|
});
|
||||||
|
@ -249,7 +249,7 @@ export function main() {
|
||||||
pv.bindElement(null, 0, new ProtoElementInjector(protoParent, 1, [AnotherDirective]));
|
pv.bindElement(null, 0, new ProtoElementInjector(protoParent, 1, [AnotherDirective]));
|
||||||
|
|
||||||
var view = pv.instantiate(null, null);
|
var view = pv.instantiate(null, null);
|
||||||
view.hydrate(null, null, null, null);
|
view.hydrate(null, null, null, null, null);
|
||||||
expect(view.elementInjectors.length).toBe(2);
|
expect(view.elementInjectors.length).toBe(2);
|
||||||
expect(view.elementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true);
|
expect(view.elementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true);
|
||||||
expect(view.elementInjectors[1].parent).toBe(view.elementInjectors[0]);
|
expect(view.elementInjectors[1].parent).toBe(view.elementInjectors[0]);
|
||||||
|
@ -296,7 +296,7 @@ export function main() {
|
||||||
pv.bindElement(null, 0, new ProtoElementInjector(protoParent, 1, [AnotherDirective]));
|
pv.bindElement(null, 0, new ProtoElementInjector(protoParent, 1, [AnotherDirective]));
|
||||||
|
|
||||||
var view = pv.instantiate(null, null);
|
var view = pv.instantiate(null, null);
|
||||||
view.hydrate(null, null, null, null);
|
view.hydrate(null, null, null, null, null);
|
||||||
expect(view.rootElementInjectors.length).toBe(1);
|
expect(view.rootElementInjectors.length).toBe(1);
|
||||||
expect(view.rootElementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true);
|
expect(view.rootElementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true);
|
||||||
});
|
});
|
||||||
|
@ -308,7 +308,7 @@ export function main() {
|
||||||
pv.bindElement(null, 0, new ProtoElementInjector(null, 2, [AnotherDirective]));
|
pv.bindElement(null, 0, new ProtoElementInjector(null, 2, [AnotherDirective]));
|
||||||
|
|
||||||
var view = pv.instantiate(null, null);
|
var view = pv.instantiate(null, null);
|
||||||
view.hydrate(null, null, null, null);
|
view.hydrate(null, null, null, null, null);
|
||||||
expect(view.rootElementInjectors.length).toBe(2)
|
expect(view.rootElementInjectors.length).toBe(2)
|
||||||
expect(view.rootElementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true);
|
expect(view.rootElementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true);
|
||||||
expect(view.rootElementInjectors[1].get(AnotherDirective) instanceof AnotherDirective).toBe(true);
|
expect(view.rootElementInjectors[1].get(AnotherDirective) instanceof AnotherDirective).toBe(true);
|
||||||
|
@ -331,7 +331,7 @@ export function main() {
|
||||||
function createNestedView(protoView) {
|
function createNestedView(protoView) {
|
||||||
ctx = new MyEvaluationContext();
|
ctx = new MyEvaluationContext();
|
||||||
var view = protoView.instantiate(null, null);
|
var view = protoView.instantiate(null, null);
|
||||||
view.hydrate(new Injector([]), null, null, ctx);
|
view.hydrate(new Injector([]), null, null, ctx, null);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -643,7 +643,7 @@ export function main() {
|
||||||
someComponentDirective, new DynamicProtoChangeDetector(null),
|
someComponentDirective, new DynamicProtoChangeDetector(null),
|
||||||
new NativeShadowDomStrategy(null));
|
new NativeShadowDomStrategy(null));
|
||||||
var view = rootProtoView.instantiate(null, null);
|
var view = rootProtoView.instantiate(null, null);
|
||||||
view.hydrate(new Injector([]), null, null, null);
|
view.hydrate(new Injector([]), null, null, null, null);
|
||||||
expect(view.rootElementInjectors[0].get(SomeComponent)).not.toBe(null);
|
expect(view.rootElementInjectors[0].get(SomeComponent)).not.toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -652,7 +652,7 @@ export function main() {
|
||||||
someComponentDirective, new DynamicProtoChangeDetector(null),
|
someComponentDirective, new DynamicProtoChangeDetector(null),
|
||||||
new NativeShadowDomStrategy(null));
|
new NativeShadowDomStrategy(null));
|
||||||
var view = rootProtoView.instantiate(null, null);
|
var view = rootProtoView.instantiate(null, null);
|
||||||
view.hydrate(new Injector([]), null, null, null);
|
view.hydrate(new Injector([]), null, null, null, null);
|
||||||
expect(element.shadowRoot.childNodes[0].childNodes[0].nodeValue).toEqual('hi');
|
expect(element.shadowRoot.childNodes[0].childNodes[0].nodeValue).toEqual('hi');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -45,7 +45,7 @@ export function main() {
|
||||||
function createView(pv) {
|
function createView(pv) {
|
||||||
component = new TestComponent();
|
component = new TestComponent();
|
||||||
view = pv.instantiate(null, null);
|
view = pv.instantiate(null, null);
|
||||||
view.hydrate(new Injector([]), null, null, component);
|
view.hydrate(new Injector([]), null, null, component, null);
|
||||||
cd = view.changeDetector;
|
cd = view.changeDetector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,20 +201,19 @@ export function main() {
|
||||||
compileWithTemplate(
|
compileWithTemplate(
|
||||||
'<div><div template="foreach #item in items">' +
|
'<div><div template="foreach #item in items">' +
|
||||||
'<div template="foreach #subitem in item">' +
|
'<div template="foreach #subitem in item">' +
|
||||||
'{{subitem}};' +
|
'{{subitem}}-{{item.length}};' +
|
||||||
'</div>|</div></div>'
|
'</div>|</div></div>'
|
||||||
).then((pv) => {
|
).then((pv) => {
|
||||||
createView(pv);
|
createView(pv);
|
||||||
component.items = [['a', 'b'], ['c','d']];
|
component.items = [['a', 'b'], ['c']];
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
expect(DOM.getText(view.nodes[0])).toEqual('a;b;|c;d;|');
|
expect(DOM.getText(view.nodes[0])).toEqual('a-2;b-2;|c-1;|');
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should display indices correctly', inject([AsyncTestCompleter], (async) => {
|
it('should display indices correctly', inject([AsyncTestCompleter], (async) => {
|
||||||
var INDEX_TEMPLATE =
|
var INDEX_TEMPLATE =
|
||||||
'<div><copy-me template="foreach: var item in items; var i=index">{{i.toString()}}</copy-me></div>';
|
'<div><copy-me template="foreach: var item in items; var i=index">{{i.toString()}}</copy-me></div>';
|
||||||
|
@ -243,7 +242,6 @@ class Foo {
|
||||||
@Component({selector: 'test-cmp'})
|
@Component({selector: 'test-cmp'})
|
||||||
class TestComponent {
|
class TestComponent {
|
||||||
items: any;
|
items: any;
|
||||||
item: any;
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.items = [1, 2];
|
this.items = [1, 2];
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ export function main() {
|
||||||
function createView(pv) {
|
function createView(pv) {
|
||||||
component = new TestComponent();
|
component = new TestComponent();
|
||||||
view = pv.instantiate(null, null);
|
view = pv.instantiate(null, null);
|
||||||
view.hydrate(new Injector([]), null, null, component);
|
view.hydrate(new Injector([]), null, null, component, null);
|
||||||
cd = view.changeDetector;
|
cd = view.changeDetector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ export function main() {
|
||||||
function createView(pv) {
|
function createView(pv) {
|
||||||
component = new TestComponent();
|
component = new TestComponent();
|
||||||
view = pv.instantiate(null, null);
|
view = pv.instantiate(null, null);
|
||||||
view.hydrate(new Injector([]), null, null, component);
|
view.hydrate(new Injector([]), null, null, component, null);
|
||||||
cd = view.changeDetector;
|
cd = view.changeDetector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ export function main() {
|
||||||
function createView(pv) {
|
function createView(pv) {
|
||||||
component = new TestComponent();
|
component = new TestComponent();
|
||||||
view = pv.instantiate(null, null);
|
view = pv.instantiate(null, null);
|
||||||
view.hydrate(new Injector([]), null, null, component);
|
view.hydrate(new Injector([]), null, null, component, null);
|
||||||
cd = view.changeDetector;
|
cd = view.changeDetector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ export function main() {
|
||||||
|
|
||||||
compiler.compile(componentType).then((pv) => {
|
compiler.compile(componentType).then((pv) => {
|
||||||
var view = pv.instantiate(null, null);
|
var view = pv.instantiate(null, null);
|
||||||
view.hydrate(new Injector([]), null, null, context);
|
view.hydrate(new Injector([]), null, null, context, null);
|
||||||
detectChanges(view);
|
detectChanges(view);
|
||||||
callback(view);
|
callback(view);
|
||||||
});
|
});
|
||||||
|
|
|
@ -105,7 +105,7 @@ function setUpChangeDetection(changeDetection:ChangeDetection, iterations) {
|
||||||
var parser = new Parser(new Lexer());
|
var parser = new Parser(new Lexer());
|
||||||
|
|
||||||
var parentProto = changeDetection.createProtoChangeDetector('parent');
|
var parentProto = changeDetection.createProtoChangeDetector('parent');
|
||||||
var parentCd = parentProto.instantiate(dispatcher, []);
|
var parentCd = parentProto.instantiate(dispatcher, [], []);
|
||||||
|
|
||||||
var proto = changeDetection.createProtoChangeDetector("proto");
|
var proto = changeDetection.createProtoChangeDetector("proto");
|
||||||
var bindingRecords = [
|
var bindingRecords = [
|
||||||
|
@ -126,8 +126,8 @@ function setUpChangeDetection(changeDetection:ChangeDetection, iterations) {
|
||||||
for (var j = 0; j < 10; ++j) {
|
for (var j = 0; j < 10; ++j) {
|
||||||
obj.setField(j, i);
|
obj.setField(j, i);
|
||||||
}
|
}
|
||||||
var cd = proto.instantiate(dispatcher, bindingRecords);
|
var cd = proto.instantiate(dispatcher, bindingRecords, []);
|
||||||
cd.hydrate(obj);
|
cd.hydrate(obj, null);
|
||||||
parentCd.addChild(cd);
|
parentCd.addChild(cd);
|
||||||
}
|
}
|
||||||
return parentCd;
|
return parentCd;
|
||||||
|
|
Loading…
Reference in New Issue