mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Renamed class functions
This commit is contained in:
@@ -4,13 +4,13 @@
|
||||
local class = require("druid.system.middleclass")
|
||||
|
||||
-- @class DruidEvent
|
||||
local M = class("druid.event")
|
||||
local Event = class("druid.event")
|
||||
|
||||
|
||||
--- Event constructur
|
||||
-- @function Event
|
||||
-- @tparam function initial_callback Subscribe the callback on new event, if callback exist
|
||||
function M.initialize(self, initial_callback)
|
||||
function Event:initialize(initial_callback)
|
||||
self._callbacks = {}
|
||||
|
||||
if initial_callback then
|
||||
@@ -22,7 +22,7 @@ end
|
||||
--- Subscribe callback on event
|
||||
-- @function event:subscribe
|
||||
-- @tparam function callback Callback itself
|
||||
function M.subscribe(self, callback)
|
||||
function Event:subscribe(callback)
|
||||
assert(type(self) == "table", "You should subscribe to event with : syntax")
|
||||
assert(type(callback) == "function", "Callback should be function")
|
||||
|
||||
@@ -35,7 +35,7 @@ end
|
||||
--- Unsubscribe callback on event
|
||||
-- @function event:unsubscribe
|
||||
-- @tparam function callback Callback itself
|
||||
function M.unsubscribe(self, callback)
|
||||
function Event:unsubscribe(callback)
|
||||
for i = 1, #self._callbacks do
|
||||
if self._callbacks[i] == callback then
|
||||
table.remove(self._callbacks, i)
|
||||
@@ -48,14 +48,14 @@ end
|
||||
--- Return true, if event have at lease one handler
|
||||
-- @function event:is_exist
|
||||
-- @treturn bool True if event have handlers
|
||||
function M.is_exist(self)
|
||||
function Event:is_exist()
|
||||
return #self._callbacks > 0
|
||||
end
|
||||
|
||||
|
||||
--- Clear the all event handlers
|
||||
-- @function event:clear
|
||||
function M.clear(self)
|
||||
function Event:clear()
|
||||
self._callbacks = {}
|
||||
end
|
||||
|
||||
@@ -63,11 +63,11 @@ end
|
||||
--- Trigger the event and call all subscribed callbacks
|
||||
-- @function event:trigger
|
||||
-- @param ... All event params
|
||||
function M.trigger(self, ...)
|
||||
function Event:trigger(...)
|
||||
for i = 1, #self._callbacks do
|
||||
self._callbacks[i](...)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return M
|
||||
return Event
|
||||
|
Reference in New Issue
Block a user