diff --git a/packages/app/src/Application.js b/packages/app/src/Application.js index e7fe836..7856bea 100644 --- a/packages/app/src/Application.js +++ b/packages/app/src/Application.js @@ -238,8 +238,16 @@ /** * Destroy and don't use after this. * @param {Boolean} [removeView=false] Automatically remove canvas from DOM. + * @param {object|boolean} [stageOptions] - Options parameter. A boolean will act as if all options + * have been set to that value + * @param {boolean} [stageOptions.children=false] - if set to true, all the children will have their destroy + * method called as well. 'stageOptions' will be passed on to those calls. + * @param {boolean} [stageOptions.texture=false] - Only used for child Sprites if stageOptions.children is set + * to true. Should it destroy the texture of the child sprite + * @param {boolean} [stageOptions.baseTexture=false] - Only used for child Sprites if stageOptions.children is set + * to true. Should it destroy the base texture of the child sprite */ - destroy(removeView) + destroy(removeView, stageOptions) { this.resizeTo = null; @@ -251,7 +259,7 @@ oldTicker.destroy(); } - this.stage.destroy(); + this.stage.destroy(stageOptions); this.stage = null; this.renderer.destroy(removeView); diff --git a/packages/app/src/Application.js b/packages/app/src/Application.js index e7fe836..7856bea 100644 --- a/packages/app/src/Application.js +++ b/packages/app/src/Application.js @@ -238,8 +238,16 @@ /** * Destroy and don't use after this. * @param {Boolean} [removeView=false] Automatically remove canvas from DOM. + * @param {object|boolean} [stageOptions] - Options parameter. A boolean will act as if all options + * have been set to that value + * @param {boolean} [stageOptions.children=false] - if set to true, all the children will have their destroy + * method called as well. 'stageOptions' will be passed on to those calls. + * @param {boolean} [stageOptions.texture=false] - Only used for child Sprites if stageOptions.children is set + * to true. Should it destroy the texture of the child sprite + * @param {boolean} [stageOptions.baseTexture=false] - Only used for child Sprites if stageOptions.children is set + * to true. Should it destroy the base texture of the child sprite */ - destroy(removeView) + destroy(removeView, stageOptions) { this.resizeTo = null; @@ -251,7 +259,7 @@ oldTicker.destroy(); } - this.stage.destroy(); + this.stage.destroy(stageOptions); this.stage = null; this.renderer.destroy(removeView); diff --git a/packages/app/test/index.js b/packages/app/test/index.js index 3fe17a8..7b2aa40 100644 --- a/packages/app/test/index.js +++ b/packages/app/test/index.js @@ -1,6 +1,6 @@ const { Application } = require('../'); const { autoDetectRenderer } = require('@pixi/canvas-renderer'); -const { Container } = require('@pixi/display'); +const { Container, DisplayObject } = require('@pixi/display'); const { Ticker, UPDATE_PRIORITY } = require('@pixi/ticker'); const { skipHello } = require('@pixi/utils'); @@ -177,4 +177,44 @@ app.destroy(); }); }); + + describe('destroy', function () + { + it('should not destroy children by default', function (done) + { + const app = new Application(); + const stage = app.stage; + const child = new DisplayObject(); + + stage.addChild(child); + + app.ticker.addOnce(() => + { + app.destroy(); + expect(stage.children.length).to.be.equals(0); + expect(child.transform).to.not.be.null; + + done(); + }); + }); + + it('should allow children destroy', function (done) + { + const app = new Application(); + const stage = app.stage; + const child = new DisplayObject(); + + stage.addChild(child); + + app.ticker.addOnce(() => + { + app.destroy(false, true); + expect(stage.children.length).to.be.equals(0); + expect(stage.transform).to.be.null; + expect(child.transform).to.be.null; + + done(); + }); + }); + }); }); diff --git a/packages/app/src/Application.js b/packages/app/src/Application.js index e7fe836..7856bea 100644 --- a/packages/app/src/Application.js +++ b/packages/app/src/Application.js @@ -238,8 +238,16 @@ /** * Destroy and don't use after this. * @param {Boolean} [removeView=false] Automatically remove canvas from DOM. + * @param {object|boolean} [stageOptions] - Options parameter. A boolean will act as if all options + * have been set to that value + * @param {boolean} [stageOptions.children=false] - if set to true, all the children will have their destroy + * method called as well. 'stageOptions' will be passed on to those calls. + * @param {boolean} [stageOptions.texture=false] - Only used for child Sprites if stageOptions.children is set + * to true. Should it destroy the texture of the child sprite + * @param {boolean} [stageOptions.baseTexture=false] - Only used for child Sprites if stageOptions.children is set + * to true. Should it destroy the base texture of the child sprite */ - destroy(removeView) + destroy(removeView, stageOptions) { this.resizeTo = null; @@ -251,7 +259,7 @@ oldTicker.destroy(); } - this.stage.destroy(); + this.stage.destroy(stageOptions); this.stage = null; this.renderer.destroy(removeView); diff --git a/packages/app/test/index.js b/packages/app/test/index.js index 3fe17a8..7b2aa40 100644 --- a/packages/app/test/index.js +++ b/packages/app/test/index.js @@ -1,6 +1,6 @@ const { Application } = require('../'); const { autoDetectRenderer } = require('@pixi/canvas-renderer'); -const { Container } = require('@pixi/display'); +const { Container, DisplayObject } = require('@pixi/display'); const { Ticker, UPDATE_PRIORITY } = require('@pixi/ticker'); const { skipHello } = require('@pixi/utils'); @@ -177,4 +177,44 @@ app.destroy(); }); }); + + describe('destroy', function () + { + it('should not destroy children by default', function (done) + { + const app = new Application(); + const stage = app.stage; + const child = new DisplayObject(); + + stage.addChild(child); + + app.ticker.addOnce(() => + { + app.destroy(); + expect(stage.children.length).to.be.equals(0); + expect(child.transform).to.not.be.null; + + done(); + }); + }); + + it('should allow children destroy', function (done) + { + const app = new Application(); + const stage = app.stage; + const child = new DisplayObject(); + + stage.addChild(child); + + app.ticker.addOnce(() => + { + app.destroy(false, true); + expect(stage.children.length).to.be.equals(0); + expect(stage.transform).to.be.null; + expect(child.transform).to.be.null; + + done(); + }); + }); + }); }); diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js index ab28882..5fa0f4f 100644 --- a/packages/mixin-app-loader/src/index.js +++ b/packages/mixin-app-loader/src/index.js @@ -27,12 +27,12 @@ // Override the destroy function // making sure to destroy the current Loader Application.prototype._parentDestroy = Application.prototype.destroy; -Application.prototype.destroy = function destroy(removeView) +Application.prototype.destroy = function destroy(removeView, stageOptions) { if (this._loader) { this._loader.destroy(); this._loader = null; } - this._parentDestroy(removeView); + this._parentDestroy(removeView, stageOptions); };