refactor(ChangeDetector): rename WatchGroup into RecordRange
This commit is contained in:
@ -7,7 +7,7 @@ import {ClosureMap} from 'change_detection/parser/closure_map';
|
||||
import {Parser} from 'change_detection/parser/parser';
|
||||
import {Lexer} from 'change_detection/parser/lexer';
|
||||
import {ChangeDetector} from 'change_detection/change_detector';
|
||||
import {WatchGroup} from 'change_detection/watch_group';
|
||||
import {RecordRange} from 'change_detection/record_range';
|
||||
import {TemplateLoader} from './compiler/template_loader';
|
||||
import {Reflector} from './compiler/reflector';
|
||||
import {AnnotatedType} from './compiler/annotated_type';
|
||||
@ -56,7 +56,7 @@ export function documentDependentBindings(appComponentType) {
|
||||
});
|
||||
}, [Compiler, Injector, appElementToken, appComponentAnnotatedTypeToken]),
|
||||
|
||||
bind(appWatchGroupToken).toFactory((rootView) => rootView.watchGroup,
|
||||
bind(appWatchGroupToken).toFactory((rootView) => rootView.recordRange,
|
||||
[appViewToken]),
|
||||
bind(ChangeDetector).toFactory((appWatchGroup) =>
|
||||
new ChangeDetector(appWatchGroup), [appWatchGroupToken])
|
||||
|
@ -4,7 +4,7 @@ import {ListWrapper, List, MapWrapper, StringMapWrapper} from 'facade/collection
|
||||
|
||||
import {Parser} from 'change_detection/parser/parser';
|
||||
import {ClosureMap} from 'change_detection/parser/closure_map';
|
||||
import {ProtoWatchGroup} from 'change_detection/watch_group';
|
||||
import {ProtoRecordRange} from 'change_detection/record_range';
|
||||
|
||||
import {Directive} from '../../annotations/directive';
|
||||
import {Component} from '../../annotations/component';
|
||||
@ -20,7 +20,7 @@ import {CompileControl} from './compile_control';
|
||||
|
||||
/**
|
||||
* Creates the ElementBinders and adds watches to the
|
||||
* ProtoWatchGroup.
|
||||
* ProtoRecordRange.
|
||||
*
|
||||
* Fills:
|
||||
* - CompileElement#inheritedElementBinder
|
||||
|
@ -2,7 +2,7 @@ import {isPresent, BaseException} from 'facade/lang';
|
||||
import {ListWrapper, MapWrapper} from 'facade/collection';
|
||||
|
||||
import {ProtoView} from '../view';
|
||||
import {ProtoWatchGroup} from 'change_detection/watch_group';
|
||||
import {ProtoRecordRange} from 'change_detection/record_range';
|
||||
|
||||
import {CompileStep} from './compile_step';
|
||||
import {CompileElement} from './compile_element';
|
||||
@ -21,7 +21,7 @@ export class ProtoViewBuilder extends CompileStep {
|
||||
process(parent:CompileElement, current:CompileElement, control:CompileControl) {
|
||||
var inheritedProtoView = null;
|
||||
if (current.isViewRoot) {
|
||||
inheritedProtoView = new ProtoView(current.element, new ProtoWatchGroup());
|
||||
inheritedProtoView = new ProtoView(current.element, new ProtoRecordRange());
|
||||
if (isPresent(parent)) {
|
||||
if (isPresent(parent.inheritedElementBinder.nestedProtoView)) {
|
||||
throw new BaseException('Only one nested view per element is allowed');
|
||||
|
@ -1,6 +1,6 @@
|
||||
import {DOM, Element, Node, Text, DocumentFragment, TemplateElement} from 'facade/dom';
|
||||
import {ListWrapper, MapWrapper} from 'facade/collection';
|
||||
import {ProtoWatchGroup, WatchGroup, WatchGroupDispatcher} from 'change_detection/watch_group';
|
||||
import {ProtoRecordRange, RecordRange, WatchGroupDispatcher} from 'change_detection/record_range';
|
||||
import {Record} from 'change_detection/record';
|
||||
import {AST} from 'change_detection/parser/ast';
|
||||
|
||||
@ -25,7 +25,7 @@ export class View {
|
||||
@FIELD('final elementInjectors:List<ElementInjector>')
|
||||
@FIELD('final bindElements:List<Element>')
|
||||
@FIELD('final textNodes:List<Text>')
|
||||
@FIELD('final watchGroup:WatchGroup')
|
||||
@FIELD('final recordRange:RecordRange')
|
||||
/// When the view is part of render tree, the DocumentFragment is empty, which is why we need
|
||||
/// to keep track of the nodes.
|
||||
@FIELD('final nodes:List<Node>')
|
||||
@ -33,15 +33,15 @@ export class View {
|
||||
@FIELD('childViews: List<View>')
|
||||
constructor(nodes:List<Node>, elementInjectors:List,
|
||||
rootElementInjectors:List, textNodes:List, bindElements:List,
|
||||
protoWatchGroup:ProtoWatchGroup, context) {
|
||||
protoRecordRange:ProtoRecordRange, context) {
|
||||
this.nodes = nodes;
|
||||
this.elementInjectors = elementInjectors;
|
||||
this.rootElementInjectors = rootElementInjectors;
|
||||
this.onChangeDispatcher = null;
|
||||
this.textNodes = textNodes;
|
||||
this.bindElements = bindElements;
|
||||
this.watchGroup = protoWatchGroup.instantiate(this, MapWrapper.create());
|
||||
this.watchGroup.setContext(context);
|
||||
this.recordRange = protoRecordRange.instantiate(this, MapWrapper.create());
|
||||
this.recordRange.setContext(context);
|
||||
// TODO(rado): Since this is only used in tests for now, investigate whether
|
||||
// we can remove it.
|
||||
this.childViews = [];
|
||||
@ -65,21 +65,21 @@ export class View {
|
||||
|
||||
addChild(childView: View) {
|
||||
ListWrapper.push(this.childViews, childView);
|
||||
this.watchGroup.addChild(childView.watchGroup);
|
||||
this.recordRange.addRange(childView.recordRange);
|
||||
}
|
||||
}
|
||||
|
||||
export class ProtoView {
|
||||
@FIELD('final element:Element')
|
||||
@FIELD('final elementBinders:List<ElementBinder>')
|
||||
@FIELD('final protoWatchGroup:ProtoWatchGroup')
|
||||
@FIELD('final protoRecordRange:ProtoRecordRange')
|
||||
constructor(
|
||||
template:Element,
|
||||
protoWatchGroup:ProtoWatchGroup) {
|
||||
protoRecordRange:ProtoRecordRange) {
|
||||
this.element = template;
|
||||
this.elementBinders = [];
|
||||
this.variableBindings = MapWrapper.create();
|
||||
this.protoWatchGroup = protoWatchGroup;
|
||||
this.protoRecordRange = protoRecordRange;
|
||||
this.textNodesWithBindingCount = 0;
|
||||
this.elementsWithBindingCount = 0;
|
||||
}
|
||||
@ -115,7 +115,7 @@ export class ProtoView {
|
||||
viewNodes = [clone];
|
||||
}
|
||||
var view = new View(viewNodes, elementInjectors, rootElementInjectors, textNodes,
|
||||
bindElements, this.protoWatchGroup, context);
|
||||
bindElements, this.protoRecordRange, context);
|
||||
|
||||
ProtoView._instantiateDirectives(
|
||||
view, elements, elementInjectors, lightDomAppInjector, shadowAppInjectors);
|
||||
@ -145,7 +145,7 @@ export class ProtoView {
|
||||
elBinder.textNodeIndices = ListWrapper.create();
|
||||
}
|
||||
ListWrapper.push(elBinder.textNodeIndices, indexInParent);
|
||||
this.protoWatchGroup.watch(expression, this.textNodesWithBindingCount++);
|
||||
this.protoRecordRange.addRecordsFromAST(expression, this.textNodesWithBindingCount++);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,7 +157,7 @@ export class ProtoView {
|
||||
elBinder.hasElementPropertyBindings = true;
|
||||
this.elementsWithBindingCount++;
|
||||
}
|
||||
this.protoWatchGroup.watch(expression,
|
||||
this.protoRecordRange.addRecordsFromAST(expression,
|
||||
new ElementPropertyMemento(
|
||||
this.elementsWithBindingCount-1,
|
||||
propertyName
|
||||
@ -184,7 +184,7 @@ export class ProtoView {
|
||||
expression:AST,
|
||||
setterName:string,
|
||||
setter:SetterFn) {
|
||||
this.protoWatchGroup.watch(
|
||||
this.protoRecordRange.addRecordsFromAST(
|
||||
expression,
|
||||
new DirectivePropertyMemento(
|
||||
this.elementBinders.length-1,
|
||||
@ -288,7 +288,7 @@ export class ProtoView {
|
||||
// Used for bootstrapping.
|
||||
static createRootProtoView(protoView: ProtoView,
|
||||
insertionElement, rootComponentAnnotatedType: AnnotatedType): ProtoView {
|
||||
var rootProtoView = new ProtoView(insertionElement, new ProtoWatchGroup());
|
||||
var rootProtoView = new ProtoView(insertionElement, new ProtoRecordRange());
|
||||
var binder = rootProtoView.bindElement(
|
||||
new ProtoElementInjector(null, 0, [rootComponentAnnotatedType.type], true));
|
||||
binder.componentDirective = rootComponentAnnotatedType;
|
||||
|
@ -9,7 +9,7 @@ export * from './annotations/template_config';
|
||||
export * from './application';
|
||||
|
||||
export * from 'change_detection/change_detector';
|
||||
export * from 'change_detection/watch_group';
|
||||
export * from 'change_detection/record_range';
|
||||
export * from 'change_detection/record';
|
||||
|
||||
export * from './compiler/compiler';
|
||||
|
@ -24,12 +24,12 @@ export function main() {
|
||||
compiler = new Compiler(null, new Reflector(), new Parser(new Lexer(), closureMap), closureMap);
|
||||
});
|
||||
|
||||
describe('react to watch group changes', function() {
|
||||
describe('react to record changes', function() {
|
||||
var view, ctx, cd;
|
||||
function createView(pv) {
|
||||
ctx = new MyComp();
|
||||
view = pv.instantiate(ctx, new Injector([]), null);
|
||||
cd = new ChangeDetector(view.watchGroup);
|
||||
cd = new ChangeDetector(view.recordRange);
|
||||
}
|
||||
|
||||
it('should consume text node changes', (done) => {
|
||||
|
@ -16,7 +16,7 @@ import {ProtoView, ElementPropertyMemento, DirectivePropertyMemento} from 'core/
|
||||
import {ProtoElementInjector} from 'core/compiler/element_injector';
|
||||
import {Reflector} from 'core/compiler/reflector';
|
||||
|
||||
import {ProtoWatchGroup} from 'change_detection/watch_group';
|
||||
import {ProtoRecordRange} from 'change_detection/record_range';
|
||||
import {Parser} from 'change_detection/parser/parser';
|
||||
import {Lexer} from 'change_detection/parser/lexer';
|
||||
import {ClosureMap} from 'change_detection/parser/closure_map';
|
||||
@ -36,7 +36,7 @@ export function main() {
|
||||
new MockStep((parent, current, control) => {
|
||||
if (isPresent(current.element.getAttribute('viewroot'))) {
|
||||
current.isViewRoot = true;
|
||||
current.inheritedProtoView = new ProtoView(current.element, new ProtoWatchGroup());
|
||||
current.inheritedProtoView = new ProtoView(current.element, new ProtoRecordRange());
|
||||
} else if (isPresent(parent)) {
|
||||
current.inheritedProtoView = parent.inheritedProtoView;
|
||||
}
|
||||
@ -81,7 +81,7 @@ export function main() {
|
||||
function instantiateView(protoView) {
|
||||
evalContext = new Context();
|
||||
view = protoView.instantiate(evalContext, new Injector([]), null);
|
||||
changeDetector = new ChangeDetector(view.watchGroup);
|
||||
changeDetector = new ChangeDetector(view.recordRange);
|
||||
}
|
||||
|
||||
it('should not create an ElementBinder for elements that have no bindings', () => {
|
||||
@ -206,7 +206,7 @@ export function main() {
|
||||
var results = pipeline.process(createElement('<div viewroot prop-binding directives></div>'));
|
||||
var pv = results[0].inheritedProtoView;
|
||||
results[0].inheritedElementBinder.nestedProtoView = new ProtoView(
|
||||
createElement('<div></div>'), new ProtoWatchGroup());
|
||||
createElement('<div></div>'), new ProtoRecordRange());
|
||||
|
||||
instantiateView(pv);
|
||||
evalContext.prop1 = 'a';
|
||||
|
@ -4,7 +4,7 @@ import {ProtoElementInjector, ElementInjector} from 'core/compiler/element_injec
|
||||
import {Reflector} from 'core/compiler/reflector';
|
||||
import {Component} from 'core/annotations/component';
|
||||
import {Decorator} from 'core/annotations/decorator';
|
||||
import {ProtoWatchGroup} from 'change_detection/watch_group';
|
||||
import {ProtoRecordRange} from 'change_detection/record_range';
|
||||
import {ChangeDetector} from 'change_detection/change_detector';
|
||||
import {TemplateConfig} from 'core/annotations/template_config';
|
||||
import {Parser} from 'change_detection/parser/parser';
|
||||
@ -35,7 +35,7 @@ export function main() {
|
||||
}
|
||||
|
||||
it('should collect the root node in the ProtoView element', () => {
|
||||
var pv = new ProtoView(templateAwareCreateElement('<div id="1"></div>'), new ProtoWatchGroup());
|
||||
var pv = new ProtoView(templateAwareCreateElement('<div id="1"></div>'), new ProtoRecordRange());
|
||||
var view = pv.instantiate(null, null, null);
|
||||
expect(view.nodes.length).toBe(1);
|
||||
expect(view.nodes[0].getAttribute('id')).toEqual('1');
|
||||
@ -44,7 +44,7 @@ export function main() {
|
||||
describe('collect elements with property bindings', () => {
|
||||
|
||||
it('should collect property bindings on the root element if it has the ng-binding class', () => {
|
||||
var pv = new ProtoView(templateAwareCreateElement('<div [prop]="a" class="ng-binding"></div>'), new ProtoWatchGroup());
|
||||
var pv = new ProtoView(templateAwareCreateElement('<div [prop]="a" class="ng-binding"></div>'), new ProtoRecordRange());
|
||||
pv.bindElement(null);
|
||||
pv.bindElementProperty('prop', parser.parseBinding('a').ast);
|
||||
|
||||
@ -55,7 +55,7 @@ export function main() {
|
||||
|
||||
it('should collect property bindings on child elements with ng-binding class', () => {
|
||||
var pv = new ProtoView(templateAwareCreateElement('<div><span></span><span class="ng-binding"></span></div>'),
|
||||
new ProtoWatchGroup());
|
||||
new ProtoRecordRange());
|
||||
pv.bindElement(null);
|
||||
pv.bindElementProperty('a', parser.parseBinding('b').ast);
|
||||
|
||||
@ -69,7 +69,7 @@ export function main() {
|
||||
describe('collect text nodes with bindings', () => {
|
||||
|
||||
it('should collect text nodes under the root element', () => {
|
||||
var pv = new ProtoView(templateAwareCreateElement('<div class="ng-binding">{{}}<span></span>{{}}</div>'), new ProtoWatchGroup());
|
||||
var pv = new ProtoView(templateAwareCreateElement('<div class="ng-binding">{{}}<span></span>{{}}</div>'), new ProtoRecordRange());
|
||||
pv.bindElement(null);
|
||||
pv.bindTextNode(0, parser.parseBinding('a').ast);
|
||||
pv.bindTextNode(2, parser.parseBinding('b').ast);
|
||||
@ -82,7 +82,7 @@ export function main() {
|
||||
|
||||
it('should collect text nodes with bindings on child elements with ng-binding class', () => {
|
||||
var pv = new ProtoView(templateAwareCreateElement('<div><span> </span><span class="ng-binding">{{}}</span></div>'),
|
||||
new ProtoWatchGroup());
|
||||
new ProtoRecordRange());
|
||||
pv.bindElement(null);
|
||||
pv.bindTextNode(0, parser.parseBinding('b').ast);
|
||||
|
||||
@ -97,14 +97,14 @@ export function main() {
|
||||
describe('inplace instantiation', () => {
|
||||
it('should be supported.', () => {
|
||||
var template = createElement('<div></div>')
|
||||
var view = new ProtoView(template, new ProtoWatchGroup())
|
||||
var view = new ProtoView(template, new ProtoRecordRange())
|
||||
.instantiate(null, null, null, true);
|
||||
expect(view.nodes[0]).toBe(template);
|
||||
});
|
||||
|
||||
it('should be off by default.', () => {
|
||||
var template = createElement('<div></div>')
|
||||
var view = new ProtoView(template, new ProtoWatchGroup())
|
||||
var view = new ProtoView(template, new ProtoRecordRange())
|
||||
.instantiate(null, null, null);
|
||||
expect(view.nodes[0]).not.toBe(template);
|
||||
});
|
||||
@ -120,7 +120,7 @@ export function main() {
|
||||
|
||||
describe('create ElementInjectors', () => {
|
||||
it('should use the directives of the ProtoElementInjector', () => {
|
||||
var pv = new ProtoView(createElement('<div class="ng-binding"></div>'), new ProtoWatchGroup());
|
||||
var pv = new ProtoView(createElement('<div class="ng-binding"></div>'), new ProtoRecordRange());
|
||||
pv.bindElement(new ProtoElementInjector(null, 1, [SomeDirective]));
|
||||
|
||||
var view = pv.instantiate(null, null, null);
|
||||
@ -130,7 +130,7 @@ export function main() {
|
||||
|
||||
it('should use the correct parent', () => {
|
||||
var pv = new ProtoView(createElement('<div class="ng-binding"><span class="ng-binding"></span></div>'),
|
||||
new ProtoWatchGroup());
|
||||
new ProtoRecordRange());
|
||||
var protoParent = new ProtoElementInjector(null, 0, [SomeDirective]);
|
||||
pv.bindElement(protoParent);
|
||||
pv.bindElement(new ProtoElementInjector(protoParent, 1, [AnotherDirective]));
|
||||
@ -146,7 +146,7 @@ export function main() {
|
||||
|
||||
it('should collect a single root element injector', () => {
|
||||
var pv = new ProtoView(createElement('<div class="ng-binding"><span class="ng-binding"></span></div>'),
|
||||
new ProtoWatchGroup());
|
||||
new ProtoRecordRange());
|
||||
var protoParent = new ProtoElementInjector(null, 0, [SomeDirective]);
|
||||
pv.bindElement(protoParent);
|
||||
pv.bindElement(new ProtoElementInjector(protoParent, 1, [AnotherDirective]));
|
||||
@ -158,7 +158,7 @@ export function main() {
|
||||
|
||||
it('should collect multiple root element injectors', () => {
|
||||
var pv = new ProtoView(createElement('<div><span class="ng-binding"></span><span class="ng-binding"></span></div>'),
|
||||
new ProtoWatchGroup());
|
||||
new ProtoRecordRange());
|
||||
pv.bindElement(new ProtoElementInjector(null, 1, [SomeDirective]));
|
||||
pv.bindElement(new ProtoElementInjector(null, 2, [AnotherDirective]));
|
||||
|
||||
@ -174,7 +174,7 @@ export function main() {
|
||||
var view, ctx;
|
||||
|
||||
function createComponentWithSubPV(subProtoView) {
|
||||
var pv = new ProtoView(createElement('<cmp class="ng-binding"></cmp>'), new ProtoWatchGroup());
|
||||
var pv = new ProtoView(createElement('<cmp class="ng-binding"></cmp>'), new ProtoRecordRange());
|
||||
var binder = pv.bindElement(new ProtoElementInjector(null, 0, [SomeComponent], true));
|
||||
binder.componentDirective = someComponentDirective;
|
||||
binder.nestedProtoView = subProtoView;
|
||||
@ -187,7 +187,7 @@ export function main() {
|
||||
}
|
||||
|
||||
it('should create shadow dom', () => {
|
||||
var subpv = new ProtoView(createElement('<span>hello shadow dom</span>'), new ProtoWatchGroup());
|
||||
var subpv = new ProtoView(createElement('<span>hello shadow dom</span>'), new ProtoRecordRange());
|
||||
var pv = createComponentWithSubPV(subpv);
|
||||
|
||||
var view = createNestedView(pv);
|
||||
@ -196,7 +196,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should expose component services to the component', () => {
|
||||
var subpv = new ProtoView(createElement('<span></span>'), new ProtoWatchGroup());
|
||||
var subpv = new ProtoView(createElement('<span></span>'), new ProtoRecordRange());
|
||||
var pv = createComponentWithSubPV(subpv);
|
||||
|
||||
var view = createNestedView(pv);
|
||||
@ -208,7 +208,7 @@ export function main() {
|
||||
it('should expose component services and component instance to directives in the shadow Dom',
|
||||
() => {
|
||||
var subpv = new ProtoView(
|
||||
createElement('<div dec class="ng-binding">hello shadow dom</div>'), new ProtoWatchGroup());
|
||||
createElement('<div dec class="ng-binding">hello shadow dom</div>'), new ProtoRecordRange());
|
||||
var subBinder = subpv.bindElement(
|
||||
new ProtoElementInjector(null, 0, [ServiceDependentDecorator]));
|
||||
var pv = createComponentWithSubPV(subpv);
|
||||
@ -226,18 +226,18 @@ export function main() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('react to watch group changes', () => {
|
||||
describe('react to record changes', () => {
|
||||
var view, cd, ctx;
|
||||
|
||||
function createView(protoView) {
|
||||
ctx = new MyEvaluationContext();
|
||||
view = protoView.instantiate(ctx, null, null);
|
||||
cd = new ChangeDetector(view.watchGroup);
|
||||
cd = new ChangeDetector(view.recordRange);
|
||||
}
|
||||
|
||||
it('should consume text node changes', () => {
|
||||
var pv = new ProtoView(createElement('<div class="ng-binding">{{}}</div>'),
|
||||
new ProtoWatchGroup());
|
||||
new ProtoRecordRange());
|
||||
pv.bindElement(null);
|
||||
pv.bindTextNode(0, parser.parseBinding('foo').ast);
|
||||
createView(pv);
|
||||
@ -249,7 +249,7 @@ export function main() {
|
||||
|
||||
it('should consume element binding changes', () => {
|
||||
var pv = new ProtoView(createElement('<div class="ng-binding"></div>'),
|
||||
new ProtoWatchGroup());
|
||||
new ProtoRecordRange());
|
||||
pv.bindElement(null);
|
||||
pv.bindElementProperty('id', parser.parseBinding('foo').ast);
|
||||
createView(pv);
|
||||
@ -261,7 +261,7 @@ export function main() {
|
||||
|
||||
it('should consume directive watch expression change.', () => {
|
||||
var pv = new ProtoView(createElement('<div class="ng-binding"></div>'),
|
||||
new ProtoWatchGroup());
|
||||
new ProtoRecordRange());
|
||||
pv.bindElement(new ProtoElementInjector(null, 0, [SomeDirective]));
|
||||
pv.bindDirectiveProperty( 0, parser.parseBinding('foo').ast, 'prop', closureMap.setter('prop'));
|
||||
createView(pv);
|
||||
@ -277,7 +277,7 @@ export function main() {
|
||||
var el, pv;
|
||||
beforeEach(() => {
|
||||
el = DOM.createElement('div');
|
||||
pv = new ProtoView(createElement('<div>hi</div>'), new ProtoWatchGroup());
|
||||
pv = new ProtoView(createElement('<div>hi</div>'), new ProtoRecordRange());
|
||||
});
|
||||
|
||||
it('should create the root component when instantiated', () => {
|
||||
|
Reference in New Issue
Block a user