From 3496c8ac546a5e8aa32ceefa37e2c18213832583 Mon Sep 17 00:00:00 2001 From: Marc Laval Date: Thu, 19 Feb 2015 10:15:06 +0100 Subject: [PATCH] refactor(change_detection): remove circular dependencies Closes #712 --- .../change_detection_jit_generator.es6 | 5 +- .../change_detection/change_detection_util.js | 2 +- .../angular2/src/change_detection/coalesce.js | 2 +- .../dynamic_change_detector.js | 5 +- .../src/change_detection/exceptions.js | 2 +- .../change_detection/proto_change_detector.js | 72 ++++--------------- .../src/change_detection/proto_record.js | 60 ++++++++++++++++ .../test/change_detection/coalesce_spec.js | 2 +- 8 files changed, 81 insertions(+), 69 deletions(-) create mode 100644 modules/angular2/src/change_detection/proto_record.js diff --git a/modules/angular2/src/change_detection/change_detection_jit_generator.es6 b/modules/angular2/src/change_detection/change_detection_jit_generator.es6 index 4cb9f13df6..885ad8a5af 100644 --- a/modules/angular2/src/change_detection/change_detection_jit_generator.es6 +++ b/modules/angular2/src/change_detection/change_detection_jit_generator.es6 @@ -16,9 +16,8 @@ import { RECORD_TYPE_KEYED_ACCESS, RECORD_TYPE_INVOKE_FORMATTER, RECORD_TYPE_STRUCTURAL_CHECK, - RECORD_TYPE_INTERPOLATE, - ProtoChangeDetector - } from './proto_change_detector'; + RECORD_TYPE_INTERPOLATE + } from './proto_record'; /** * The code generator takes a list of proto records and creates a function/class diff --git a/modules/angular2/src/change_detection/change_detection_util.js b/modules/angular2/src/change_detection/change_detection_util.js index 16e85217fc..fa8bfc5a0a 100644 --- a/modules/angular2/src/change_detection/change_detection_util.js +++ b/modules/angular2/src/change_detection/change_detection_util.js @@ -1,7 +1,7 @@ import {isPresent, isBlank, BaseException, Type} from 'angular2/src/facade/lang'; import {List, ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection'; import {ContextWithVariableBindings} from './parser/context_with_variable_bindings'; -import {ProtoRecord} from './proto_change_detector'; +import {ProtoRecord} from './proto_record'; import {ExpressionChangedAfterItHasBeenChecked} from './exceptions'; import {NO_CHANGE} from './pipes/pipe'; import {ChangeRecord, ChangeDetector, CHECK_ALWAYS, CHECK_ONCE, CHECKED, DETACHED} from './interfaces'; diff --git a/modules/angular2/src/change_detection/coalesce.js b/modules/angular2/src/change_detection/coalesce.js index 9f227bedec..a1d0e429de 100644 --- a/modules/angular2/src/change_detection/coalesce.js +++ b/modules/angular2/src/change_detection/coalesce.js @@ -1,6 +1,6 @@ import {isPresent} from 'angular2/src/facade/lang'; import {List, ListWrapper, Map, MapWrapper} from 'angular2/src/facade/collection'; -import {RECORD_TYPE_SELF, ProtoRecord} from './proto_change_detector'; +import {RECORD_TYPE_SELF, ProtoRecord} from './proto_record'; /** * Removes "duplicate" records. It assuming that record evaluation does not diff --git a/modules/angular2/src/change_detection/dynamic_change_detector.js b/modules/angular2/src/change_detection/dynamic_change_detector.js index 1605f386ec..63fd06bd7b 100644 --- a/modules/angular2/src/change_detection/dynamic_change_detector.js +++ b/modules/angular2/src/change_detection/dynamic_change_detector.js @@ -18,9 +18,8 @@ import { RECORD_TYPE_KEYED_ACCESS, RECORD_TYPE_INVOKE_FORMATTER, RECORD_TYPE_STRUCTURAL_CHECK, - RECORD_TYPE_INTERPOLATE, - ProtoChangeDetector - } from './proto_change_detector'; + RECORD_TYPE_INTERPOLATE + } from './proto_record'; import {ExpressionChangedAfterItHasBeenChecked, ChangeDetectionError} from './exceptions'; diff --git a/modules/angular2/src/change_detection/exceptions.js b/modules/angular2/src/change_detection/exceptions.js index 1f6308a1d7..34c9cc1fbe 100644 --- a/modules/angular2/src/change_detection/exceptions.js +++ b/modules/angular2/src/change_detection/exceptions.js @@ -1,4 +1,4 @@ -import {ProtoRecord} from './proto_change_detector'; +import {ProtoRecord} from './proto_record'; export class ExpressionChangedAfterItHasBeenChecked extends Error { message:string; diff --git a/modules/angular2/src/change_detection/proto_change_detector.js b/modules/angular2/src/change_detection/proto_change_detector.js index 67de6def9b..c13b8103d2 100644 --- a/modules/angular2/src/change_detection/proto_change_detector.js +++ b/modules/angular2/src/change_detection/proto_change_detector.js @@ -31,65 +31,19 @@ import {PipeRegistry} from './pipes/pipe_registry'; import {coalesce} from './coalesce'; -export const RECORD_TYPE_SELF = 0; -export const RECORD_TYPE_CONST = 1; -export const RECORD_TYPE_PRIMITIVE_OP = 2; -export const RECORD_TYPE_PROPERTY = 3; -export const RECORD_TYPE_INVOKE_METHOD = 4; -export const RECORD_TYPE_INVOKE_CLOSURE = 5; -export const RECORD_TYPE_KEYED_ACCESS = 6; -export const RECORD_TYPE_INVOKE_FORMATTER = 7; -export const RECORD_TYPE_STRUCTURAL_CHECK = 8; -export const RECORD_TYPE_INTERPOLATE = 9; - -export class ProtoRecord { - mode:number; - name:string; - funcOrValue:any; - args:List; - fixedArgs:List; - contextIndex:number; - selfIndex:number; - bindingMemento:any; - directiveMemento:any; - lastInBinding:boolean; - lastInDirective:boolean; - expressionAsString:string; - - constructor(mode:number, - name:string, - funcOrValue, - args:List, - fixedArgs:List, - contextIndex:number, - selfIndex:number, - bindingMemento:any, - directiveMemento:any, - expressionAsString:string, - lastInBinding:boolean, - lastInDirective:boolean) { - - this.mode = mode; - this.name = name; - this.funcOrValue = funcOrValue; - this.args = args; - this.fixedArgs = fixedArgs; - this.contextIndex = contextIndex; - this.selfIndex = selfIndex; - this.bindingMemento = bindingMemento; - this.directiveMemento = directiveMemento; - this.lastInBinding = lastInBinding; - this.lastInDirective = lastInDirective; - this.expressionAsString = expressionAsString; - } - - isPureFunction():boolean { - return this.mode === RECORD_TYPE_INTERPOLATE || - this.mode === RECORD_TYPE_INVOKE_FORMATTER || - this.mode === RECORD_TYPE_PRIMITIVE_OP; - } -} - +import { + ProtoRecord, + RECORD_TYPE_SELF, + RECORD_TYPE_PROPERTY, + RECORD_TYPE_INVOKE_METHOD, + RECORD_TYPE_CONST, + RECORD_TYPE_INVOKE_CLOSURE, + RECORD_TYPE_PRIMITIVE_OP, + RECORD_TYPE_KEYED_ACCESS, + RECORD_TYPE_INVOKE_FORMATTER, + RECORD_TYPE_STRUCTURAL_CHECK, + RECORD_TYPE_INTERPOLATE + } from './proto_record'; export class ProtoChangeDetector { addAst(ast:AST, bindingMemento:any, directiveMemento:any = null, structural:boolean = false){} diff --git a/modules/angular2/src/change_detection/proto_record.js b/modules/angular2/src/change_detection/proto_record.js new file mode 100644 index 0000000000..9aa77ba9ea --- /dev/null +++ b/modules/angular2/src/change_detection/proto_record.js @@ -0,0 +1,60 @@ +import {List} from 'angular2/src/facade/collection'; + +export const RECORD_TYPE_SELF = 0; +export const RECORD_TYPE_CONST = 1; +export const RECORD_TYPE_PRIMITIVE_OP = 2; +export const RECORD_TYPE_PROPERTY = 3; +export const RECORD_TYPE_INVOKE_METHOD = 4; +export const RECORD_TYPE_INVOKE_CLOSURE = 5; +export const RECORD_TYPE_KEYED_ACCESS = 6; +export const RECORD_TYPE_INVOKE_FORMATTER = 7; +export const RECORD_TYPE_STRUCTURAL_CHECK = 8; +export const RECORD_TYPE_INTERPOLATE = 9; + +export class ProtoRecord { + mode:number; + name:string; + funcOrValue:any; + args:List; + fixedArgs:List; + contextIndex:number; + selfIndex:number; + bindingMemento:any; + directiveMemento:any; + lastInBinding:boolean; + lastInDirective:boolean; + expressionAsString:string; + + constructor(mode:number, + name:string, + funcOrValue, + args:List, + fixedArgs:List, + contextIndex:number, + selfIndex:number, + bindingMemento:any, + directiveMemento:any, + expressionAsString:string, + lastInBinding:boolean, + lastInDirective:boolean) { + + this.mode = mode; + this.name = name; + this.funcOrValue = funcOrValue; + this.args = args; + this.fixedArgs = fixedArgs; + this.contextIndex = contextIndex; + this.selfIndex = selfIndex; + this.bindingMemento = bindingMemento; + this.directiveMemento = directiveMemento; + this.lastInBinding = lastInBinding; + this.lastInDirective = lastInDirective; + this.expressionAsString = expressionAsString; + } + + isPureFunction():boolean { + return this.mode === RECORD_TYPE_INTERPOLATE || + this.mode === RECORD_TYPE_INVOKE_FORMATTER || + this.mode === RECORD_TYPE_PRIMITIVE_OP; + } +} diff --git a/modules/angular2/test/change_detection/coalesce_spec.js b/modules/angular2/test/change_detection/coalesce_spec.js index bcb3ab1081..e4d2bc0aca 100644 --- a/modules/angular2/test/change_detection/coalesce_spec.js +++ b/modules/angular2/test/change_detection/coalesce_spec.js @@ -1,7 +1,7 @@ import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib'; import {coalesce} from 'angular2/src/change_detection/coalesce'; -import {RECORD_TYPE_SELF, ProtoRecord} from 'angular2/src/change_detection/proto_change_detector'; +import {RECORD_TYPE_SELF, ProtoRecord} from 'angular2/src/change_detection/proto_record'; export function main() { function r(funcOrValue, args, contextIndex, selfIndex, lastInBinding = false) {