Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
EZP-25137: Added an option to destroy a side view when it's getting u…
Browse files Browse the repository at this point in the history
…nused
  • Loading branch information
dpobel committed Sep 8, 2016
1 parent 53f9a1c commit d705f24
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Resources/public/js/apps/ez-platformuiapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
}
},

Expand Down
29 changes: 28 additions & 1 deletion Tests/js/apps/assets/ez-platformuiapp-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit d705f24

Please sign in to comment.