phaser/src/events/EventEmitter.js

179 lines
4.2 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../utils/Class');
var EE = require('eventemitter3');
var PluginCache = require('../plugins/PluginCache');
2018-02-07 15:27:21 +00:00
/**
* @classdesc
* EventEmitter is a Scene Systems plugin compatible version of eventemitter3.
*
* @class EventEmitter
2018-10-10 09:49:13 +00:00
* @memberof Phaser.Events
2018-02-07 15:27:21 +00:00
* @constructor
* @since 3.0.0
*/
var EventEmitter = new Class({
Extends: EE,
initialize:
function EventEmitter ()
{
EE.call(this);
2018-01-18 05:19:00 +00:00
},
2018-01-26 03:40:49 +00:00
/**
* Removes all listeners.
*
* @method Phaser.Events.EventEmitter#shutdown
* @since 3.0.0
*/
2018-01-18 05:19:00 +00:00
shutdown: function ()
{
this.removeAllListeners();
},
2018-01-26 03:40:49 +00:00
/**
* Removes all listeners.
*
* @method Phaser.Events.EventEmitter#destroy
* @since 3.0.0
*/
2018-01-18 05:19:00 +00:00
destroy: function ()
{
this.removeAllListeners();
}
});
2018-02-13 00:40:51 +00:00
/**
* Return an array listing the events for which the emitter has registered listeners.
*
2018-03-21 14:09:58 +00:00
* @method Phaser.Events.EventEmitter#eventNames
2018-03-15 17:27:30 +00:00
* @since 3.0.0
2018-03-20 14:58:02 +00:00
*
2018-02-13 00:40:51 +00:00
* @return {array}
*/
/**
* Return the listeners registered for a given event.
*
2018-03-21 14:09:58 +00:00
* @method Phaser.Events.EventEmitter#listeners
2018-03-15 17:27:30 +00:00
* @since 3.0.0
2018-03-20 14:58:02 +00:00
*
* @param {(string|symbol)} event - The event name.
*
2018-02-13 00:40:51 +00:00
* @return {array} The registered listeners.
*/
/**
* Return the number of listeners listening to a given event.
2018-03-20 14:58:02 +00:00
*
2018-03-21 14:09:58 +00:00
* @method Phaser.Events.EventEmitter#listenerCount
2018-03-15 17:27:30 +00:00
* @since 3.0.0
2018-02-13 00:40:51 +00:00
*
2018-03-20 14:58:02 +00:00
* @param {(string|symbol)} event - The event name.
*
2018-02-13 00:40:51 +00:00
* @return {number} The number of listeners.
*/
/**
* Calls each of the listeners registered for a given event.
*
2018-03-21 14:09:58 +00:00
* @method Phaser.Events.EventEmitter#emit
2018-03-15 17:27:30 +00:00
* @since 3.0.0
2018-03-20 14:58:02 +00:00
*
* @param {(string|symbol)} event - The event name.
* @param {...*} [args] - Additional arguments that will be passed to the event handler.
2018-03-20 14:58:02 +00:00
*
2018-03-19 17:05:29 +00:00
* @return {boolean} `true` if the event had listeners, else `false`.
2018-02-13 00:40:51 +00:00
*/
/**
* Add a listener for a given event.
*
2018-03-21 14:09:58 +00:00
* @method Phaser.Events.EventEmitter#on
2018-03-15 17:27:30 +00:00
* @since 3.0.0
2018-03-20 14:58:02 +00:00
*
* @param {(string|symbol)} event - The event name.
2018-02-13 00:40:51 +00:00
* @param {function} fn - The listener function.
* @param {*} [context=this] - The context to invoke the listener with.
2018-03-20 14:58:02 +00:00
*
2018-03-21 14:09:58 +00:00
* @return {Phaser.Events.EventEmitter} `this`.
2018-02-13 00:40:51 +00:00
*/
/**
* Add a listener for a given event.
*
2018-03-21 14:09:58 +00:00
* @method Phaser.Events.EventEmitter#addListener
2018-03-15 17:27:30 +00:00
* @since 3.0.0
2018-03-20 14:58:02 +00:00
*
* @param {(string|symbol)} event - The event name.
2018-02-13 00:40:51 +00:00
* @param {function} fn - The listener function.
* @param {*} [context=this] - The context to invoke the listener with.
2018-03-20 14:58:02 +00:00
*
2018-03-21 14:09:58 +00:00
* @return {Phaser.Events.EventEmitter} `this`.
2018-02-13 00:40:51 +00:00
*/
/**
* Add a one-time listener for a given event.
*
2018-03-21 14:09:58 +00:00
* @method Phaser.Events.EventEmitter#once
2018-03-15 17:27:30 +00:00
* @since 3.0.0
2018-03-20 14:58:02 +00:00
*
* @param {(string|symbol)} event - The event name.
2018-02-13 00:40:51 +00:00
* @param {function} fn - The listener function.
* @param {*} [context=this] - The context to invoke the listener with.
2018-03-20 14:58:02 +00:00
*
2018-03-21 14:09:58 +00:00
* @return {Phaser.Events.EventEmitter} `this`.
2018-02-13 00:40:51 +00:00
*/
/**
* Remove the listeners of a given event.
*
2018-03-21 14:09:58 +00:00
* @method Phaser.Events.EventEmitter#removeListener
2018-03-15 17:27:30 +00:00
* @since 3.0.0
2018-03-20 14:58:02 +00:00
*
* @param {(string|symbol)} event - The event name.
2018-02-13 00:40:51 +00:00
* @param {function} fn - Only remove the listeners that match this function.
* @param {*} context - Only remove the listeners that have this context.
* @param {boolean} once - Only remove one-time listeners.
2018-03-20 14:58:02 +00:00
*
2018-03-21 14:09:58 +00:00
* @return {Phaser.Events.EventEmitter} `this`.
2018-02-13 00:40:51 +00:00
*/
/**
* Remove the listeners of a given event.
*
2018-03-21 14:09:58 +00:00
* @method Phaser.Events.EventEmitter#off
2018-03-15 17:27:30 +00:00
* @since 3.0.0
2018-03-20 14:58:02 +00:00
*
* @param {(string|symbol)} event - The event name.
2018-02-13 00:40:51 +00:00
* @param {function} fn - Only remove the listeners that match this function.
* @param {*} context - Only remove the listeners that have this context.
* @param {boolean} once - Only remove one-time listeners.
2018-03-20 14:58:02 +00:00
*
2018-03-21 14:09:58 +00:00
* @return {Phaser.Events.EventEmitter} `this`.
2018-02-13 00:40:51 +00:00
*/
/**
* Remove all listeners, or those of the specified event.
*
2018-03-21 14:09:58 +00:00
* @method Phaser.Events.EventEmitter#removeAllListeners
2018-03-15 17:27:30 +00:00
* @since 3.0.0
2018-03-20 14:58:02 +00:00
*
* @param {(string|symbol)} [event] - The event name.
*
2018-03-21 14:09:58 +00:00
* @return {Phaser.Events.EventEmitter} `this`.
2018-02-13 00:40:51 +00:00
*/
PluginCache.register('EventEmitter', EventEmitter, 'events');
2018-01-18 05:19:00 +00:00
module.exports = EventEmitter;