EventManager

@objcMembers public final class EventManager: NSObject

Manages the use of events across Blockly.

This class is designed as a singleton instance, accessible via EventManager.shared.

Note

This class is not thread-safe and should only be accessed from the main thread.
  • Shared instance.

    Declaration

    Swift

    public static let shared = EventManager()
  • Sequential list of events queued up for firing.

    Declaration

    Swift

    public private(set) var pendingEvents = [BlocklyEvent]()
  • Flag that determines if the event manager is allowing any new events to be queued via addPendingEvent(:). Defaults to true.

    Declaration

    Swift

    public var isEnabled: Bool = true
  • The current group ID that is automatically assigned to new events with no group ID.

    Declaration

    Swift

    public private(set) var currentGroupID: String?
  • Queues an event to be fired in the future (via firePendingEvents()). However, this event will not be queued if self.isEnabled is set to false, or if the event is discardable.

    If event.groupID is nil, it is automatically assigned the value of self.currentGroupID, by this method.

    Declaration

    Swift

    public func addPendingEvent(_ event: BlocklyEvent)
  • Fires all pending events.

    Declaration

    Swift

    public func firePendingEvents()
  • Generates a group UUID and pushes this new group ID to the group stack, effectively setting it to self.currentGroupID. Each new pending event will automatically be assigned to this group ID, if it is not already assigned to a group ID.

    Every call to pushNewGroup() needs to be balanced by a future call to popGroup().

    Note

    It is not recommended to push a new group ID if self.currentGroupID is not nil. Doing this will result in an error in debug mode and a warning in release mode.

    Declaration

    Swift

    public func pushNewGroup()
  • Pushes a given group ID to the group stack, effectively setting it to self.currentGroupID. Each new pending event will automatically be assigned to this group ID, if it is not already assigned to a group ID.

    Every call to pushGroup(groupID:) needs to be balanced by a future call to popGroup().

    Note

    It is not recommended to push a group ID that differs from self.currentGroupID, if it is not nil. Doing this will result in an error in debug mode and a warning in release mode.

    Declaration

    Swift

    public func pushGroup(groupID: String)
  • Pops the current group ID from the group stack.

    If the group stack is not empty, self.currentGroupID is assigned to the previously pushed group ID. If the group stack is empty, self.currentGroupID is assigned to nil.

    Each new pending event will automatically be assigned to the new value of self.currentGroupID, if it is not already assigned to a group ID.

    Declaration

    Swift

    public func popGroup()
  • Convenience method that starts a new group, executes a given closure, stops the group, and then fires all pending events.

    Note

    This method guarantees a group is started, stopped, and all pending events are fired, regardless if the given closure throws an error.

    Declaration

    Swift

    public func groupAndFireEvents(
        groupID: String? = nil, forClosure closure: () throws -> Void) rethrows