refactor(change_detection): renamed BindingPropagationConfig to ChangeDetectorRef
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import {isPresent} from 'angular2/src/facade/lang';
|
||||
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {BindingPropagationConfig} from './binding_propagation_config';
|
||||
import {ChangeDetectorRef} from './change_detector_ref';
|
||||
import {ChangeDetector} from './interfaces';
|
||||
import {CHECK_ALWAYS, CHECK_ONCE, CHECKED, DETACHED, ON_PUSH} from './constants';
|
||||
|
||||
@ -9,13 +9,13 @@ export class AbstractChangeDetector extends ChangeDetector {
|
||||
shadowDomChildren:List;
|
||||
parent:ChangeDetector;
|
||||
mode:string;
|
||||
bindingPropagationConfig:BindingPropagationConfig;
|
||||
changeDetectorRef:ChangeDetectorRef;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.lightDomChildren = [];
|
||||
this.shadowDomChildren = [];
|
||||
this.bindingPropagationConfig = new BindingPropagationConfig(this);
|
||||
this.changeDetectorRef = new ChangeDetectorRef(this);
|
||||
this.mode = null;
|
||||
}
|
||||
|
||||
|
@ -1,29 +0,0 @@
|
||||
import {ChangeDetector} from './interfaces';
|
||||
import {CHECK_ONCE, DETACHED, CHECK_ALWAYS} from './constants';
|
||||
|
||||
/**
|
||||
* @exportedAs angular2/change_detection
|
||||
*/
|
||||
export class BindingPropagationConfig {
|
||||
_cd:ChangeDetector;
|
||||
|
||||
constructor(cd:ChangeDetector) {
|
||||
this._cd = cd;
|
||||
}
|
||||
|
||||
shouldBePropagated() {
|
||||
this._cd.mode = CHECK_ONCE;
|
||||
}
|
||||
|
||||
shouldBePropagatedFromRoot() {
|
||||
this._cd.markPathToRootAsCheckOnce();
|
||||
}
|
||||
|
||||
shouldNotPropagate() {
|
||||
this._cd.mode = DETACHED;
|
||||
}
|
||||
|
||||
shouldAlwaysPropagate() {
|
||||
this._cd.mode = CHECK_ALWAYS;
|
||||
}
|
||||
}
|
@ -362,13 +362,13 @@ export class ChangeDetectorJITGenerator {
|
||||
var change = this.changeNames[r.selfIndex];
|
||||
|
||||
var pipe = this.pipeNames[r.selfIndex];
|
||||
var bpc = r.mode === RECORD_TYPE_BINDING_PIPE ? "this.bindingPropagationConfig" : "null";
|
||||
var cdRef = r.mode === RECORD_TYPE_BINDING_PIPE ? "this.changeDetectorRef" : "null";
|
||||
|
||||
var update = this.genUpdateDirectiveOrElement(r);
|
||||
var addToChanges = this.genAddToChanges(r);
|
||||
var lastInDirective = this.genNotifyOnChanges(r);
|
||||
|
||||
return pipeCheckTemplate(r.selfIndex - 1, context, bpc, pipe, r.name, oldValue, newValue, change,
|
||||
return pipeCheckTemplate(r.selfIndex - 1, context, cdRef, pipe, r.name, oldValue, newValue, change,
|
||||
update, addToChanges, lastInDirective);
|
||||
}
|
||||
|
||||
|
45
modules/angular2/src/change_detection/change_detector_ref.js
vendored
Normal file
45
modules/angular2/src/change_detection/change_detector_ref.js
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
import {ChangeDetector} from './interfaces';
|
||||
import {CHECK_ONCE, DETACHED, CHECK_ALWAYS} from './constants';
|
||||
|
||||
/**
|
||||
* Controls change detection.
|
||||
*
|
||||
* [ChangeDetectorRef] allows requesting checks for detectors that rely on observables. It also allows detaching and
|
||||
* attaching change detector subtrees.
|
||||
*
|
||||
* @exportedAs angular2/change_detection
|
||||
*/
|
||||
export class ChangeDetectorRef {
|
||||
_cd:ChangeDetector;
|
||||
|
||||
constructor(cd:ChangeDetector) {
|
||||
this._cd = cd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to check all ON_PUSH ancestors.
|
||||
*/
|
||||
requestCheck() {
|
||||
this._cd.markPathToRootAsCheckOnce();
|
||||
}
|
||||
|
||||
/**
|
||||
* Detaches the change detector from the change detector tree.
|
||||
*
|
||||
* The detached change detector will not be checked until it is reattached.
|
||||
*/
|
||||
detach() {
|
||||
this._cd.mode = DETACHED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reattach the change detector to the change detector tree.
|
||||
*
|
||||
* This also requests a check of this change detector. This reattached change detector will be checked during the
|
||||
* next change detection run.
|
||||
*/
|
||||
reattach() {
|
||||
this._cd.mode = CHECK_ALWAYS;
|
||||
this.requestCheck();
|
||||
}
|
||||
}
|
@ -245,12 +245,12 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
|
||||
}
|
||||
|
||||
// Currently, only pipes that used in bindings in the template get
|
||||
// the bindingPropagationConfig of the encompassing component.
|
||||
// the changeDetectorRef of the encompassing component.
|
||||
//
|
||||
// In the future, pipes declared in the bind configuration should
|
||||
// be able to access the bindingPropagationConfig of that component.
|
||||
var bpc = proto.mode === RECORD_TYPE_BINDING_PIPE ? this.bindingPropagationConfig : null;
|
||||
var pipe = this.pipeRegistry.get(proto.name, context, bpc);
|
||||
// be able to access the changeDetectorRef of that component.
|
||||
var cdr = proto.mode === RECORD_TYPE_BINDING_PIPE ? this.changeDetectorRef : null;
|
||||
var pipe = this.pipeRegistry.get(proto.name, context, cdr);
|
||||
this._writePipe(proto, pipe);
|
||||
return pipe;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ export class IterableChangesFactory {
|
||||
return IterableChanges.supportsObj(obj);
|
||||
}
|
||||
|
||||
create(bpc):Pipe {
|
||||
create(cdRef):Pipe {
|
||||
return new IterableChanges();
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ export class KeyValueChangesFactory {
|
||||
return KeyValueChanges.supportsObj(obj);
|
||||
}
|
||||
|
||||
create(bpc):Pipe {
|
||||
create(cdRef):Pipe {
|
||||
return new KeyValueChanges();
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ export class NullPipeFactory {
|
||||
return NullPipe.supportsObj(obj);
|
||||
}
|
||||
|
||||
create(bpc):Pipe {
|
||||
create(cdRef):Pipe {
|
||||
return new NullPipe();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {isBlank, isPresent, BaseException, CONST} from 'angular2/src/facade/lang';
|
||||
import {Pipe} from './pipe';
|
||||
import {BindingPropagationConfig} from '../binding_propagation_config';
|
||||
import {ChangeDetectorRef} from '../change_detector_ref';
|
||||
|
||||
export class PipeRegistry {
|
||||
config;
|
||||
@ -10,7 +10,7 @@ export class PipeRegistry {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
get(type:string, obj, bpc:BindingPropagationConfig):Pipe {
|
||||
get(type:string, obj, cdRef:ChangeDetectorRef):Pipe {
|
||||
var listOfConfigs = this.config[type];
|
||||
if (isBlank(listOfConfigs)) {
|
||||
throw new BaseException(`Cannot find a pipe for type '${type}' object '${obj}'`);
|
||||
@ -23,6 +23,6 @@ export class PipeRegistry {
|
||||
throw new BaseException(`Cannot find a pipe for type '${type}' object '${obj}'`);
|
||||
}
|
||||
|
||||
return matchingConfig.create(bpc);
|
||||
return matchingConfig.create(cdRef);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user