HubCategory

final public class HubCategory : Category
extension HubCategory: HubCategoryBehavior
extension HubCategory: DefaultLogger
extension HubCategory: Resettable

Amplify has a local eventing system called Hub. It is a lightweight implementation of Publisher-Subscriber pattern, and is used to share data between modules and components in your app. Hub enables different categories to communicate with one another when specific events occur, such as authentication events like a user sign-in or notification of a file download.

Plugin handling

  • Adds plugin to the list of Plugins that implement functionality for this category.

    The default plugin that is assigned at initialization will function without an explicit call to configure. However, adding a plugin removes the default plugin, and will also cause the Hub category to require configure be invoked before using any logging APIs.

    Note: It is a programmer error to use Amplify.Hub APIs during the initialization and configuration phases of a custom Hub category plugin.

    Declaration

    Swift

    public func add(plugin: HubCategoryPlugin) throws

    Parameters

    plugin

    The Plugin to add

  • Returns the added plugin with the specified key property.

    Declaration

    Swift

    public func getPlugin(for key: PluginKey) throws -> HubCategoryPlugin

    Parameters

    key

    The PluginKey (String) of the plugin to retrieve

    Return Value

    The wrapped plugin

  • Removes the plugin registered for key from the list of Plugins that implement functionality for this category. If no plugin has been added for key, no action is taken, making this method safe to call multiple times.

    Declaration

    Swift

    public func removePlugin(for key: PluginKey)

    Parameters

    key

    The key used to add the plugin

  • Declaration

    Swift

    public func dispatch(to channel: HubChannel, payload: HubPayload)
  • Declaration

    Swift

    public func listen(to channel: HubChannel,
                       eventName: HubPayloadEventName,
                       listener: @escaping HubListener) -> UnsubscribeToken
  • Declaration

    Swift

    public func listen(to channel: HubChannel,
                       isIncluded filter: HubFilter? = nil,
                       listener: @escaping HubListener) -> UnsubscribeToken
  • Declaration

    Swift

    public func removeListener(_ token: UnsubscribeToken)
  • log

    Declaration

    Swift

    public static var log: Logger { get }
  • log

    Declaration

    Swift

    public var log: Logger { get }
  • reset() Asynchronous

    Declaration

    Swift

    public func reset() async
  • Convenience method to allow callers to listen to Hub events for a particular operation. Internally, the listener transforms the HubPayload into the Operation’s expected OperationResult type, so callers may re-use their listeners

    Declaration

    Swift

    func listenForResult<Request: AmplifyOperationRequest, Success, Failure: AmplifyError>(
        to operation: AmplifyOperation<Request, Success, Failure>,
        resultListener: @escaping AmplifyOperation<Request, Success, Failure>.ResultListener
    ) -> UnsubscribeToken

    Parameters

    operation

    The operation to monitor for results

    resultListener

    The Operation-specific listener callback to be invoked when an OperationResult for that operation is received.

  • Convenience method to allow callers to listen to Hub in-process events for a particular operation. Internally, the listener transforms the HubPayload into the Operation’s expected InProcess type, so callers may re-use their listeners.

    Declaration

    Swift

    func listenForInProcess<Request: AmplifyOperationRequest, InProcess, Success, Failure: AmplifyError>(
        to operation: AmplifyInProcessReportingOperation<Request, InProcess, Success, Failure>,
        inProcessListener: @escaping AmplifyInProcessReportingOperation<
        Request, InProcess, Success, Failure>.InProcessListener
    ) -> UnsubscribeToken

    Parameters

    operation

    The progress reporting operation monitor for progress and results

    inProcessListener

    The ProgressListener callback to be invoked when the operation emits an in-process value