From d705f24e4cbfd32ec7bb28ee6f854532e2071877 Mon Sep 17 00:00:00 2001 From: Damien Pobel Date: Thu, 8 Sep 2016 16:01:00 +0200 Subject: [PATCH] EZP-25137: Added an option to destroy a side view when it's getting unused --- Resources/public/js/apps/ez-platformuiapp.js | 9 ++++++ .../js/apps/assets/ez-platformuiapp-tests.js | 29 ++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Resources/public/js/apps/ez-platformuiapp.js b/Resources/public/js/apps/ez-platformuiapp.js index 53766e319..9d4595f20 100644 --- a/Resources/public/js/apps/ez-platformuiapp.js +++ b/Resources/public/js/apps/ez-platformuiapp.js @@ -35,6 +35,11 @@ YUI.add('ez-platformuiapp', function (Y) { * rendered view * * `hideClass`: a class to add on the application container to hide * the rendered side view when it's not needed. + * * `service`: a reference to the constructor of a view service + * * [`destroyUnusedView=false`]: a boolean flag. If true, the view + * will be destroyed when the view is not used anymore. As a result, + * when this flag is positionned, the view is recreated and + * rerendered everytime it is used. * * The lifecycle of the side views is handled by the `handleSideViews` * method based on the meta information available in the route. @@ -651,6 +656,10 @@ YUI.add('ez-platformuiapp', function (Y) { view = viewInfo.instance; view.set('active', false); viewInfo.serviceInstance.removeTarget(this); + if ( viewInfo.destroyUnusedView ) { + view.destroy({remove: true}); + delete viewInfo.instance; + } } }, diff --git a/Tests/js/apps/assets/ez-platformuiapp-tests.js b/Tests/js/apps/assets/ez-platformuiapp-tests.js index fcf9607c0..1911b0837 100644 --- a/Tests/js/apps/assets/ez-platformuiapp-tests.js +++ b/Tests/js/apps/assets/ez-platformuiapp-tests.js @@ -1167,7 +1167,34 @@ YUI.add('ez-platformuiapp-tests', function (Y) { Y.Assert.isTrue(nextCalled, "The next callback should have been called"); }, - "Should destroy the sideViews": function () { + "Should destroy the side view when unused": function () { + var req = { + route: { + sideViews: { + sideView1: true, + } + } + }, + destroyed = false; + + this.app.sideViews.sideView1.destroyUnusedView = true; + this.app.sideViews.sideView1.type = Y.Base.create('sideView1', Y.View, [], { + destructor: function () { + destroyed = true; + }, + }); + + this.app.handleSideViews(req, {}, function () {}); + this.app.handleSideViews({route: {sideViews: {sideView1: false}}}, {}, function () {}); + + Assert.isTrue(destroyed, "The side view should not be destroyed"); + Assert.isUndefined( + this.app.sideViews.sideView1.instance, + "The view object should have been deleted" + ); + }, + + "Should destroy the sideViews on logout": function () { var sideViewInstanceMock = new Y.Mock(), sideViewServiceMock = new Y.Mock();