Namespace: bitbucket/util/events

bitbucket/util/events

Provides methods for handling events fired by Bitbucket Server, and for triggering your own events.

This module is available synchronously.

Web Resource: com.atlassian.bitbucket.server.bitbucket-web-api:events

Source:

Classes

EventChain

Methods

<static> chain() → {bitbucket/util/events.EventChain}

Creates an event object that tracks all listeners and provides a convenience function bitbucket/util/events.EventChain#destroy
that will stop listening to all events in the chain, rather than manually having to call bitbucket/util/events.off
again.

Source:
Returns:
Type
bitbucket/util/events.EventChain
Example
var chain = events.chain().on('a', callback).on('b', callback);
    ...
    chain.destroy();

<static> chainWith(that) → {bitbucket/util/events.EventChain}

Works exactly like bitbucket/util/events.chain, but allows you to specify your own
event producer to attach and detach listeners on. The event producer must conform to the
bitbucket/util/events.EventProducer interface.

Parameters:
Name Type Description
that bitbucket/util/events.EventProducer

An object on which to attach/detach event listeners.

Source:
Returns:
Type
bitbucket/util/events.EventChain
Example
var chain = events.chainWith($('.something')).on('a', callback).on('b', callback);
    ...
    chain.destroy();

<static> listeners(eventName) → {Array.<function()>}

Return all handlers that would be triggered when an event is fired.

Parameters:
Name Type Description
eventName string

The name of the event to return handlers for.

Source:
Returns:
  • An array of handler functions.
Type
Array.<function()>

<static> name(subname) → {string|boolean}

Determine the current event name or whether the current event name includes a specific sub-name.

Parameters:
Name Type Argument Description
subname string <optional>

The sub-name to search for in the current event name (optional).

Source:
Returns:

Either returns the name of the currently firing event, or if a sub-name is passed in
it instead returns whether this event includes that sub-name.

Type
string | boolean

<static> off(eventName, fn)

Stop calling a function when an event is fired. The function is assumed to have previously been passed to
.on or .once

Parameters:
Name Type Description
eventName string

The name of the event to stop handling. This should be a '.'-delimited namespace.
You can replace any component of the namespace with a '*' for wildcard matching.

fn function

The handler function to stop calling when the event is fired.

Source:

<static> on(eventName, fn)

Call a function every time an event is fired.

Parameters:
Name Type Description
eventName string

The name of the event to handle. This should be a '.'-delimited namespace.
You can replace any component of the namespace with a '*' for wildcard matching.

fn function

The handler function to call when the event is fired.

Source:

<static> once(eventName, fn)

Call a function the first time an event is fired.

Parameters:
Name Type Description
eventName string

The name of the event to handle once. This should be a '.'-delimited namespace.
You can replace any component of the namespace with a '*' for wildcard matching.

fn function

The handler function to call the first time the event is fired.

Source:

<static> trigger(eventName, context)

Trigger a global event.

Parameters:
Name Type Description
eventName string

The name of the event to fire. This should be a '.'-delimited namespace.

context Object

The context to fire the event with. Handlers will be called with the context as this.
Any further params will be used as arguments to the handlers.

Source:

Type Definitions

EventProducer

An interface for objects that accept event handlers. Used with bitbucket/util/events.chainWith.

Type:
  • Object
Properties:
Name Type Description
on bitbucket/util/events.EventProducerOn

Accept an event listener who will be called when an event occurs.

off bitbucket/util/events.EventProducerOff

Detach an event listener who will no longer be called when an event occurs.

Source:

EventProducerOff(eventName, eventListener)

Parameters:
Name Type Description
eventName string

The type of event to detach the listener from.

eventListener function

The listener to detach.

Source:

EventProducerOn(eventName, eventListener)

Parameters:
Name Type Description
eventName string

The type of event to attach the listener to.

eventListener function

The listener to attach.

Source: