BlocklyEvent

@objcMembers open class BlocklyEvent: NSObject

Base class for all Blockly events.

  • Data type used for specifying a type of BlocklyEvent.

    Declaration

    Swift

    public typealias EventType = String
  • The type of this event.

    Declaration

    Swift

    open let type: EventType
  • The ID for the workspace that triggered this event.

    Declaration

    Swift

    open let workspaceID: String
  • The ID for the group of related events.

    Declaration

    Swift

    open var groupID: String?
  • The ID of the primary or root affected block.

    Declaration

    Swift

    open let blockID: String?
  • Creates a BlocklyEvent.

    Declaration

    Swift

    public init(type: EventType, workspaceID: String, groupID: String?, blockID: String?)
  • Constructs a BlocklyEvent with base attributes assigned from JSON.

    Throws

    BlocklyError: Thrown if BlocklyEvent.JSON_WORKSPACE_ID is not specified as a key within the given json.

    Declaration

    Swift

    public init(type: EventType, json: [String: Any]) throws
  • Returns a JSON dictionary serialization of the event.

    Throws

    BlocklyError: Thrown if the event could not be serialized.

    Declaration

    Swift

    open func toJSON() throws -> [String: Any]

    Return Value

    A JSON dictionary serialization of the event.

  • Calls self.toJSON() and returns a string representation of that JSON dictionary.

    Throws

    BlocklyError: Thrown if the event could not be serialized.

    Declaration

    Swift

    public final func toJSONString() throws -> String

    Return Value

    A JSON string representation of the event.

  • This method indicates if this event can be discarded so it doesn’t get fired. An example of when this might be true is for a BlocklyEvent.Change where no change is recorded between old and new values.

    The default implementation of this method returns false. Subclasses may override this method to specify individual behavior of when the event can be discarded, based on its current state.

    Declaration

    Swift

    open func isDiscardable() -> Bool

    Return Value

    true if this event can be discarded, or false otherwise.

  • Attempts to merge this event with the next chronological event that was fired, and returns the result. If the events are incompatible and cannot be merged, nil is returned.

    The default implementation of this method returns nil. Subclasses may override this method to specify individual merge behavior with other events.

    Declaration

    Swift

    open func merged(withNextChronologicalEvent event: BlocklyEvent) -> BlocklyEvent?

    Return Value

    If the events are compatible, this returns a new BlocklyEvent that is the result of merging the two events together. Otherwise, nil is returned.

  • Event fired when a property of a block changes.

    Declaration

    Swift

    @objcMembers public final class Change: BlocklyEvent
  • Event fired when a block is removed from the workspace.

    Declaration

    Swift

    @objcMembers public final class Delete: BlocklyEvent
  • UI

    Event class for user interface related actions, including selecting blocks, opening/closing the toolbox or trash, and changing toolbox categories.

    Declaration

    Swift

    @objcMembers public final class UI: BlocklyEvent
  • Event fired when a block is added to the workspace, possibly containing other child blocks and next blocks.

    Declaration

    Swift

    @objcMembers public final class Create: BlocklyEvent
  • Event fired when a block is moved on the workspace, or its parent connection is changed.

    This event must be created before the block is moved to capture the original position. After the move has been completed in the workspace, capture the updated position or parent using recordNew(forBlock:).

    Declaration

    Swift

    @objcMembers public final class Move: BlocklyEvent