refactor(change_detection): removed NO_CHANGED and replaced it with WrappedValue
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import {Observable, ObservableWrapper} from 'angular2/src/facade/async';
|
||||
import {isBlank, isPresent} from 'angular2/src/facade/lang';
|
||||
import {Pipe, NO_CHANGE} from './pipe';
|
||||
import {Pipe, WrappedValue} from './pipe';
|
||||
import {ChangeDetectorRef} from '../change_detector_ref';
|
||||
|
||||
/**
|
||||
@ -67,10 +67,10 @@ export class AsyncPipe extends Pipe {
|
||||
}
|
||||
|
||||
if (this._latestValue === this._latestReturnedValue) {
|
||||
return NO_CHANGE;
|
||||
return this._latestReturnedValue;
|
||||
} else {
|
||||
this._latestReturnedValue = this._latestValue;
|
||||
return this._latestValue;
|
||||
return WrappedValue.wrap(this._latestValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ import {
|
||||
looseIdentical,
|
||||
} from 'angular2/src/facade/lang';
|
||||
|
||||
import {NO_CHANGE, Pipe} from './pipe';
|
||||
import {WrappedValue, Pipe} from './pipe';
|
||||
|
||||
export class IterableChangesFactory {
|
||||
supports(obj):boolean {
|
||||
@ -117,9 +117,9 @@ export class IterableChanges extends Pipe {
|
||||
|
||||
transform(collection){
|
||||
if (this.check(collection)) {
|
||||
return this;
|
||||
return WrappedValue.wrap(this);
|
||||
} else {
|
||||
return NO_CHANGE;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
||||
import {stringify, looseIdentical, isJsObject} from 'angular2/src/facade/lang';
|
||||
|
||||
import {NO_CHANGE, Pipe} from './pipe';
|
||||
import {WrappedValue, Pipe} from './pipe';
|
||||
|
||||
/**
|
||||
* @exportedAs angular2/pipes
|
||||
@ -54,9 +54,9 @@ export class KeyValueChanges extends Pipe {
|
||||
|
||||
transform(map){
|
||||
if (this.check(map)) {
|
||||
return this;
|
||||
return WrappedValue.wrap(this);
|
||||
} else {
|
||||
return NO_CHANGE;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {isBlank} from 'angular2/src/facade/lang';
|
||||
import {Pipe, NO_CHANGE} from './pipe';
|
||||
import {Pipe, WrappedValue} from './pipe';
|
||||
|
||||
/**
|
||||
* @exportedAs angular2/pipes
|
||||
@ -35,9 +35,9 @@ export class NullPipe extends Pipe {
|
||||
transform(value) {
|
||||
if (! this.called) {
|
||||
this.called = true;
|
||||
return null;
|
||||
return WrappedValue.wrap(null);
|
||||
} else {
|
||||
return NO_CHANGE;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,33 @@
|
||||
/**
|
||||
* Indicates that the result of a {@link Pipe} transformation has not changed since the last time the pipe was called.
|
||||
* Indicates that the result of a {@link Pipe} transformation has changed even though the reference has not changed.
|
||||
*
|
||||
* Suppose we have a pipe that computes changes in an array by performing a simple diff operation. If
|
||||
* we call this pipe with the same array twice, it will return `NO_CHANGE` the second time.
|
||||
* The wrapped value will be unwrapped by change detection, and the unwrapped value will be stored.
|
||||
*
|
||||
* @exportedAs angular2/pipes
|
||||
*/
|
||||
export class WrappedValue {
|
||||
wrapped:any;
|
||||
|
||||
export var NO_CHANGE = new Object();
|
||||
constructor(wrapped:any) {
|
||||
this.wrapped = wrapped;
|
||||
}
|
||||
|
||||
static wrap(value:any):WrappedValue {
|
||||
var w = _wrappedValues[_wrappedIndex++ % 5];
|
||||
w.wrapped = value;
|
||||
return w;
|
||||
}
|
||||
}
|
||||
|
||||
var _wrappedValues = [
|
||||
new WrappedValue(null),
|
||||
new WrappedValue(null),
|
||||
new WrappedValue(null),
|
||||
new WrappedValue(null),
|
||||
new WrappedValue(null)
|
||||
];
|
||||
|
||||
var _wrappedIndex = 0;
|
||||
|
||||
/**
|
||||
* An interface for extending the list of pipes known to Angular.
|
||||
|
Reference in New Issue
Block a user