Module DruidEvent
Druid Event Module
The Event module provides a simple class for handling callbacks.
It is used in many Druid components.
You can subscribe to an event using the `:subscribe` method and unsubscribe using the `:unsubscribe` method.
Functions
clear(self) | Clear the all event handlers |
initialize(self[, initial_callback]) | DruidEvent constructor |
is_exist(self) | Return true, if event have at lease one handler |
subscribe(self, callback[, context]) | Subscribe callback on event |
trigger(self, ...) | Trigger the event and call all subscribed callbacks |
unsubscribe(self, callback[, context]) | Unsubscribe callback on event |
Functions
- clear(self)
-
Clear the all event handlers
Parameters:
- self DruidEvent DruidEvent
Usage:
button.on_long_click:clear()
- initialize(self[, initial_callback])
-
DruidEvent constructor
Parameters:
- self DruidEvent DruidEvent
- initial_callback function Subscribe the callback on new event, if callback exist (optional)
Usage:
local Event = require("druid.event") ... local event = Event(initial_callback)
- is_exist(self)
-
Return true, if event have at lease one handler
Parameters:
- self DruidEvent DruidEvent
Returns:
-
bool
True if event have handlers
Usage:
local is_long_click_handler_exists = button.on_long_click:is_exist()
- subscribe(self, callback[, context])
-
Subscribe callback on event
Parameters:
- self DruidEvent DruidEvent
- callback function Callback itself
- context Any Additional context as first param to callback call, usually it's self (optional)
Usage:
local function on_long_callback(self) print("Long click!") end ... local button = self.druid:new_button("button", callback) button.on_long_click:subscribe(on_long_callback, self)
- trigger(self, ...)
-
Trigger the event and call all subscribed callbacks
Parameters:
- self DruidEvent DruidEvent
- ... Any All event params
Usage:
local Event = require("druid.event") ... local event = Event() event:trigger("Param1", "Param2")
- unsubscribe(self, callback[, context])
-
Unsubscribe callback on event
Parameters:
- self DruidEvent DruidEvent
- callback function Callback itself
- context Any Additional context as first param to callback call (optional)
Usage:
local function on_long_callback(self) print("Long click!") end ... button.on_long_click:unsubscribe(on_long_callback, self)