refactor(core): refactor WrappedValue (#20997)
- Improve `WrappedValue` by adding `unwrap` symetrical to `wrap`. - remove dead code - `ValueUnwrapper` The property `wrapped` is an implementation details and should never be accessed directly - use `unwrap(wrappedValue)`. Will change to protected in Angular 7. PR Close #20997
This commit is contained in:

committed by
Alex Eagle

parent
54bf179888
commit
3bcc0e6f76
@ -437,10 +437,7 @@ function updateProp(
|
||||
providerData.instance[propName] = value;
|
||||
if (def.flags & NodeFlags.OnChanges) {
|
||||
changes = changes || {};
|
||||
let oldValue = view.oldValues[def.bindingIndex + bindingIdx];
|
||||
if (oldValue instanceof WrappedValue) {
|
||||
oldValue = oldValue.wrapped;
|
||||
}
|
||||
const oldValue = WrappedValue.unwrap(view.oldValues[def.bindingIndex + bindingIdx]);
|
||||
const binding = def.bindings[bindingIdx];
|
||||
changes[binding.nonMinifiedName !] =
|
||||
new SimpleChange(oldValue, value, (view.state & ViewState.FirstCheck) !== 0);
|
||||
|
@ -28,13 +28,10 @@ export function tokenKey(token: any): string {
|
||||
}
|
||||
|
||||
export function unwrapValue(view: ViewData, nodeIdx: number, bindingIdx: number, value: any): any {
|
||||
if (value instanceof WrappedValue) {
|
||||
value = value.wrapped;
|
||||
let globalBindingIdx = view.def.nodes[nodeIdx].bindingIndex + bindingIdx;
|
||||
let oldValue = view.oldValues[globalBindingIdx];
|
||||
if (oldValue instanceof WrappedValue) {
|
||||
oldValue = oldValue.wrapped;
|
||||
}
|
||||
if (WrappedValue.isWrapped(value)) {
|
||||
value = WrappedValue.unwrap(value);
|
||||
const globalBindingIdx = view.def.nodes[nodeIdx].bindingIndex + bindingIdx;
|
||||
const oldValue = WrappedValue.unwrap(view.oldValues[globalBindingIdx]);
|
||||
view.oldValues[globalBindingIdx] = new WrappedValue(oldValue);
|
||||
}
|
||||
return value;
|
||||
|
Reference in New Issue
Block a user