LibRockEvent-1.0

From WowAce Wiki
Jump to: navigation, search

API Documentation

Note: This documentation is auto-generated. Please note that direct modifications may be overwritten on next autogenerate. string or function number

:AddEventListener("namespace" , eventName [, callback] [, bucketDelay] [, ...])

Arguments

"namespace"
string - the namespace, could be "Blizzard" or the name of a library or addon. Optional, default: "Blizzard"
eventName
string or table - the name of the event or a table containing a set of events.
callback
string or function - the callback (method name or function) to call. Default: "eventName",
bucketDelay
number - if a number is provided, the bucketing delay. Default: nil
...
tuple - a list of arguments to pass into the start of the callback.

Notes

  • adds a listener for an event specified by the "namespace"/"eventName" pair.
  • to register for a Blizzard event, specify namespace as "Blizzard"
  • Along with the normal arguments passed into the callback, the "namespace" and "eventName" are passed in.
  • Bucketed events can be handled by setting the bucketDelay argument to a number, which is the amount of time to bucket events by. Bucket events will take the first argument passed in and store it in a set. If the set is non-empty by the time the specified delay is up, the callback will be called, passing along the set.
  • It is recommended to only use the multiple event system when using buckets.
  • If you wish to listen to events triggered by AceEvent-2.0, specify the namespace "AceEvent-2.0". e.g. "AceEvent-2.0", "SharedMedia_Registered".

Example

MyAddon.PLAYER_LOGIN = function(self, namespace, event)
	-- do something here.
end
MyAddon:AddEventListener("PLAYER_LOGIN") -- same as :AddEventListener("Blizzard", "PLAYER_LOGIN")
MyAddon.ADDON_LOADED = function(self, value, namespace, event)
	assert(value == 50)
end
MyAddon:AddEventListener("ADDON_LOADED", nil, nil, 50)
-- buckets:
MyAddon.SomeEvent = function(self, namespace, event, data)
end
MyAddon:AddEventListener("MyAddon", "SomeEvent", nil, 1) -- bucketing by every second.
MyAddon:DispatchEvent("SomeEvent", "alpha")
-- half second later
MyAddon:DispatchEvent("SomeEvent", "bravo")
-- once the second has passed, MyAddon:SomeEvent("MyAddon", "SomeEvent", { ["alpha"] = true, ["bravo"] = true }) will be called.
-- multiple events:
MyAddon.Handler = function(self, namespace, event)
	-- will receive SomeEvent and SomeOtherEvent
end
MyAddon:AddEventListener("SomeNamespace", { SomeEvent = true, SomeOtherEvent = true}, "Handler")

:DispatchEvent("eventName" , ...)

Arguments

"eventName"
string - the name of the event.
...
tuple - list of arguments to pass.

Notes

  • dispatch an event, causing all addons which have registered for the event to have their callbacks called.
  • events should be in the form of PascalCase. Only Blizzard's events should be in CONSTANT_CASE
  • events are passed with the namespace as specified by object.name

Example

MyAddon:DispatchEvent("Kersplosion") -- dispatches "MyAddon","Kersplosion"

:DispatchNamespaceEvent("namespace" , "eventName" , ...)

Arguments

"namespace"
string - the namespace.
"eventName"
string - the name of the event.
...
tuple - list of arguments to pass.

Notes

  • dispatches an event with the specified namespace, causing all addons which have registered for the event to have their callbacks called.
  • events should be in the form of PascalCase. Only Blizzard's events should be in CONSTANT_CASE
  • events are passed with the namespace as specified by object.name
  • this is for special cases only, e.g. debugging. It is highly recommended that :DispatchEvent is used instead.

Example

Rock("LibRockEvent-1.0"):DispatchNamespaceEvent("MyAddon", "Kersplosion") -- dispatches "MyAddon","Kersplosion"

:HasEventListener("namespace" , "eventName")

Arguments

"namespace"
string - the namespace. Optional, default: "Blizzard"
"eventName"
string - the name of the event.

Returns

boolean or function or string - false if not registered, otherwise the callback that the event is registered to. Note: if this is called on LibRockEvent-1.0 itself, it will only return true/false.

Example

local has = MyAddon:HasEventListener("PLAYER_LOGIN") -- same as :HasEventListener("Blizzard", "PLAYER_LOGIN")
local has = MyAddon:HasEventListener("MyAddon", "Kersplosion")

:IsFullyInitialized()

Notes

  • The event "LibEvent-1.0","FullyInitialized" will be dispatched when the UI has fully initialized.
  • Fully initialized means that it is post-PLAYER_LOGIN and all chat channels have been properly joined, which has no corresponding Blizzard event.

Returns

boolean - whether the UI has fully initialized

Example

local init = Rock("LibRockEvent-1.0"):IsFullyInitialized()

string

:RemoveAllEventListeners([namespace])

Arguments

namespace
string - the namespace, could be "Blizzard" or the name of a library or addon. Default: all namespaces

Notes

  • remove all event listener for the specified namespace or for all namespaces.

Example

MyAddon:RemoveAllEventListeners()

:RemoveEventListener("namespace" , "eventName")

Arguments

"namespace"
string - the namespace, could be "Blizzard" or the name of a library or addon. Optional, default: "Blizzard"
"eventName"
string - the name of the event.

Notes

  • remove the event listener for the specified "namespace"/"eventName" pair.

Returns

boolean - whether the event actually was removed.

Example

MyAddon:RemoveEventListener("PLAYER_LOGIN") -- same as :RemoveEventListener("Blizzard", "PLAYER_LOGIN")