diff --git a/package.json b/package.json index b9506f5..9bdccae 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", + "remove-array-items": "^1.0.0", "resource-loader": "^2.0.6" }, "devDependencies": { diff --git a/package.json b/package.json index b9506f5..9bdccae 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", + "remove-array-items": "^1.0.0", "resource-loader": "^2.0.6" }, "devDependencies": { diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 098b383..22e2d98 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -4,6 +4,7 @@ import pluginTarget from './pluginTarget'; import * as mixins from './mixin'; import * as isMobile from 'ismobilejs'; +import removeItems from 'remove-array-items'; let nextUid = 0; let saidHello = false; @@ -35,6 +36,15 @@ * @type {Object} */ isMobile, + + /** + * @see {@link https://github.com/mreinstein/remove-array-items} + * + * @memberof PIXI.utils + * @function removeItems + * @type {Object} + */ + removeItems, /** * @see {@link https://github.com/primus/eventemitter3} * @@ -333,36 +343,6 @@ } /** - * Remove a range of items from an array - * - * @memberof PIXI.utils - * @function removeItems - * @param {Array<*>} arr The target array - * @param {number} startIdx The index to begin removing from (inclusive) - * @param {number} removeCount How many items to remove - */ -export function removeItems(arr, startIdx, removeCount) -{ - const length = arr.length; - - if (startIdx >= length || removeCount === 0) - { - return; - } - - removeCount = (startIdx + removeCount > length ? length - startIdx : removeCount); - - const len = length - removeCount; - - for (let i = startIdx; i < len; ++i) - { - arr[i] = arr[i + removeCount]; - } - - arr.length = len; -} - -/** * @todo Describe property usage * * @memberof PIXI.utils diff --git a/package.json b/package.json index b9506f5..9bdccae 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "ismobilejs": "^0.4.0", "object-assign": "^4.0.1", "pixi-gl-core": "^1.0.3", + "remove-array-items": "^1.0.0", "resource-loader": "^2.0.6" }, "devDependencies": { diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 098b383..22e2d98 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -4,6 +4,7 @@ import pluginTarget from './pluginTarget'; import * as mixins from './mixin'; import * as isMobile from 'ismobilejs'; +import removeItems from 'remove-array-items'; let nextUid = 0; let saidHello = false; @@ -35,6 +36,15 @@ * @type {Object} */ isMobile, + + /** + * @see {@link https://github.com/mreinstein/remove-array-items} + * + * @memberof PIXI.utils + * @function removeItems + * @type {Object} + */ + removeItems, /** * @see {@link https://github.com/primus/eventemitter3} * @@ -333,36 +343,6 @@ } /** - * Remove a range of items from an array - * - * @memberof PIXI.utils - * @function removeItems - * @param {Array<*>} arr The target array - * @param {number} startIdx The index to begin removing from (inclusive) - * @param {number} removeCount How many items to remove - */ -export function removeItems(arr, startIdx, removeCount) -{ - const length = arr.length; - - if (startIdx >= length || removeCount === 0) - { - return; - } - - removeCount = (startIdx + removeCount > length ? length - startIdx : removeCount); - - const len = length - removeCount; - - for (let i = startIdx; i < len; ++i) - { - arr[i] = arr[i + removeCount]; - } - - arr.length = len; -} - -/** * @todo Describe property usage * * @memberof PIXI.utils diff --git a/test/core/util.js b/test/core/util.js index 239aaeb..68c7e6d 100755 --- a/test/core/util.js +++ b/test/core/util.js @@ -280,39 +280,9 @@ describe('.removeItems', function () { - var arr; - - beforeEach(() => + it('should exist', function () { - arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - }); - - it('should return if the start index is greater than or equal to the length of the array', function () - { - PIXI.utils.removeItems(arr, arr.length + 1, 5); - expect(arr.length).to.be.equal(10); - }); - - it('should return if the remove count is 0', function () - { - PIXI.utils.removeItems(arr, 2, 0); - expect(arr.length).to.be.equal(10); - }); - - it('should remove the number of elements specified from the array, starting from the start index', function () - { - const res = [1, 2, 3, 8, 9, 10]; - - PIXI.utils.removeItems(arr, 3, 4); - expect(arr).to.be.deep.equal(res); - }); - - it('should remove other elements if delete count is > than the number of elements after start index', function () - { - const res = [1, 2, 3, 4, 5, 6, 7]; - - PIXI.utils.removeItems(arr, 7, 10); - expect(arr).to.be.deep.equal(res); + expect(PIXI.utils.removeItems).to.be.a('function'); }); });