CanBeState type since v0.2 ¶
A value which may either be a state object or a constant.
Provided as a convenient shorthand for indicating that constant-ness is not important.
StateObject<T> | T
Example Usage¶
local function printItem(item: CanBeState<string>)
if typeof(item) == "string" then
-- constant
print("Got constant: ", item)
else
-- state object
print("Got state object: ", item:get())
end
end
local constant = "Hello"
local state = Value("World")
printItem(constant) --> Got constant: Hello
printItem(state) --> Got state object: World