refactor(compiler): make `view.disposable` array null if empty
This commit is contained in:
parent
bda1909ede
commit
f6710fefeb
|
@ -573,7 +573,7 @@ function generateCreateMethod(view: CompileView): o.Statement[] {
|
||||||
[
|
[
|
||||||
view.lastRenderNode,
|
view.lastRenderNode,
|
||||||
o.literalArr(view.nodes.map(node => node.renderNode)),
|
o.literalArr(view.nodes.map(node => node.renderNode)),
|
||||||
o.literalArr(view.disposables),
|
view.disposables.length ? o.literalArr(view.disposables) : o.NULL_EXPR,
|
||||||
])
|
])
|
||||||
.toStmt(),
|
.toStmt(),
|
||||||
new o.ReturnStatement(resultExpr)
|
new o.ReturnStatement(resultExpr)
|
||||||
|
|
|
@ -120,8 +120,10 @@ export abstract class AppView<T> {
|
||||||
}
|
}
|
||||||
var hostElement =
|
var hostElement =
|
||||||
this.type === ViewType.COMPONENT ? this.declarationAppElement.nativeElement : null;
|
this.type === ViewType.COMPONENT ? this.declarationAppElement.nativeElement : null;
|
||||||
for (var i = 0; i < this.disposables.length; i++) {
|
if (this.disposables) {
|
||||||
this.disposables[i]();
|
for (var i = 0; i < this.disposables.length; i++) {
|
||||||
|
this.disposables[i]();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.destroyInternal();
|
this.destroyInternal();
|
||||||
this.dirtyParentQueriesInternal();
|
this.dirtyParentQueriesInternal();
|
||||||
|
|
|
@ -117,7 +117,12 @@ export class ViewRef_<C> implements EmbeddedViewRef<C>, ChangeDetectorRef {
|
||||||
this.markForCheck();
|
this.markForCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
onDestroy(callback: Function) { this._view.disposables.push(callback); }
|
onDestroy(callback: Function) {
|
||||||
|
if (!this._view.disposables) {
|
||||||
|
this._view.disposables = [];
|
||||||
|
}
|
||||||
|
this._view.disposables.push(callback);
|
||||||
|
}
|
||||||
|
|
||||||
destroy() { this._view.detachAndDestroy(); }
|
destroy() { this._view.detachAndDestroy(); }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue