this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Changing return of hooks.lua from class table to global instance of Hooks class

+6 -5
+6 -5
hooks.lua
··· 1 - Hooks = class(function(self) 1 + hooks = class(function(self) 2 2 self.events = {} 3 3 end) 4 4 5 - function Hooks:on(event, callback) 5 + function hooks:on(event, callback) 6 6 if not self.events[event] then 7 7 self.events[event] = {} 8 8 end ··· 10 10 table.insert(self.events[event], callback) 11 11 end 12 12 13 - function Hooks:once(event, callback) 13 + function hooks:once(event, callback) 14 14 local wrapper 15 15 wrapper = function(...) 16 16 callback(...) ··· 20 20 self:on(event, wrapper) 21 21 end 22 22 23 - function Hooks:off(event, callback) 23 + function hooks:off(event, callback) 24 24 local list = self.events[event] 25 25 if not list then return end 26 26 for i, cb in ipairs(list) do ··· 31 31 end 32 32 end 33 33 34 - function Hooks:emit(event, ...) 34 + function hooks:emit(event, ...) 35 35 local list = self.events[event] 36 36 if not list then return end 37 37 for _, cb in ipairs(list) do ··· 39 39 end 40 40 end 41 41 42 + local Hooks = hooks() 42 43 return Hooks