From effeb870d79342b2b49d7389e8a0be91a39845c6 Mon Sep 17 00:00:00 2001 From: Maksim Kozhukh Date: Tue, 26 Jun 2018 11:12:09 +0300 Subject: [PATCH 1/2] [update] order of destroy and init events Update changes the order of events. Now, when view A replaces view B, events will go like next - B.destroy() - A.init() To do so, we remove direct destructor() calls from the rendering callback and place the same call just after rendering new UI ( after this point we don't need old view anymore ) --- dist/JetApp.js | 4 ---- dist/JetView.js | 9 +++++---- sources/JetApp.ts | 5 ----- sources/JetView.ts | 11 ++++++----- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/dist/JetApp.js b/dist/JetApp.js index 686a82b..c982347 100644 --- a/dist/JetApp.js +++ b/dist/JetApp.js @@ -284,10 +284,6 @@ var JetApp = (function (_super) { _this._view = view; // render url state for the root return view.render(_this._container, parsed, _this._parent).then(function (root) { - // destroy and detack old view - if (oldview && oldview !== _this._view) { - oldview.destructor(); - } if (_this._view.getRoot().getParentView()) { _this._container = root; } diff --git a/dist/JetView.js b/dist/JetView.js index d8fb3e4..991cdd1 100644 --- a/dist/JetView.js +++ b/dist/JetView.js @@ -186,7 +186,12 @@ var JetView = (function (_super) { result.ui.id = prev.config.id; } } + var oldScope = this._container.$scope; this._root = this.app.webix.ui(result.ui, this._container); + // check, if some other view need to be destroyed + if (oldScope && oldScope !== this && oldScope.getRoot && oldScope.getRoot().$destructed) { + oldScope.destructor(); + } if (this._root.getParentView()) { this._container = this._root; } @@ -255,10 +260,6 @@ var JetView = (function (_super) { JetView.prototype._renderSubView = function (sub, view, suburl) { var cell = this.app.webix.$$(sub.id); return view.render(cell, suburl, this).then(function (ui) { - // destroy old view - if (sub.view && sub.view !== view) { - sub.view.destructor(); - } // save info about a new view sub.view = view; sub.id = ui.config.id; diff --git a/sources/JetApp.ts b/sources/JetApp.ts index 74e4f9d..7094669 100644 --- a/sources/JetApp.ts +++ b/sources/JetApp.ts @@ -316,11 +316,6 @@ export class JetApp extends JetBase implements IJetApp { // render url state for the root return view.render(this._container, parsed, this._parent).then(root => { - - // destroy and detack old view - if (oldview && oldview !== this._view) { - oldview.destructor(); - } if (this._view.getRoot().getParentView()){ this._container = root; } diff --git a/sources/JetView.ts b/sources/JetView.ts index b7417e8..a3d259d 100644 --- a/sources/JetView.ts +++ b/sources/JetView.ts @@ -207,7 +207,13 @@ export class JetView extends JetBase{ } } + const oldScope = (this._container as any).$scope; this._root = this.app.webix.ui(result.ui, this._container); + // check, if some other view need to be destroyed + if (oldScope && oldScope !== this && oldScope.getRoot && oldScope.getRoot().$destructed){ + oldScope.destructor(); + } + if (this._root.getParentView()){ this._container = this._root; } @@ -286,11 +292,6 @@ export class JetView extends JetBase{ suburl:IJetURL):Promise{ const cell = this.app.webix.$$(sub.id); return view.render(cell, suburl, this).then(ui => { - // destroy old view - if (sub.view && sub.view !== view){ - sub.view.destructor(); - } - // save info about a new view sub.view = view; sub.id = ui.config.id as string; From 7f5b37411d640bc69472d5fa955e556907fc6b3a Mon Sep 17 00:00:00 2001 From: Maksim Kozhukh Date: Thu, 27 Sep 2018 15:27:59 +0300 Subject: [PATCH 2/2] [fix] destroy sub-app when root view of sub app is destroyed --- dist/JetView.js | 7 ++++++- sources/JetView.ts | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dist/JetView.js b/dist/JetView.js index 991cdd1..3185588 100644 --- a/dist/JetView.js +++ b/dist/JetView.js @@ -190,7 +190,12 @@ var JetView = (function (_super) { this._root = this.app.webix.ui(result.ui, this._container); // check, if some other view need to be destroyed if (oldScope && oldScope !== this && oldScope.getRoot && oldScope.getRoot().$destructed) { - oldScope.destructor(); + if (oldScope.app !== this.app && oldScope.app.getRoot().$destructed) { + oldScope.app.destructor(); + } + else { + oldScope.destructor(); + } } if (this._root.getParentView()) { this._container = this._root; diff --git a/sources/JetView.ts b/sources/JetView.ts index a3d259d..d268ddb 100644 --- a/sources/JetView.ts +++ b/sources/JetView.ts @@ -211,7 +211,11 @@ export class JetView extends JetBase{ this._root = this.app.webix.ui(result.ui, this._container); // check, if some other view need to be destroyed if (oldScope && oldScope !== this && oldScope.getRoot && oldScope.getRoot().$destructed){ - oldScope.destructor(); + if (oldScope.app !== this.app && oldScope.app.getRoot().$destructed){ + oldScope.app.destructor(); + } else { + oldScope.destructor(); + } } if (this._root.getParentView()){