Socket
Socket
Sign inDemoInstall

@pixi/runner

Package Overview
Dependencies
Maintainers
3
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pixi/runner - npm Package Compare versions

Comparing version 6.5.3 to 7.0.0-alpha

240

dist/cjs/runner.js
/*!
* @pixi/runner - v6.5.3
* Compiled Fri, 09 Sep 2022 13:55:20 UTC
* @pixi/runner - v7.0.0-alpha
* Compiled Fri, 09 Sep 2022 16:09:18 UTC
*

@@ -12,177 +12,67 @@ * @pixi/runner is licensed under the MIT License.

/**
* A Runner is a highly performant and simple alternative to signals. Best used in situations
* where events are dispatched to many objects at high frequency (say every frame!)
*
*
* like a signal..
* ```
* import { Runner } from '@pixi/runner';
*
* const myObject = {
* loaded: new Runner('loaded')
* }
*
* const listener = {
* loaded: function(){
* // thin
* }
* }
*
* myObject.loaded.add(listener);
*
* myObject.loaded.emit();
* ```
*
* Or for handling calling the same function on many items
* ```
* import { Runner } from '@pixi/runner';
*
* const myGame = {
* update: new Runner('update')
* }
*
* const gameObject = {
* update: function(time){
* // update my gamey state
* }
* }
*
* myGame.update.add(gameObject);
*
* myGame.update.emit(time);
* ```
* @memberof PIXI
*/
var Runner = /** @class */ (function () {
/**
* @param name - The function name that will be executed on the listeners added to this Runner.
*/
function Runner(name) {
this.items = [];
this._name = name;
this._aliasCount = 0;
class Runner {
constructor(name) {
this.items = [];
this._name = name;
this._aliasCount = 0;
}
emit(a0, a1, a2, a3, a4, a5, a6, a7) {
if (arguments.length > 8) {
throw new Error("max arguments reached");
}
/* eslint-disable jsdoc/require-param, jsdoc/check-param-names */
/**
* Dispatch/Broadcast Runner to all listeners added to the queue.
* @param {...any} params - (optional) parameters to pass to each listener
*/
/* eslint-enable jsdoc/require-param, jsdoc/check-param-names */
Runner.prototype.emit = function (a0, a1, a2, a3, a4, a5, a6, a7) {
if (arguments.length > 8) {
throw new Error('max arguments reached');
}
var _a = this, name = _a.name, items = _a.items;
this._aliasCount++;
for (var i = 0, len = items.length; i < len; i++) {
items[i][name](a0, a1, a2, a3, a4, a5, a6, a7);
}
if (items === this.items) {
this._aliasCount--;
}
return this;
};
Runner.prototype.ensureNonAliasedItems = function () {
if (this._aliasCount > 0 && this.items.length > 1) {
this._aliasCount = 0;
this.items = this.items.slice(0);
}
};
/**
* Add a listener to the Runner
*
* Runners do not need to have scope or functions passed to them.
* All that is required is to pass the listening object and ensure that it has contains a function that has the same name
* as the name provided to the Runner when it was created.
*
* Eg A listener passed to this Runner will require a 'complete' function.
*
* ```
* import { Runner } from '@pixi/runner';
*
* const complete = new Runner('complete');
* ```
*
* The scope used will be the object itself.
* @param {any} item - The object that will be listening.
*/
Runner.prototype.add = function (item) {
if (item[this._name]) {
this.ensureNonAliasedItems();
this.remove(item);
this.items.push(item);
}
return this;
};
/**
* Remove a single listener from the dispatch queue.
* @param {any} item - The listener that you would like to remove.
*/
Runner.prototype.remove = function (item) {
var index = this.items.indexOf(item);
if (index !== -1) {
this.ensureNonAliasedItems();
this.items.splice(index, 1);
}
return this;
};
/**
* Check to see if the listener is already in the Runner
* @param {any} item - The listener that you would like to check.
*/
Runner.prototype.contains = function (item) {
return this.items.indexOf(item) !== -1;
};
/** Remove all listeners from the Runner */
Runner.prototype.removeAll = function () {
this.ensureNonAliasedItems();
this.items.length = 0;
return this;
};
/** Remove all references, don't use after this. */
Runner.prototype.destroy = function () {
this.removeAll();
this.items = null;
this._name = null;
};
Object.defineProperty(Runner.prototype, "empty", {
/**
* `true` if there are no this Runner contains no listeners
* @readonly
*/
get: function () {
return this.items.length === 0;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Runner.prototype, "name", {
/**
* The name of the runner.
* @readonly
*/
get: function () {
return this._name;
},
enumerable: false,
configurable: true
});
return Runner;
}());
const { name, items } = this;
this._aliasCount++;
for (let i = 0, len = items.length; i < len; i++) {
items[i][name](a0, a1, a2, a3, a4, a5, a6, a7);
}
if (items === this.items) {
this._aliasCount--;
}
return this;
}
ensureNonAliasedItems() {
if (this._aliasCount > 0 && this.items.length > 1) {
this._aliasCount = 0;
this.items = this.items.slice(0);
}
}
add(item) {
if (item[this._name]) {
this.ensureNonAliasedItems();
this.remove(item);
this.items.push(item);
}
return this;
}
remove(item) {
const index = this.items.indexOf(item);
if (index !== -1) {
this.ensureNonAliasedItems();
this.items.splice(index, 1);
}
return this;
}
contains(item) {
return this.items.includes(item);
}
removeAll() {
this.ensureNonAliasedItems();
this.items.length = 0;
return this;
}
destroy() {
this.removeAll();
this.items = null;
this._name = null;
}
get empty() {
return this.items.length === 0;
}
get name() {
return this._name;
}
}
Object.defineProperties(Runner.prototype, {
/**
* Alias for `emit`
* @memberof PIXI.Runner#
* @method dispatch
* @see PIXI.Runner#emit
*/
dispatch: { value: Runner.prototype.emit },
/**
* Alias for `emit`
* @memberof PIXI.Runner#
* @method run
* @see PIXI.Runner#emit
*/
run: { value: Runner.prototype.emit },
dispatch: { value: Runner.prototype.emit },
run: { value: Runner.prototype.emit }
});

@@ -189,0 +79,0 @@

@@ -1,9 +0,8 @@

/*!
* @pixi/runner - v6.5.3
* Compiled Fri, 09 Sep 2022 13:55:20 UTC
"use strict";/*!
* @pixi/runner - v7.0.0-alpha
* Compiled Fri, 09 Sep 2022 16:09:18 UTC
*
* @pixi/runner is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(){function t(t){this.items=[],this._name=t,this._aliasCount=0}return t.prototype.emit=function(t,e,i,s,n,r,o,u){if(arguments.length>8)throw new Error("max arguments reached");var h=this,a=h.name,m=h.items;this._aliasCount++;for(var p=0,l=m.length;p<l;p++)m[p][a](t,e,i,s,n,r,o,u);return m===this.items&&this._aliasCount--,this},t.prototype.ensureNonAliasedItems=function(){this._aliasCount>0&&this.items.length>1&&(this._aliasCount=0,this.items=this.items.slice(0))},t.prototype.add=function(t){return t[this._name]&&(this.ensureNonAliasedItems(),this.remove(t),this.items.push(t)),this},t.prototype.remove=function(t){var e=this.items.indexOf(t);return-1!==e&&(this.ensureNonAliasedItems(),this.items.splice(e,1)),this},t.prototype.contains=function(t){return-1!==this.items.indexOf(t)},t.prototype.removeAll=function(){return this.ensureNonAliasedItems(),this.items.length=0,this},t.prototype.destroy=function(){this.removeAll(),this.items=null,this._name=null},Object.defineProperty(t.prototype,"empty",{get:function(){return 0===this.items.length},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"name",{get:function(){return this._name},enumerable:!1,configurable:!0}),t}();Object.defineProperties(t.prototype,{dispatch:{value:t.prototype.emit},run:{value:t.prototype.emit}}),exports.Runner=t;
*/Object.defineProperty(exports,"__esModule",{value:!0});class s{constructor(e){this.items=[],this._name=e,this._aliasCount=0}emit(e,t,r,h,m,a,u,l){if(arguments.length>8)throw new Error("max arguments reached");const{name:o,items:i}=this;this._aliasCount++;for(let n=0,c=i.length;n<c;n++)i[n][o](e,t,r,h,m,a,u,l);return i===this.items&&this._aliasCount--,this}ensureNonAliasedItems(){this._aliasCount>0&&this.items.length>1&&(this._aliasCount=0,this.items=this.items.slice(0))}add(e){return e[this._name]&&(this.ensureNonAliasedItems(),this.remove(e),this.items.push(e)),this}remove(e){const t=this.items.indexOf(e);return t!==-1&&(this.ensureNonAliasedItems(),this.items.splice(t,1)),this}contains(e){return this.items.includes(e)}removeAll(){return this.ensureNonAliasedItems(),this.items.length=0,this}destroy(){this.removeAll(),this.items=null,this._name=null}get empty(){return this.items.length===0}get name(){return this._name}}Object.defineProperties(s.prototype,{dispatch:{value:s.prototype.emit},run:{value:s.prototype.emit}}),exports.Runner=s;
//# sourceMappingURL=runner.min.js.map
{
"name": "@pixi/runner",
"version": "6.5.3",
"version": "7.0.0-alpha",
"main": "dist/cjs/runner.js",
"module": "dist/esm/runner.mjs",
"bundle": "dist/browser/runner.js",
"types": "index.d.ts",

@@ -51,7 +50,6 @@ "exports": {

"files": [
"lib",
"dist",
"*.d.ts"
],
"gitHead": "28e6b2841a65837a5e2873a3d5a9c27cabbe795a"
"gitHead": "da993226df64b804a9c00ed9ee4d011191467b8a"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc