-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheventManager.lua
More file actions
56 lines (44 loc) · 1.83 KB
/
eventManager.lua
File metadata and controls
56 lines (44 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
local PATH = (...):match("^(.-)[^%.]+$")
local mintmousse = require(PATH .. "conf")
local codec = require(PATH .. "codec")
local proxy = require(PATH .. "proxy")
local log = mintmousse._logger:extend("Event")
local eventManager = {
eventCallbacks = { },
}
eventManager.onEvent = function(callbackID, callbackFunction)
if callbackFunction == nil then return end
log:assert(type(callbackID) == "string", "onEvent: callbackID expected to be type string! Received:", type(callbackID))
log:assert(type(callbackFunction) == "function", "onEvent: callbackFunction expected to be type function! Received:", type(callbackFunction))
eventManager.eventCallbacks[callbackID] = callbackFunction
end
eventManager.removeEvent = function(callbackID)
log:assert(type(callbackID) == "string", "removeEvent: callbackID expected to be type string! Received:", type(callbackID))
eventManager.eventCallbacks[callbackID] = nil
end
eventManager.jsEvent = function(callbackID, componentID, encodedSnapshot, values)
if type(callbackID) ~= "string" or type(componentID) ~= "string" or type(encodedSnapshot) ~= "string" then
log:warning("MintMousseJSEvent: expected three string arguments, instead received:", type(componentID), type(callbackID), type(encodedSnapshot))
return
end
local callbackFunction = eventManager.eventCallbacks[callbackID]
if not callbackFunction then
return
end
local component
if mintmousse.has(componentID) then
component = mintmousse.get(componentID)
else
local snapshot = codec.decode(encodedSnapshot)
component = proxy.createTempProxy(snapshot)
-- Temp components aren't added to the lookup for .has or .get
end
if type(values) == "table" then
local raw = rawget(component, "__raw")
for k, v in pairs(values) do
raw[k] = v
end
end
callbackFunction(component)
end
return eventManager