Dispatch

detroit_live.dispatch(*typenames: str) Dispatch

Creates a new dispatch for the specified event types. Each type is a string, such as "start" or "end".

Parameters:

typenames (str) – Typename value such as "start" or "end"

Returns:

Dispatch object

Return type:

Dispatch

class detroit_live.dispatch.dispatch.Dispatch(typenames: dict[str, list[tuple[str, Callable[[...], None]]]])
__call__(typename: str, *args: Any)

Invokes each registered callback for the specified type, passing the callback the specified arguments, with that as the this context.

Parameters:
  • typename (str) – Typename

  • args (Any) – Additional arguments passed to the callback function

on(typename: str, callback: Callable[[...], None] | None = None) Dispatch

Adds, removes or gets the callback for the specified typenames. If a callback function is specified, it is registered for the specified (fully-qualified) typenames. If a callback was already registered for the given typenames, the existing callback is removed before the new callback is added.

The specified typenames is a string, such as start or end.foo. The type may be optionally followed by a period (.) and a name; the optional name allows multiple callbacks to be registered to receive events of the same type, such as start.foo and start.bar. To specify multiple typenames, separate typenames with spaces, such as start end or start.foo start.bar.

To remove all callbacks for a given name foo, say dispatch.on(".foo", null).

If callback is not specified, returns the current callback for the specified typenames, if any. If multiple typenames are specified, the first matching callback is returned.

Parameters:
  • typename (str) – Typename value

  • callback (Callback | None) – Callback

Returns:

Itself

Return type:

Dispatch

parse_typenames(typenames: str) list[tuple[str, str]]
copy() Dispatch

Returns a copy of this dispatch object. Changes to this dispatch do not affect the returned copy and vice versa.

Returns:

Dispatch copy

Return type:

Dispatch