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
create(callback, callback_context) DruidEvent constructor
is_empty(self) Return true, if event not have handler
is_exist(self) Return true, if event have at lease one handler
is_subscribed(self, callback, callback_context) Check is event subscribed.
subscribe(self, callback, callback_context) Subscribe callback on event
trigger(self, ...) Trigger the event and call all subscribed callbacks
unsubscribe(self, callback, callback_context) Unsubscribe callback on event


Functions

clear(self)
Clear the all event handlers

Parameters:

Usage:

    button.on_long_click:clear()
create(callback, callback_context)
DruidEvent constructor

Parameters:

  • callback function or nil Subscribe the callback on new event, if callback exist
  • callback_context any or nil Additional context as first param to callback call

Usage:

    local Event = require("druid.event")
    ...
    local event = Event(callback)
is_empty(self)
Return true, if event not have handler

Parameters:

Returns:

    boolean True if event not have handlers

Usage:

    local is_long_click_handler_not_exists = button.on_long_click:is_empty()
is_exist(self)
Return true, if event have at lease one handler

Parameters:

Returns:

    boolean True if event have handlers

Usage:

    local is_long_click_handler_exists = button.on_long_click:is_exist()
is_subscribed(self, callback, callback_context)
Check is event subscribed.

Parameters:

  • self DruidEvent DruidEvent
  • callback function Callback itself
  • callback_context any or nil Additional context as first param to callback call

Returns:

    boolean, number|nil @Is event subscribed, return index of callback in event as second param
subscribe(self, callback, callback_context)
Subscribe callback on event

Parameters:

  • self DruidEvent DruidEvent
  • callback function Callback itself
  • callback_context any or nil Additional context as first param to callback call, usually it's self

Returns:

    boolean True if callback was subscribed

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, callback_context)
Unsubscribe callback on event

Parameters:

  • self DruidEvent DruidEvent
  • callback function Callback itself
  • callback_context any or nil Additional context as first param to callback call

Usage:

    local function on_long_callback(self)
        print("Long click!")
    end
    ...
    button.on_long_click:unsubscribe(on_long_callback, self)
generated by LDoc TESTING Last updated 2015-01-01 12:00:00