android-components / mozilla.components.concept.push / Bus

Bus

interface Bus<T, M> (source)

Interface for a basic bus that is implemented by MessageBus so that classes can observe particular event types.

    bus.register(Type.A, MyObservableClass())

    // In some other class, we can notify the MyObservableClass.
    bus.notifyObservers(Type.A, Message("Hello!"))

Parameters

T - A type that’s capable of describing message categories (e.g. an enum).

M - A type for holding message contents (e.g. data or sealed class).

Types

Name Summary
Observer interface Observer<T, M>
An observer interface that all listeners have to implement in order to register and receive events.

Functions

Name Summary
notifyObservers abstract fun notifyObservers(type: T, message: M): Unit
Notifies all registered observers of a particular message.
register abstract fun register(type: T, observer: Observer<T, M>): Unit
abstract fun register(type: T, observer: Observer<T, M>, owner: LifecycleOwner, autoPause: Boolean): Unit
Registers an observer to get notified about events.
unregister abstract fun unregister(type: T, observer: Observer<T, M>): Unit
Unregisters an observer to stop getting notified about events.

Extension Functions

Name Summary
loadResourceAsString fun Any.loadResourceAsString(path: String): String
Loads a file from the resources folder and returns its content as a string object.

Inheritors

Name Summary
MessageBus class MessageBus<T : Enum<T>, M> : Bus<T, M>
An implementation of Bus where the event type is restricted to an enum.