Show:

Q.Event Class

Wraps a callable in a Q.Event object

Constructor

Q.Event

(
  • callable
  • [key=null]
  • [prepend=false]
)

Parameters:

  • callable Callable

    Optional. If not provided, the chain of handlers will start out empty. Any kind of callable which Q.handle can invoke

  • [key=null] String optional

    Optional key under which to add this, so you can remove it later if needed

  • [prepend=false] Boolean optional

    If true, then prepends the callable to the chain of handlers

Methods

add

(
  • handler
  • Optional
  • prepend
)
String | Null

Like the "set" method, adds a handler to an event, or overwrites an existing one. But in addition, immediately handles the handler if the event has already occurred at least once, or is currently occuring, passing it the same subject and arguments as were passed to the event the last time it occurred.

Parameters:

  • handler Mixed

    Any kind of callable which Q.handle can invoke

  • Optional String | Boolean | Q.Tool

    key to associate with the handler. Used to replace handlers previously added under the same key. Also used for removing handlers with .remove(key). If the key is not provided, a unique one is computed. Pass a Q.Tool object here to associate the handler to the tool, and it will be automatically removed when the tool is removed.

  • prepend Boolean

    If true, then prepends the handler to the chain

Returns:

String | Null:

The key under which the handler was set, or null if handler is empty

addOnce

(
  • handler
  • Optional
  • prepend
)
String

Like "add" method, but removes the handler right after it has executed.

Parameters:

  • handler Mixed

    Any kind of callable which Q.handle can invoke

  • Optional String | Boolean | Q.Tool

    key to associate with the handler. Used to replace handlers previously added under the same key. If the key is not provided, a unique one is computed. Pass a Q.Tool object here to associate the handler to the tool, and it will be automatically removed when the tool is removed.

  • prepend Boolean

    If true, then prepends the handler to the chain

Returns:

String:

The key under which the handler was set

and

(
  • anotherEvent
  • [key]
  • [anotherKey]
)
Q.Event

Return a new Q.Event that occurs whenever either this or anotherEvent occurs as long as both have occurred.

Parameters:

  • anotherEvent Q.Event

    The other event to check

  • [key] String | Boolean | Q.Tool optional

    Optional key to pass to this.add (see docs for that method).

  • [anotherKey] String | Boolean | Q.Tool optional

    Optional key to pass to anotherEvent.add (see docs for that method).

Returns:

Q.Event:

A new Q.Event object

copy

() Q.Event

Make a copy of this event, with all the keys and handlers

Returns:

debounce

(
  • milliseconds
  • [immediate=false]
  • [key]
)
Q.Event

Return a new Q.Event object that waits until after this event's handle() stops being called for a given number of milliseconds, before processing the last call. If the immediate param is true, the wrapper lets the function be called without waiting if it hasn't been called for the given number of milliseconds.

Parameters:

  • milliseconds Number

    The number of milliseconds

  • [immediate=false] Boolean optional

    if true, the wrapper lets the function be called without waiting if it hasn't been called for the given number of milliseconds.

  • [key] String | Boolean | Q.Tool optional

    Optional key to pass to event.add (see docs for that method).

Returns:

Q.Event:

A new Q.Event object

factory

(
  • [collection]
  • [defaults]
  • [callback]
  • [removeOnEmpty=false]
)
Function static

Make an event factory

Parameters:

  • [collection] Object optional

    The object that will store all the events. Pass null here to auto-create one.

  • [defaults] Array optional

    You can pass an array of defaults for the fields in the returned function The last element of this array can be a function that further processes the arguments, returning an array of the resulting arguments

  • [callback] Function optional

    An optional callback that gets called when a new event is created. The "this" object is the Q.Event, and the parameters are the processed parameters passed to the returned factory function. The callback should return the event to be added to the collection (could just return this).

  • [removeOnEmpty=false] Function optional

    Pass true here to remove events from the factory after their last handler is removed. They might be created again by the factory.

Returns:

Function:

Returns a function that can take one or more index fields and return a Q.Event that was either already stored under those index fields or newly created.

filter

(
  • test
  • [key]
)
Q.Event

Return a new Q.Event object that will call handle() when this event's handle() is called, but only if the test function returns true

Parameters:

  • test Function

    Function to test the arguments and return a Boolean

  • [key] String | Boolean | Q.Tool optional

    Optional key to pass to event.add (see docs for that method).

Returns:

Q.Event:

A new Q.Event object

from

(
  • key
  • source
  • eventName
)
Q.Event static

Returns a Q.Event that will fire given an DOM object and an event name

Parameters:

Returns:

handle

() Mixed

Shorthand closure for emitting events Pass any arguments to the event here. You can pass this closure anywhere a callback function is expected.

Returns:

Mixed:

map

(
  • transform
  • [key]
)
Q.Event

Return a new Q.Event object that will call handle() when this event's handle() is called, but with the arguments returned by the transform function

Parameters:

  • transform Function

    Function to transform the arguments and return an array of two items for the new call: [this, arguments]

  • [key] String | Boolean | Q.Tool optional

    Optional key to pass to event.add (see docs for that method).

Returns:

Q.Event:

A new Q.Event object

or

(
  • anotherEvent
  • [key]
  • [anotherKey]
)
Q.Event

Returns a new Q.Event that occurs whenever either this or anotherEvent occurs

Parameters:

  • anotherEvent Q.Event

    The other event to check

  • [key] String | Boolean | Q.Tool optional

    Optional key to pass to this event.add (see docs for that method).

  • [anotherKey] String | Boolean | Q.Tool optional

    Optional key to pass to anotherEvent.add (see docs for that method).

Returns:

queue

(
  • milliseconds
  • [key]
)
Q.Event

Return a new Q.Event object that will queue calls to this event's handle() method, to occur once every given milliseconds

Parameters:

  • milliseconds Number

    The number of milliseconds, can be 0

  • [key] String | Boolean | Q.Tool optional

    Optional key to pass to event.add (see docs for that method).

Returns:

Q.Event:

A new Q.Event object

remove

(
  • key
)

Removes an event handler

Parameters:

  • key String

    The key of the handler to remove. Pass a Q.Tool object here to remove the handler, if any, associated with this tool.

removeAllHandlers

(
  • key
)

Removes all handlers for this event

Parameters:

  • key String

    The key of the handler to remove. Pass a Q.Tool object here to remove the handler, if any, associated with this tool.

set

(
  • handler
  • key
  • prepend
)
String | Null

Adds a handler to an event, or overwrites an existing one

Parameters:

  • handler Mixed

    Any kind of callable which Q.handle can invoke

  • key String | Boolean | Q.Tool

    Optional key to associate with the handler. Used to replace handlers previously added under the same key. Also used for removing handlers with .remove(key). If the key is not provided, a unique one is computed. Pass true here to associate the handler to the current page, and it will be automatically removed when the current page is removed. Pass a Q.Tool object here to associate the handler to the tool, and it will be automatically removed when the tool is removed.

  • prepend Boolean

    If true, then prepends the handler to the chain

Returns:

String | Null:

The key under which the handler was set, or null if handler is empty

setOnce

(
  • handler
  • Optional
  • prepend
)
String

Like "set" method, but removes the handler right after it has executed.

Parameters:

  • handler Mixed

    Any kind of callable which Q.handle can invoke

  • Optional String | Boolean | Q.Tool

    key to associate with the handler. Used to replace handlers previously added under the same key. If the key is not provided, a unique one is computed. Pass a Q.Tool object here to associate the handler to the tool, and it will be automatically removed when the tool is removed.

  • prepend Boolean

    If true, then prepends the handler to the chain

Returns:

String:

The key under which the handler was set

stop

(
  • removeAllHandlers
)

Indicates that the event won't be firing anymore

Parameters:

  • removeAllHandlers Boolean

    If true, then also removes all the handlers added to this event

then

(
  • [key]
)
Q.Event

Return a new Q.Event object that waits until this event is stopped, then processes all the pending calls to .handle(), continuing normally after that.

Parameters:

  • [key] String | Boolean | Q.Tool optional

    Optional key to pass to event.onStop().add (see docs for that method).

Returns:

Q.Event:

A new Q.Event object

throttle

(
  • milliseconds
  • delayedFinal
  • [key]
)
Q.Event

Return a new Q.Event object that will call handle() when this event's handle() is called, but only at most every given milliseconds.

Parameters:

  • milliseconds Number

    The number of milliseconds

  • delayedFinal Boolean

    Whether the wrapper should execute the latest function call after throttle opens again, useful for e.g. following a mouse pointer that stopped.

  • [key] String | Boolean | Q.Tool optional

    Optional key to pass to event.add (see docs for that method).

Returns:

Q.Event:

A new Q.Event object

until

(
  • anotherEvent
  • [key]
  • [anotherKey]
)
Q.Event

Return a new Q.Event object that is handled whenever this event is handled, until anotherEvent occurs, in which case this event occurs one final time.

Parameters:

  • anotherEvent Q.Event

    An event whose occurrence will stop the returned event

  • [key] String | Boolean | Q.Tool optional

    Optional key to pass to this.add (see docs for that method).

  • [anotherKey] String | Boolean | Q.Tool optional

    Optional key to pass to anotherEvent.add (see docs for that method).

Returns:

Q.Event:

A new Q.Event object