# Class goog.events.ListenerMap

code »

Creates a new listener map.

## Constructor

goog.events.ListenerMap ( src )

Parameters

src: `(EventTarget|goog.events.Listenable)`
  The src object.

Show:Public Protected Private

## Instance Methods

code »add ( type, listener, callOnce, opt_useCapture, opt_listenerScope ) ⇒ `goog.events.ListenableKey`

Adds an event listener. A listener can only be added once to an object and if it is added again the key for the listener is returned. Note that a one-off listener will not change an existing listener, if any. On the other hand a normal listener will change existing one-off listener to become a normal listener.

Parameters

type: `(string|!goog.events.EventId)`
  The listener event type.
listener: `!Function`
  This listener callback method.
callOnce: `boolean`
  Whether the listener is a one-off listener.
opt_useCapture: `boolean=`
  The capture mode of the listener.
opt_listenerScope: `Object=`
  Object in whose scope to call the listener.

Returns

Unique key for the listener.

code »getListener ( type, listener, capture, opt_listenerScope ) ⇒ `goog.events.ListenableKey`

Gets the goog.events.ListenableKey for the event or null if no such listener is in use.

Parameters

type: `(string|!goog.events.EventId)`
  The type of the listener to retrieve.
listener: `!Function`
  The listener function to get.
capture: `boolean`
  Whether the listener is a capturing listener.
opt_listenerScope: `Object=`
  Object in whose scope to call the listener.

Returns

the found listener or null if not found.

code »getListenerCount ( ) ⇒ `number`

Returns

Total number of registered listeners.

code »getListeners ( type, capture ) ⇒ `!Array.<goog.events.ListenableKey>`

Gets all listeners that match the given type and capture mode. The returned array is a copy (but the listener objects are not).

Parameters

type: `(string|!goog.events.EventId)`
  The type of the listeners to retrieve.
capture: `boolean`
  The capture mode of the listeners to retrieve.

Returns

An array of matching listeners.

code »getTypeCount ( ) ⇒ `number`

Returns

The count of event types in this map that actually have registered listeners.

code »hasListener ( opt_type, opt_capture ) ⇒ `boolean`

Whether there is a matching listener. If either the type or capture parameters are unspecified, the function will match on the remaining criteria.

Parameters

opt_type: `(string|!goog.events.EventId)=`
  The type of the listener.
opt_capture: `boolean=`
  The capture mode of the listener.

Returns

Whether there is an active listener matching the requested type and/or capture phase.

code »remove ( type, listener, opt_useCapture, opt_listenerScope ) ⇒ `boolean`

Removes a matching listener.

Parameters

type: `(string|!goog.events.EventId)`
  The listener event type.
listener: `!Function`
  This listener callback method.
opt_useCapture: `boolean=`
  The capture mode of the listener.
opt_listenerScope: `Object=`
  Object in whose scope to call the listener.

Returns

Whether any listener was removed.

code »removeAll ( opt_type ) ⇒ `number`

Removes all listeners from this map. If opt_type is provided, only listeners that match the given type are removed.

Parameters

opt_type: `(string|!goog.events.EventId)=`
  Type of event to remove.

Returns

Number of listeners removed.

code »removeByKey ( listener ) ⇒ `boolean`

Removes the given listener object.

Parameters

listener: `goog.events.ListenableKey`
  The listener to remove.

Returns

Whether the listener is removed.

## Instance Properties

code »listeners : `Object.<string>`

Maps of event type to an array of listeners.

code »src : `(EventTarget|goog.events.Listenable)`
code »typeCount_ : `number`

The count of types in this map that have registered listeners.

## Static Functions

code »goog.events.ListenerMap.findListenerIndex_ ( listenerArray, listener, opt_useCapture, opt_listenerScope ) ⇒ `number`

Finds the index of a matching goog.events.Listener in the given listenerArray.

Parameters

listenerArray: `!Array`
  Array of listener.
listener: `!Function`
  The listener function.
opt_useCapture: `boolean=`
  The capture flag for the listener.
opt_listenerScope: `Object=`
  The listener scope.

Returns

The index of the matching listener within the listenerArray.