fix: clear the resolvedPage when entry is being cleared, change the passed View to be a weak reference (#7327)

* fix: clear the `resolvedPage` when entry is being cleared
fix: change the passed `View` to be a weak reference

* chore: add trace logs when weak ref has been cleared but is continuing to be used
chore: add condition to check if weak ref has not been cleared when it is being used

* chore: refactor the way the `resolvedPage` is cleared

* chore: add backward compatible property to avoid breaking changes

* chore: refactor condition to check if WeakRef is not cleared
chore: add tracelogs

* chore: refactor condition to check if WeakRef is not cleared
chore: add tracelogs

* refactor: weakRef usages

* chore: change the way WeakRef type check is done
This commit is contained in:
Vladimir Amiorkov
2019-06-21 11:48:49 +03:00
committed by Dimitar Topuzov
parent 81e1f54955
commit dfe76213dd
7 changed files with 239 additions and 51 deletions

View File

@@ -4,6 +4,12 @@ import { ViewBase } from "../view-base";
// Types.
import { WrappedValue, PropertyChangeData } from "../../../data/observable";
import {
write as traceWrite,
categories as traceCategories,
messageType as traceMessageType,
} from "../../../trace";
import { Style } from "../../styling/style";
import { profile } from "../../../profiling";
@@ -125,7 +131,7 @@ export class Property<T extends ViewBase, U> implements TypedPropertyDescriptor<
if (affectsLayout) {
this.requestLayout();
}
if (reset) {
delete this[key];
if (valueChanged) {
@@ -466,6 +472,13 @@ export class CssProperty<T extends Style, U> implements definitions.CssProperty<
const property = this;
function setLocalValue(this: T, newValue: U | string): void {
const view = this.viewRef.get();
if (!view) {
traceWrite(`${newValue} not set to view because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn);
return;
}
const reset = newValue === unsetValue || newValue === "";
let value: U;
if (reset) {
@@ -482,7 +495,6 @@ export class CssProperty<T extends Style, U> implements definitions.CssProperty<
const changed: boolean = equalityComparer ? !equalityComparer(oldValue, value) : oldValue !== value;
if (changed) {
const view = this.view;
if (reset) {
delete this[key];
if (valueChanged) {
@@ -534,6 +546,13 @@ export class CssProperty<T extends Style, U> implements definitions.CssProperty<
}
function setCssValue(this: T, newValue: U | string): void {
const view = this.viewRef.get();
if (!view) {
traceWrite(`${newValue} not set to view because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn);
return;
}
const currentValueSource: number = this[sourceKey] || ValueSource.Default;
// We have localValueSource - NOOP.
@@ -557,7 +576,6 @@ export class CssProperty<T extends Style, U> implements definitions.CssProperty<
const changed: boolean = equalityComparer ? !equalityComparer(oldValue, value) : oldValue !== value;
if (changed) {
const view = this.view;
if (reset) {
delete this[key];
if (valueChanged) {
@@ -718,12 +736,18 @@ export class CssAnimationProperty<T extends Style, U> implements definitions.Css
enumerable, configurable,
get: getsComputed ? function (this: T) { return this[computedValue]; } : function (this: T) { return this[symbol]; },
set(this: T, boxedValue: U | string) {
const view = this.viewRef.get();
if (!view) {
traceWrite(`${boxedValue} not set to view because ".viewRef" is cleared`, traceCategories.Animation, traceMessageType.warn);
return;
}
const oldValue = this[computedValue];
const oldSource = this[computedSource];
const wasSet = oldSource !== ValueSource.Default;
const reset = boxedValue === unsetValue || boxedValue === "";
if (reset) {
this[symbol] = unsetValue;
if (this[computedSource] === propertySource) {
@@ -760,7 +784,6 @@ export class CssAnimationProperty<T extends Style, U> implements definitions.Css
valueChanged(this, oldValue, value);
}
const view = this.view;
if (view[setNative] && (computedValueChanged || isSet !== wasSet)) {
if (view._suspendNativeUpdatesCount) {
if (view._suspendedUpdates) {
@@ -816,10 +839,16 @@ export class CssAnimationProperty<T extends Style, U> implements definitions.Css
}
public _initDefaultNativeValue(target: T): void {
const view = target.viewRef.get();
if (!view) {
traceWrite(`_initDefaultNativeValue not executed to view because ".viewRef" is cleared`, traceCategories.Animation, traceMessageType.warn);
return;
}
const defaultValueKey = this.defaultValueKey;
if (!(defaultValueKey in target)) {
const view = target.view;
const getDefault = this.getDefault;
target[defaultValueKey] = view[getDefault] ? view[getDefault]() : this.defaultValue;
}
@@ -862,6 +891,13 @@ export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U>
const property = this;
const setFunc = (valueSource: ValueSource) => function (this: T, boxedValue: any): void {
const view = this.viewRef.get();
if (!view) {
traceWrite(`${boxedValue} not set to view's property because ".viewRef" is cleared`, traceCategories.Style, traceMessageType.warn);
return;
}
const reset = boxedValue === unsetValue || boxedValue === "";
const currentValueSource: number = this[sourceKey] || ValueSource.Default;
if (reset) {
@@ -876,7 +912,6 @@ export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U>
}
const oldValue: U = key in this ? this[key] : defaultValue;
const view = this.view;
let value: U;
let unsetNativeValue = false;
if (reset) {
@@ -907,7 +942,6 @@ export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U>
const changed: boolean = equalityComparer ? !equalityComparer(oldValue, value) : oldValue !== value;
if (changed) {
const view = this.view;
if (valueChanged) {
valueChanged(this, oldValue, value);
}
@@ -997,7 +1031,14 @@ export class ShorthandProperty<T extends Style, P> implements definitions.Shorth
const converter = options.converter;
function setLocalValue(this: T, value: string | P): void {
this.view._batchUpdate(() => {
const view = this.viewRef.get();
if (!view) {
traceWrite(`setLocalValue not executed to view because ".viewRef" is cleared`, traceCategories.Animation, traceMessageType.warn);
return;
}
view._batchUpdate(() => {
for (let [p, v] of converter(value)) {
this[p.name] = v;
}
@@ -1005,7 +1046,14 @@ export class ShorthandProperty<T extends Style, P> implements definitions.Shorth
}
function setCssValue(this: T, value: string): void {
this.view._batchUpdate(() => {
const view = this.viewRef.get();
if (!view) {
traceWrite(`setCssValue not executed to view because ".viewRef" is cleared`, traceCategories.Animation, traceMessageType.warn);
return;
}
view._batchUpdate(() => {
for (let [p, v] of converter(value)) {
this[p.cssName] = v;
}

View File

@@ -192,7 +192,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
public _domId: number;
public _context: any;
public _isAddedToNativeVisualTree: boolean;
public _cssState: ssm.CssState = new ssm.CssState(this);
public _cssState: ssm.CssState = new ssm.CssState(new WeakRef(this));
public _styleScope: ssm.StyleScope;
public _suspendedUpdates: { [propertyName: string]: Property<ViewBase, any> | CssProperty<Style, any> | CssAnimationProperty<Style, any> };
public _suspendNativeUpdatesCount: SuspendType;
@@ -249,7 +249,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
constructor() {
super();
this._domId = viewIdCounter++;
this._style = new Style(this);
this._style = new Style(new WeakRef(this));
}
// Used in Angular.