diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index d1d3c60..aa2db53 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -43,9 +43,6 @@ Application.registerPlugin(TickerPlugin); Application.registerPlugin(AppLoaderPlugin); -// Apply deplayed mixins -utils.mixins.performMixins(); - /** * String of the current PIXI version. * diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index d1d3c60..aa2db53 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -43,9 +43,6 @@ Application.registerPlugin(TickerPlugin); Application.registerPlugin(AppLoaderPlugin); -// Apply deplayed mixins -utils.mixins.performMixins(); - /** * String of the current PIXI version. * diff --git a/bundles/pixi.js/src/useDeprecated.js b/bundles/pixi.js/src/useDeprecated.js index 8a5077e..6aafc18 100644 --- a/bundles/pixi.js/src/useDeprecated.js +++ b/bundles/pixi.js/src/useDeprecated.js @@ -928,4 +928,38 @@ this.autoDensity = value; }, }); + + /** + * @namespace PIXI.utils.mixins + * @deprecated since 5.0.0 + */ + PIXI.utils.mixins = { + /** + * @memberof PIXI.utils.mixins + * @function mixin + * @deprecated since 5.0.0 + */ + mixin() + { + deprecation(v5, 'PIXI.utils.mixins.mixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function delayMixin + * @deprecated since 5.0.0 + */ + delayMixin() + { + deprecation(v5, 'PIXI.utils.mixins.delayMixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function performMixins + * @deprecated since 5.0.0 + */ + performMixins() + { + deprecation(v5, 'PIXI.utils.mixins.performMixins no longer available'); + }, + }; } diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index d1d3c60..aa2db53 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -43,9 +43,6 @@ Application.registerPlugin(TickerPlugin); Application.registerPlugin(AppLoaderPlugin); -// Apply deplayed mixins -utils.mixins.performMixins(); - /** * String of the current PIXI version. * diff --git a/bundles/pixi.js/src/useDeprecated.js b/bundles/pixi.js/src/useDeprecated.js index 8a5077e..6aafc18 100644 --- a/bundles/pixi.js/src/useDeprecated.js +++ b/bundles/pixi.js/src/useDeprecated.js @@ -928,4 +928,38 @@ this.autoDensity = value; }, }); + + /** + * @namespace PIXI.utils.mixins + * @deprecated since 5.0.0 + */ + PIXI.utils.mixins = { + /** + * @memberof PIXI.utils.mixins + * @function mixin + * @deprecated since 5.0.0 + */ + mixin() + { + deprecation(v5, 'PIXI.utils.mixins.mixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function delayMixin + * @deprecated since 5.0.0 + */ + delayMixin() + { + deprecation(v5, 'PIXI.utils.mixins.delayMixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function performMixins + * @deprecated since 5.0.0 + */ + performMixins() + { + deprecation(v5, 'PIXI.utils.mixins.performMixins no longer available'); + }, + }; } diff --git a/packages/accessibility/src/AccessibilityManager.js b/packages/accessibility/src/AccessibilityManager.js index 8fea8ba..5908bfe 100644 --- a/packages/accessibility/src/AccessibilityManager.js +++ b/packages/accessibility/src/AccessibilityManager.js @@ -1,13 +1,10 @@ import Device from 'ismobilejs'; import accessibleTarget from './accessibleTarget'; -import { removeItems, mixins } from '@pixi/utils'; +import { removeItems } from '@pixi/utils'; import { DisplayObject } from '@pixi/display'; // add some extra variables to the container.. -mixins.delayMixin( - DisplayObject.prototype, - accessibleTarget -); +DisplayObject.mixin(accessibleTarget); const KEY_CODE_TAB = 9; diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index d1d3c60..aa2db53 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -43,9 +43,6 @@ Application.registerPlugin(TickerPlugin); Application.registerPlugin(AppLoaderPlugin); -// Apply deplayed mixins -utils.mixins.performMixins(); - /** * String of the current PIXI version. * diff --git a/bundles/pixi.js/src/useDeprecated.js b/bundles/pixi.js/src/useDeprecated.js index 8a5077e..6aafc18 100644 --- a/bundles/pixi.js/src/useDeprecated.js +++ b/bundles/pixi.js/src/useDeprecated.js @@ -928,4 +928,38 @@ this.autoDensity = value; }, }); + + /** + * @namespace PIXI.utils.mixins + * @deprecated since 5.0.0 + */ + PIXI.utils.mixins = { + /** + * @memberof PIXI.utils.mixins + * @function mixin + * @deprecated since 5.0.0 + */ + mixin() + { + deprecation(v5, 'PIXI.utils.mixins.mixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function delayMixin + * @deprecated since 5.0.0 + */ + delayMixin() + { + deprecation(v5, 'PIXI.utils.mixins.delayMixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function performMixins + * @deprecated since 5.0.0 + */ + performMixins() + { + deprecation(v5, 'PIXI.utils.mixins.performMixins no longer available'); + }, + }; } diff --git a/packages/accessibility/src/AccessibilityManager.js b/packages/accessibility/src/AccessibilityManager.js index 8fea8ba..5908bfe 100644 --- a/packages/accessibility/src/AccessibilityManager.js +++ b/packages/accessibility/src/AccessibilityManager.js @@ -1,13 +1,10 @@ import Device from 'ismobilejs'; import accessibleTarget from './accessibleTarget'; -import { removeItems, mixins } from '@pixi/utils'; +import { removeItems } from '@pixi/utils'; import { DisplayObject } from '@pixi/display'; // add some extra variables to the container.. -mixins.delayMixin( - DisplayObject.prototype, - accessibleTarget -); +DisplayObject.mixin(accessibleTarget); const KEY_CODE_TAB = 9; diff --git a/packages/accessibility/test/accessibleTarget.js b/packages/accessibility/test/accessibleTarget.js index 83782a1..3a54be6 100644 --- a/packages/accessibility/test/accessibleTarget.js +++ b/packages/accessibility/test/accessibleTarget.js @@ -1,21 +1,11 @@ -const { accessibleTarget } = require('../'); const { DisplayObject } = require('@pixi/display'); -const { mixins } = require('@pixi/utils'); + +require('../'); describe('PIXI.accessibility.accessibleTarget', function () { it('should have target public properties', function () { - expect(accessibleTarget.accessible).to.be.a.boolean; - expect(accessibleTarget.accessible).to.be.false; - expect(accessibleTarget.accessibleTitle).to.be.null; - expect(accessibleTarget.accessibleHint).to.be.null; - expect(accessibleTarget.tabIndex).to.equal(0); - }); - - it('should add properties after mixin', function () - { - mixins.performMixins(); const obj = new DisplayObject(); expect(obj.accessible).to.be.a.boolean; diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index d1d3c60..aa2db53 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -43,9 +43,6 @@ Application.registerPlugin(TickerPlugin); Application.registerPlugin(AppLoaderPlugin); -// Apply deplayed mixins -utils.mixins.performMixins(); - /** * String of the current PIXI version. * diff --git a/bundles/pixi.js/src/useDeprecated.js b/bundles/pixi.js/src/useDeprecated.js index 8a5077e..6aafc18 100644 --- a/bundles/pixi.js/src/useDeprecated.js +++ b/bundles/pixi.js/src/useDeprecated.js @@ -928,4 +928,38 @@ this.autoDensity = value; }, }); + + /** + * @namespace PIXI.utils.mixins + * @deprecated since 5.0.0 + */ + PIXI.utils.mixins = { + /** + * @memberof PIXI.utils.mixins + * @function mixin + * @deprecated since 5.0.0 + */ + mixin() + { + deprecation(v5, 'PIXI.utils.mixins.mixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function delayMixin + * @deprecated since 5.0.0 + */ + delayMixin() + { + deprecation(v5, 'PIXI.utils.mixins.delayMixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function performMixins + * @deprecated since 5.0.0 + */ + performMixins() + { + deprecation(v5, 'PIXI.utils.mixins.performMixins no longer available'); + }, + }; } diff --git a/packages/accessibility/src/AccessibilityManager.js b/packages/accessibility/src/AccessibilityManager.js index 8fea8ba..5908bfe 100644 --- a/packages/accessibility/src/AccessibilityManager.js +++ b/packages/accessibility/src/AccessibilityManager.js @@ -1,13 +1,10 @@ import Device from 'ismobilejs'; import accessibleTarget from './accessibleTarget'; -import { removeItems, mixins } from '@pixi/utils'; +import { removeItems } from '@pixi/utils'; import { DisplayObject } from '@pixi/display'; // add some extra variables to the container.. -mixins.delayMixin( - DisplayObject.prototype, - accessibleTarget -); +DisplayObject.mixin(accessibleTarget); const KEY_CODE_TAB = 9; diff --git a/packages/accessibility/test/accessibleTarget.js b/packages/accessibility/test/accessibleTarget.js index 83782a1..3a54be6 100644 --- a/packages/accessibility/test/accessibleTarget.js +++ b/packages/accessibility/test/accessibleTarget.js @@ -1,21 +1,11 @@ -const { accessibleTarget } = require('../'); const { DisplayObject } = require('@pixi/display'); -const { mixins } = require('@pixi/utils'); + +require('../'); describe('PIXI.accessibility.accessibleTarget', function () { it('should have target public properties', function () { - expect(accessibleTarget.accessible).to.be.a.boolean; - expect(accessibleTarget.accessible).to.be.false; - expect(accessibleTarget.accessibleTitle).to.be.null; - expect(accessibleTarget.accessibleHint).to.be.null; - expect(accessibleTarget.tabIndex).to.equal(0); - }); - - it('should add properties after mixin', function () - { - mixins.performMixins(); const obj = new DisplayObject(); expect(obj.accessible).to.be.a.boolean; diff --git a/packages/display/src/DisplayObject.js b/packages/display/src/DisplayObject.js index 20063cc..216ca4a 100644 --- a/packages/display/src/DisplayObject.js +++ b/packages/display/src/DisplayObject.js @@ -14,6 +14,33 @@ */ export default class DisplayObject extends EventEmitter { + /** + * Mixes all enumerable properties and methods from a source object to DisplayObject. + * + * @param {object} source The source of properties and methods to mix in. + */ + static mixin(source) + { + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty( + DisplayObject.prototype, + propertyName, + Object.getOwnPropertyDescriptor(source, propertyName) + ); + } + } + constructor() { super(); diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index d1d3c60..aa2db53 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -43,9 +43,6 @@ Application.registerPlugin(TickerPlugin); Application.registerPlugin(AppLoaderPlugin); -// Apply deplayed mixins -utils.mixins.performMixins(); - /** * String of the current PIXI version. * diff --git a/bundles/pixi.js/src/useDeprecated.js b/bundles/pixi.js/src/useDeprecated.js index 8a5077e..6aafc18 100644 --- a/bundles/pixi.js/src/useDeprecated.js +++ b/bundles/pixi.js/src/useDeprecated.js @@ -928,4 +928,38 @@ this.autoDensity = value; }, }); + + /** + * @namespace PIXI.utils.mixins + * @deprecated since 5.0.0 + */ + PIXI.utils.mixins = { + /** + * @memberof PIXI.utils.mixins + * @function mixin + * @deprecated since 5.0.0 + */ + mixin() + { + deprecation(v5, 'PIXI.utils.mixins.mixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function delayMixin + * @deprecated since 5.0.0 + */ + delayMixin() + { + deprecation(v5, 'PIXI.utils.mixins.delayMixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function performMixins + * @deprecated since 5.0.0 + */ + performMixins() + { + deprecation(v5, 'PIXI.utils.mixins.performMixins no longer available'); + }, + }; } diff --git a/packages/accessibility/src/AccessibilityManager.js b/packages/accessibility/src/AccessibilityManager.js index 8fea8ba..5908bfe 100644 --- a/packages/accessibility/src/AccessibilityManager.js +++ b/packages/accessibility/src/AccessibilityManager.js @@ -1,13 +1,10 @@ import Device from 'ismobilejs'; import accessibleTarget from './accessibleTarget'; -import { removeItems, mixins } from '@pixi/utils'; +import { removeItems } from '@pixi/utils'; import { DisplayObject } from '@pixi/display'; // add some extra variables to the container.. -mixins.delayMixin( - DisplayObject.prototype, - accessibleTarget -); +DisplayObject.mixin(accessibleTarget); const KEY_CODE_TAB = 9; diff --git a/packages/accessibility/test/accessibleTarget.js b/packages/accessibility/test/accessibleTarget.js index 83782a1..3a54be6 100644 --- a/packages/accessibility/test/accessibleTarget.js +++ b/packages/accessibility/test/accessibleTarget.js @@ -1,21 +1,11 @@ -const { accessibleTarget } = require('../'); const { DisplayObject } = require('@pixi/display'); -const { mixins } = require('@pixi/utils'); + +require('../'); describe('PIXI.accessibility.accessibleTarget', function () { it('should have target public properties', function () { - expect(accessibleTarget.accessible).to.be.a.boolean; - expect(accessibleTarget.accessible).to.be.false; - expect(accessibleTarget.accessibleTitle).to.be.null; - expect(accessibleTarget.accessibleHint).to.be.null; - expect(accessibleTarget.tabIndex).to.equal(0); - }); - - it('should add properties after mixin', function () - { - mixins.performMixins(); const obj = new DisplayObject(); expect(obj.accessible).to.be.a.boolean; diff --git a/packages/display/src/DisplayObject.js b/packages/display/src/DisplayObject.js index 20063cc..216ca4a 100644 --- a/packages/display/src/DisplayObject.js +++ b/packages/display/src/DisplayObject.js @@ -14,6 +14,33 @@ */ export default class DisplayObject extends EventEmitter { + /** + * Mixes all enumerable properties and methods from a source object to DisplayObject. + * + * @param {object} source The source of properties and methods to mix in. + */ + static mixin(source) + { + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty( + DisplayObject.prototype, + propertyName, + Object.getOwnPropertyDescriptor(source, propertyName) + ); + } + } + constructor() { super(); diff --git a/packages/interaction/src/InteractionManager.js b/packages/interaction/src/InteractionManager.js index af8b086..cd3d3fd 100644 --- a/packages/interaction/src/InteractionManager.js +++ b/packages/interaction/src/InteractionManager.js @@ -1,18 +1,15 @@ import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { Point } from '@pixi/math'; import { DisplayObject } from '@pixi/display'; -import { mixins } from '@pixi/utils'; import InteractionData from './InteractionData'; import InteractionEvent from './InteractionEvent'; import InteractionTrackingData from './InteractionTrackingData'; import EventEmitter from 'eventemitter3'; import interactiveTarget from './interactiveTarget'; -// Mix interactiveTarget into DisplayObject.prototype, after deprecation has been handled -mixins.delayMixin( - DisplayObject.prototype, - interactiveTarget -); +// Mix interactiveTarget into DisplayObject.prototype, +// after deprecation has been handled +DisplayObject.mixin(interactiveTarget); const MOUSE_POINTER_ID = 1; diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index d1d3c60..aa2db53 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -43,9 +43,6 @@ Application.registerPlugin(TickerPlugin); Application.registerPlugin(AppLoaderPlugin); -// Apply deplayed mixins -utils.mixins.performMixins(); - /** * String of the current PIXI version. * diff --git a/bundles/pixi.js/src/useDeprecated.js b/bundles/pixi.js/src/useDeprecated.js index 8a5077e..6aafc18 100644 --- a/bundles/pixi.js/src/useDeprecated.js +++ b/bundles/pixi.js/src/useDeprecated.js @@ -928,4 +928,38 @@ this.autoDensity = value; }, }); + + /** + * @namespace PIXI.utils.mixins + * @deprecated since 5.0.0 + */ + PIXI.utils.mixins = { + /** + * @memberof PIXI.utils.mixins + * @function mixin + * @deprecated since 5.0.0 + */ + mixin() + { + deprecation(v5, 'PIXI.utils.mixins.mixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function delayMixin + * @deprecated since 5.0.0 + */ + delayMixin() + { + deprecation(v5, 'PIXI.utils.mixins.delayMixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function performMixins + * @deprecated since 5.0.0 + */ + performMixins() + { + deprecation(v5, 'PIXI.utils.mixins.performMixins no longer available'); + }, + }; } diff --git a/packages/accessibility/src/AccessibilityManager.js b/packages/accessibility/src/AccessibilityManager.js index 8fea8ba..5908bfe 100644 --- a/packages/accessibility/src/AccessibilityManager.js +++ b/packages/accessibility/src/AccessibilityManager.js @@ -1,13 +1,10 @@ import Device from 'ismobilejs'; import accessibleTarget from './accessibleTarget'; -import { removeItems, mixins } from '@pixi/utils'; +import { removeItems } from '@pixi/utils'; import { DisplayObject } from '@pixi/display'; // add some extra variables to the container.. -mixins.delayMixin( - DisplayObject.prototype, - accessibleTarget -); +DisplayObject.mixin(accessibleTarget); const KEY_CODE_TAB = 9; diff --git a/packages/accessibility/test/accessibleTarget.js b/packages/accessibility/test/accessibleTarget.js index 83782a1..3a54be6 100644 --- a/packages/accessibility/test/accessibleTarget.js +++ b/packages/accessibility/test/accessibleTarget.js @@ -1,21 +1,11 @@ -const { accessibleTarget } = require('../'); const { DisplayObject } = require('@pixi/display'); -const { mixins } = require('@pixi/utils'); + +require('../'); describe('PIXI.accessibility.accessibleTarget', function () { it('should have target public properties', function () { - expect(accessibleTarget.accessible).to.be.a.boolean; - expect(accessibleTarget.accessible).to.be.false; - expect(accessibleTarget.accessibleTitle).to.be.null; - expect(accessibleTarget.accessibleHint).to.be.null; - expect(accessibleTarget.tabIndex).to.equal(0); - }); - - it('should add properties after mixin', function () - { - mixins.performMixins(); const obj = new DisplayObject(); expect(obj.accessible).to.be.a.boolean; diff --git a/packages/display/src/DisplayObject.js b/packages/display/src/DisplayObject.js index 20063cc..216ca4a 100644 --- a/packages/display/src/DisplayObject.js +++ b/packages/display/src/DisplayObject.js @@ -14,6 +14,33 @@ */ export default class DisplayObject extends EventEmitter { + /** + * Mixes all enumerable properties and methods from a source object to DisplayObject. + * + * @param {object} source The source of properties and methods to mix in. + */ + static mixin(source) + { + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty( + DisplayObject.prototype, + propertyName, + Object.getOwnPropertyDescriptor(source, propertyName) + ); + } + } + constructor() { super(); diff --git a/packages/interaction/src/InteractionManager.js b/packages/interaction/src/InteractionManager.js index af8b086..cd3d3fd 100644 --- a/packages/interaction/src/InteractionManager.js +++ b/packages/interaction/src/InteractionManager.js @@ -1,18 +1,15 @@ import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { Point } from '@pixi/math'; import { DisplayObject } from '@pixi/display'; -import { mixins } from '@pixi/utils'; import InteractionData from './InteractionData'; import InteractionEvent from './InteractionEvent'; import InteractionTrackingData from './InteractionTrackingData'; import EventEmitter from 'eventemitter3'; import interactiveTarget from './interactiveTarget'; -// Mix interactiveTarget into DisplayObject.prototype, after deprecation has been handled -mixins.delayMixin( - DisplayObject.prototype, - interactiveTarget -); +// Mix interactiveTarget into DisplayObject.prototype, +// after deprecation has been handled +DisplayObject.mixin(interactiveTarget); const MOUSE_POINTER_ID = 1; diff --git a/packages/interaction/test/InteractionManager.js b/packages/interaction/test/InteractionManager.js index c93fc4a..0671e97 100644 --- a/packages/interaction/test/InteractionManager.js +++ b/packages/interaction/test/InteractionManager.js @@ -2,7 +2,6 @@ const { Container } = require('@pixi/display'); const { Graphics } = require('@pixi/graphics'); const { Point, Rectangle } = require('@pixi/math'); -const { mixins } = require('@pixi/utils'); const { CanvasRenderer } = require('@pixi/canvas-renderer'); const { InteractionManager } = require('../'); const { CanvasGraphicsRenderer } = require('@pixi/canvas-graphics'); @@ -15,8 +14,6 @@ CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); -mixins.performMixins(); - describe('PIXI.interaction.InteractionManager', function () { afterEach(function () diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index d1d3c60..aa2db53 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -43,9 +43,6 @@ Application.registerPlugin(TickerPlugin); Application.registerPlugin(AppLoaderPlugin); -// Apply deplayed mixins -utils.mixins.performMixins(); - /** * String of the current PIXI version. * diff --git a/bundles/pixi.js/src/useDeprecated.js b/bundles/pixi.js/src/useDeprecated.js index 8a5077e..6aafc18 100644 --- a/bundles/pixi.js/src/useDeprecated.js +++ b/bundles/pixi.js/src/useDeprecated.js @@ -928,4 +928,38 @@ this.autoDensity = value; }, }); + + /** + * @namespace PIXI.utils.mixins + * @deprecated since 5.0.0 + */ + PIXI.utils.mixins = { + /** + * @memberof PIXI.utils.mixins + * @function mixin + * @deprecated since 5.0.0 + */ + mixin() + { + deprecation(v5, 'PIXI.utils.mixins.mixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function delayMixin + * @deprecated since 5.0.0 + */ + delayMixin() + { + deprecation(v5, 'PIXI.utils.mixins.delayMixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function performMixins + * @deprecated since 5.0.0 + */ + performMixins() + { + deprecation(v5, 'PIXI.utils.mixins.performMixins no longer available'); + }, + }; } diff --git a/packages/accessibility/src/AccessibilityManager.js b/packages/accessibility/src/AccessibilityManager.js index 8fea8ba..5908bfe 100644 --- a/packages/accessibility/src/AccessibilityManager.js +++ b/packages/accessibility/src/AccessibilityManager.js @@ -1,13 +1,10 @@ import Device from 'ismobilejs'; import accessibleTarget from './accessibleTarget'; -import { removeItems, mixins } from '@pixi/utils'; +import { removeItems } from '@pixi/utils'; import { DisplayObject } from '@pixi/display'; // add some extra variables to the container.. -mixins.delayMixin( - DisplayObject.prototype, - accessibleTarget -); +DisplayObject.mixin(accessibleTarget); const KEY_CODE_TAB = 9; diff --git a/packages/accessibility/test/accessibleTarget.js b/packages/accessibility/test/accessibleTarget.js index 83782a1..3a54be6 100644 --- a/packages/accessibility/test/accessibleTarget.js +++ b/packages/accessibility/test/accessibleTarget.js @@ -1,21 +1,11 @@ -const { accessibleTarget } = require('../'); const { DisplayObject } = require('@pixi/display'); -const { mixins } = require('@pixi/utils'); + +require('../'); describe('PIXI.accessibility.accessibleTarget', function () { it('should have target public properties', function () { - expect(accessibleTarget.accessible).to.be.a.boolean; - expect(accessibleTarget.accessible).to.be.false; - expect(accessibleTarget.accessibleTitle).to.be.null; - expect(accessibleTarget.accessibleHint).to.be.null; - expect(accessibleTarget.tabIndex).to.equal(0); - }); - - it('should add properties after mixin', function () - { - mixins.performMixins(); const obj = new DisplayObject(); expect(obj.accessible).to.be.a.boolean; diff --git a/packages/display/src/DisplayObject.js b/packages/display/src/DisplayObject.js index 20063cc..216ca4a 100644 --- a/packages/display/src/DisplayObject.js +++ b/packages/display/src/DisplayObject.js @@ -14,6 +14,33 @@ */ export default class DisplayObject extends EventEmitter { + /** + * Mixes all enumerable properties and methods from a source object to DisplayObject. + * + * @param {object} source The source of properties and methods to mix in. + */ + static mixin(source) + { + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty( + DisplayObject.prototype, + propertyName, + Object.getOwnPropertyDescriptor(source, propertyName) + ); + } + } + constructor() { super(); diff --git a/packages/interaction/src/InteractionManager.js b/packages/interaction/src/InteractionManager.js index af8b086..cd3d3fd 100644 --- a/packages/interaction/src/InteractionManager.js +++ b/packages/interaction/src/InteractionManager.js @@ -1,18 +1,15 @@ import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { Point } from '@pixi/math'; import { DisplayObject } from '@pixi/display'; -import { mixins } from '@pixi/utils'; import InteractionData from './InteractionData'; import InteractionEvent from './InteractionEvent'; import InteractionTrackingData from './InteractionTrackingData'; import EventEmitter from 'eventemitter3'; import interactiveTarget from './interactiveTarget'; -// Mix interactiveTarget into DisplayObject.prototype, after deprecation has been handled -mixins.delayMixin( - DisplayObject.prototype, - interactiveTarget -); +// Mix interactiveTarget into DisplayObject.prototype, +// after deprecation has been handled +DisplayObject.mixin(interactiveTarget); const MOUSE_POINTER_ID = 1; diff --git a/packages/interaction/test/InteractionManager.js b/packages/interaction/test/InteractionManager.js index c93fc4a..0671e97 100644 --- a/packages/interaction/test/InteractionManager.js +++ b/packages/interaction/test/InteractionManager.js @@ -2,7 +2,6 @@ const { Container } = require('@pixi/display'); const { Graphics } = require('@pixi/graphics'); const { Point, Rectangle } = require('@pixi/math'); -const { mixins } = require('@pixi/utils'); const { CanvasRenderer } = require('@pixi/canvas-renderer'); const { InteractionManager } = require('../'); const { CanvasGraphicsRenderer } = require('@pixi/canvas-graphics'); @@ -15,8 +14,6 @@ CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); -mixins.performMixins(); - describe('PIXI.interaction.InteractionManager', function () { afterEach(function () diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index 4e71aa1..a1cab20 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -42,12 +42,6 @@ export { EventEmitter }; /** - * @namespace PIXI.utils.mixins - */ -import * as mixins from './mixins'; -export { mixins }; - -/** * A polygon triangulation library * * @see {@link https://github.com/mapbox/earcut} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index d1d3c60..aa2db53 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -43,9 +43,6 @@ Application.registerPlugin(TickerPlugin); Application.registerPlugin(AppLoaderPlugin); -// Apply deplayed mixins -utils.mixins.performMixins(); - /** * String of the current PIXI version. * diff --git a/bundles/pixi.js/src/useDeprecated.js b/bundles/pixi.js/src/useDeprecated.js index 8a5077e..6aafc18 100644 --- a/bundles/pixi.js/src/useDeprecated.js +++ b/bundles/pixi.js/src/useDeprecated.js @@ -928,4 +928,38 @@ this.autoDensity = value; }, }); + + /** + * @namespace PIXI.utils.mixins + * @deprecated since 5.0.0 + */ + PIXI.utils.mixins = { + /** + * @memberof PIXI.utils.mixins + * @function mixin + * @deprecated since 5.0.0 + */ + mixin() + { + deprecation(v5, 'PIXI.utils.mixins.mixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function delayMixin + * @deprecated since 5.0.0 + */ + delayMixin() + { + deprecation(v5, 'PIXI.utils.mixins.delayMixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function performMixins + * @deprecated since 5.0.0 + */ + performMixins() + { + deprecation(v5, 'PIXI.utils.mixins.performMixins no longer available'); + }, + }; } diff --git a/packages/accessibility/src/AccessibilityManager.js b/packages/accessibility/src/AccessibilityManager.js index 8fea8ba..5908bfe 100644 --- a/packages/accessibility/src/AccessibilityManager.js +++ b/packages/accessibility/src/AccessibilityManager.js @@ -1,13 +1,10 @@ import Device from 'ismobilejs'; import accessibleTarget from './accessibleTarget'; -import { removeItems, mixins } from '@pixi/utils'; +import { removeItems } from '@pixi/utils'; import { DisplayObject } from '@pixi/display'; // add some extra variables to the container.. -mixins.delayMixin( - DisplayObject.prototype, - accessibleTarget -); +DisplayObject.mixin(accessibleTarget); const KEY_CODE_TAB = 9; diff --git a/packages/accessibility/test/accessibleTarget.js b/packages/accessibility/test/accessibleTarget.js index 83782a1..3a54be6 100644 --- a/packages/accessibility/test/accessibleTarget.js +++ b/packages/accessibility/test/accessibleTarget.js @@ -1,21 +1,11 @@ -const { accessibleTarget } = require('../'); const { DisplayObject } = require('@pixi/display'); -const { mixins } = require('@pixi/utils'); + +require('../'); describe('PIXI.accessibility.accessibleTarget', function () { it('should have target public properties', function () { - expect(accessibleTarget.accessible).to.be.a.boolean; - expect(accessibleTarget.accessible).to.be.false; - expect(accessibleTarget.accessibleTitle).to.be.null; - expect(accessibleTarget.accessibleHint).to.be.null; - expect(accessibleTarget.tabIndex).to.equal(0); - }); - - it('should add properties after mixin', function () - { - mixins.performMixins(); const obj = new DisplayObject(); expect(obj.accessible).to.be.a.boolean; diff --git a/packages/display/src/DisplayObject.js b/packages/display/src/DisplayObject.js index 20063cc..216ca4a 100644 --- a/packages/display/src/DisplayObject.js +++ b/packages/display/src/DisplayObject.js @@ -14,6 +14,33 @@ */ export default class DisplayObject extends EventEmitter { + /** + * Mixes all enumerable properties and methods from a source object to DisplayObject. + * + * @param {object} source The source of properties and methods to mix in. + */ + static mixin(source) + { + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty( + DisplayObject.prototype, + propertyName, + Object.getOwnPropertyDescriptor(source, propertyName) + ); + } + } + constructor() { super(); diff --git a/packages/interaction/src/InteractionManager.js b/packages/interaction/src/InteractionManager.js index af8b086..cd3d3fd 100644 --- a/packages/interaction/src/InteractionManager.js +++ b/packages/interaction/src/InteractionManager.js @@ -1,18 +1,15 @@ import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { Point } from '@pixi/math'; import { DisplayObject } from '@pixi/display'; -import { mixins } from '@pixi/utils'; import InteractionData from './InteractionData'; import InteractionEvent from './InteractionEvent'; import InteractionTrackingData from './InteractionTrackingData'; import EventEmitter from 'eventemitter3'; import interactiveTarget from './interactiveTarget'; -// Mix interactiveTarget into DisplayObject.prototype, after deprecation has been handled -mixins.delayMixin( - DisplayObject.prototype, - interactiveTarget -); +// Mix interactiveTarget into DisplayObject.prototype, +// after deprecation has been handled +DisplayObject.mixin(interactiveTarget); const MOUSE_POINTER_ID = 1; diff --git a/packages/interaction/test/InteractionManager.js b/packages/interaction/test/InteractionManager.js index c93fc4a..0671e97 100644 --- a/packages/interaction/test/InteractionManager.js +++ b/packages/interaction/test/InteractionManager.js @@ -2,7 +2,6 @@ const { Container } = require('@pixi/display'); const { Graphics } = require('@pixi/graphics'); const { Point, Rectangle } = require('@pixi/math'); -const { mixins } = require('@pixi/utils'); const { CanvasRenderer } = require('@pixi/canvas-renderer'); const { InteractionManager } = require('../'); const { CanvasGraphicsRenderer } = require('@pixi/canvas-graphics'); @@ -15,8 +14,6 @@ CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); -mixins.performMixins(); - describe('PIXI.interaction.InteractionManager', function () { afterEach(function () diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index 4e71aa1..a1cab20 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -42,12 +42,6 @@ export { EventEmitter }; /** - * @namespace PIXI.utils.mixins - */ -import * as mixins from './mixins'; -export { mixins }; - -/** * A polygon triangulation library * * @see {@link https://github.com/mapbox/earcut} diff --git a/packages/utils/src/mixins.js b/packages/utils/src/mixins.js deleted file mode 100644 index 335c54f..0000000 --- a/packages/utils/src/mixins.js +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Mixes all enumerable properties and methods from a source object to a target object. - * - * @memberof PIXI.utils.mixins - * @function mixin - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function mixin(target, source) -{ - if (!target || !source) return; - // in ES8/ES2017, this would be really easy: - // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); - - // get all the enumerable property keys - const keys = Object.keys(source); - - // loop through properties - for (let i = 0; i < keys.length; ++i) - { - const propertyName = keys[i]; - - // Set the property using the property descriptor - this works for accessors and normal value properties - Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); - } -} - -const mixins = []; - -/** - * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation - * can take effect. - * - * @memberof PIXI.utils.mixins - * @function delayMixin - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function delayMixin(target, source) -{ - mixins.push(target, source); -} - -/** - * Handles all mixins queued via delayMixin(). - * - * @memberof PIXI.utils.mixins - * @function performMixins - */ -export function performMixins() -{ - for (let i = 0; i < mixins.length; i += 2) - { - mixin(mixins[i], mixins[i + 1]); - } - mixins.length = 0; -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index d1d3c60..aa2db53 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -43,9 +43,6 @@ Application.registerPlugin(TickerPlugin); Application.registerPlugin(AppLoaderPlugin); -// Apply deplayed mixins -utils.mixins.performMixins(); - /** * String of the current PIXI version. * diff --git a/bundles/pixi.js/src/useDeprecated.js b/bundles/pixi.js/src/useDeprecated.js index 8a5077e..6aafc18 100644 --- a/bundles/pixi.js/src/useDeprecated.js +++ b/bundles/pixi.js/src/useDeprecated.js @@ -928,4 +928,38 @@ this.autoDensity = value; }, }); + + /** + * @namespace PIXI.utils.mixins + * @deprecated since 5.0.0 + */ + PIXI.utils.mixins = { + /** + * @memberof PIXI.utils.mixins + * @function mixin + * @deprecated since 5.0.0 + */ + mixin() + { + deprecation(v5, 'PIXI.utils.mixins.mixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function delayMixin + * @deprecated since 5.0.0 + */ + delayMixin() + { + deprecation(v5, 'PIXI.utils.mixins.delayMixin no longer available'); + }, + /** + * @memberof PIXI.utils.mixins + * @function performMixins + * @deprecated since 5.0.0 + */ + performMixins() + { + deprecation(v5, 'PIXI.utils.mixins.performMixins no longer available'); + }, + }; } diff --git a/packages/accessibility/src/AccessibilityManager.js b/packages/accessibility/src/AccessibilityManager.js index 8fea8ba..5908bfe 100644 --- a/packages/accessibility/src/AccessibilityManager.js +++ b/packages/accessibility/src/AccessibilityManager.js @@ -1,13 +1,10 @@ import Device from 'ismobilejs'; import accessibleTarget from './accessibleTarget'; -import { removeItems, mixins } from '@pixi/utils'; +import { removeItems } from '@pixi/utils'; import { DisplayObject } from '@pixi/display'; // add some extra variables to the container.. -mixins.delayMixin( - DisplayObject.prototype, - accessibleTarget -); +DisplayObject.mixin(accessibleTarget); const KEY_CODE_TAB = 9; diff --git a/packages/accessibility/test/accessibleTarget.js b/packages/accessibility/test/accessibleTarget.js index 83782a1..3a54be6 100644 --- a/packages/accessibility/test/accessibleTarget.js +++ b/packages/accessibility/test/accessibleTarget.js @@ -1,21 +1,11 @@ -const { accessibleTarget } = require('../'); const { DisplayObject } = require('@pixi/display'); -const { mixins } = require('@pixi/utils'); + +require('../'); describe('PIXI.accessibility.accessibleTarget', function () { it('should have target public properties', function () { - expect(accessibleTarget.accessible).to.be.a.boolean; - expect(accessibleTarget.accessible).to.be.false; - expect(accessibleTarget.accessibleTitle).to.be.null; - expect(accessibleTarget.accessibleHint).to.be.null; - expect(accessibleTarget.tabIndex).to.equal(0); - }); - - it('should add properties after mixin', function () - { - mixins.performMixins(); const obj = new DisplayObject(); expect(obj.accessible).to.be.a.boolean; diff --git a/packages/display/src/DisplayObject.js b/packages/display/src/DisplayObject.js index 20063cc..216ca4a 100644 --- a/packages/display/src/DisplayObject.js +++ b/packages/display/src/DisplayObject.js @@ -14,6 +14,33 @@ */ export default class DisplayObject extends EventEmitter { + /** + * Mixes all enumerable properties and methods from a source object to DisplayObject. + * + * @param {object} source The source of properties and methods to mix in. + */ + static mixin(source) + { + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty( + DisplayObject.prototype, + propertyName, + Object.getOwnPropertyDescriptor(source, propertyName) + ); + } + } + constructor() { super(); diff --git a/packages/interaction/src/InteractionManager.js b/packages/interaction/src/InteractionManager.js index af8b086..cd3d3fd 100644 --- a/packages/interaction/src/InteractionManager.js +++ b/packages/interaction/src/InteractionManager.js @@ -1,18 +1,15 @@ import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { Point } from '@pixi/math'; import { DisplayObject } from '@pixi/display'; -import { mixins } from '@pixi/utils'; import InteractionData from './InteractionData'; import InteractionEvent from './InteractionEvent'; import InteractionTrackingData from './InteractionTrackingData'; import EventEmitter from 'eventemitter3'; import interactiveTarget from './interactiveTarget'; -// Mix interactiveTarget into DisplayObject.prototype, after deprecation has been handled -mixins.delayMixin( - DisplayObject.prototype, - interactiveTarget -); +// Mix interactiveTarget into DisplayObject.prototype, +// after deprecation has been handled +DisplayObject.mixin(interactiveTarget); const MOUSE_POINTER_ID = 1; diff --git a/packages/interaction/test/InteractionManager.js b/packages/interaction/test/InteractionManager.js index c93fc4a..0671e97 100644 --- a/packages/interaction/test/InteractionManager.js +++ b/packages/interaction/test/InteractionManager.js @@ -2,7 +2,6 @@ const { Container } = require('@pixi/display'); const { Graphics } = require('@pixi/graphics'); const { Point, Rectangle } = require('@pixi/math'); -const { mixins } = require('@pixi/utils'); const { CanvasRenderer } = require('@pixi/canvas-renderer'); const { InteractionManager } = require('../'); const { CanvasGraphicsRenderer } = require('@pixi/canvas-graphics'); @@ -15,8 +14,6 @@ CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); -mixins.performMixins(); - describe('PIXI.interaction.InteractionManager', function () { afterEach(function () diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index 4e71aa1..a1cab20 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -42,12 +42,6 @@ export { EventEmitter }; /** - * @namespace PIXI.utils.mixins - */ -import * as mixins from './mixins'; -export { mixins }; - -/** * A polygon triangulation library * * @see {@link https://github.com/mapbox/earcut} diff --git a/packages/utils/src/mixins.js b/packages/utils/src/mixins.js deleted file mode 100644 index 335c54f..0000000 --- a/packages/utils/src/mixins.js +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Mixes all enumerable properties and methods from a source object to a target object. - * - * @memberof PIXI.utils.mixins - * @function mixin - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function mixin(target, source) -{ - if (!target || !source) return; - // in ES8/ES2017, this would be really easy: - // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); - - // get all the enumerable property keys - const keys = Object.keys(source); - - // loop through properties - for (let i = 0; i < keys.length; ++i) - { - const propertyName = keys[i]; - - // Set the property using the property descriptor - this works for accessors and normal value properties - Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); - } -} - -const mixins = []; - -/** - * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation - * can take effect. - * - * @memberof PIXI.utils.mixins - * @function delayMixin - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function delayMixin(target, source) -{ - mixins.push(target, source); -} - -/** - * Handles all mixins queued via delayMixin(). - * - * @memberof PIXI.utils.mixins - * @function performMixins - */ -export function performMixins() -{ - for (let i = 0; i < mixins.length; i += 2) - { - mixin(mixins[i], mixins[i + 1]); - } - mixins.length = 0; -} diff --git a/packages/utils/test/index.js b/packages/utils/test/index.js index 4567122..62cf3e8 100755 --- a/packages/utils/test/index.js +++ b/packages/utils/test/index.js @@ -243,32 +243,6 @@ }); }); - describe('mixins', function () - { - it('should exist', function () - { - expect(utils.mixins).to.be.an('object'); - }); - - it('should perform mixins', function () - { - // eslint-disable-next-line - const target = function () {}; - const source = { - foo: true, - bar: 1, - }; - - utils.mixins.delayMixin(target.prototype, source); - expect(target.prototype.foo).to.be.undefined; - expect(target.prototype.bar).to.be.undefined; - - utils.mixins.performMixins(); - expect(target.prototype.foo).to.equal(true); - expect(target.prototype.bar).to.equal(1); - }); - }); - describe('earcut', function () { it('should exist', function ()