Observer
The Observer class allows for the construction of tables with observational capabilities.
Functions
new
Observer.
new
(
) →
{
[
any
]
:any
}
--
Returns a table with observational capabilities.
This function allows you to create a new observational table.
note
The returned data type is actually a userdata
. In order to performantly emit table read / write events, we need to use this setup.
local Observer = require(game:GetService("ReplicatedStorage"):WaitForChild("Commons")).Observer
local MyTable = Observer.new()
MyTable.onRead(function(key)
print("Someone read " .. key .. " from MyTable!")
end)
MyTable.abc = 123
print(MyTable.abc) -- Triggers the pre-defined onRead function
cleanup
Observer.
cleanup
(
proxy:
{
[
any
]
:any
}
--
The observational table you want to clean up.
) →
(
)
This function cleans up an observational table.
local Observer = require(game:GetService("ReplicatedStorage"):WaitForChild("Commons")).Observer
local MyTable = Observer.new()
MyTable.onRead(function(key)
print("Someone read " .. key .. " from MyTable!")
end)
MyTable.abc = 123
print(MyTable.abc) -- Triggers the pre-defined onRead function
Observer.cleanup(MyTable)