mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 07:26:02 +01:00
refactor(callbacks): remove the cb argument
BREAKING CHANGE: Registered callbacks now return values rather than sending them as a callback. Previously the cb needed to be called to return to the client, now it will happen once the function closes. i.e. cb(string, string, false) -> return string, string, false
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
local ServerCallback = {}
|
||||
|
||||
---@param name string
|
||||
---@param callback function
|
||||
--- Registers an event handler and callback function to respond to client requests.
|
||||
ServerCallback.Register = function(name, callback)
|
||||
name = ('__cb_%s:%s'):format(GetCurrentResourceName(), name)
|
||||
---@param name string
|
||||
---@param callback function
|
||||
--- Registers an event handler and callback function to respond to client requests.
|
||||
ServerCallback.Register = function(name, callback)
|
||||
name = ('__cb_%s:%s'):format(GetCurrentResourceName(), name)
|
||||
|
||||
RegisterServerEvent(name, function(id, ...)
|
||||
local source = source
|
||||
callback(source, function(...)
|
||||
TriggerClientEvent(name..id, source, ...)
|
||||
end, ...)
|
||||
end)
|
||||
end
|
||||
RegisterServerEvent(name, function(id, ...)
|
||||
TriggerClientEvent(name..id, source, {callback(source, ...)})
|
||||
end)
|
||||
end
|
||||
|
||||
return ServerCallback
|
||||
Reference in New Issue
Block a user