Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/attributeutils/src/Shared/AttributeValue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ function AttributeValue.Observe<T>(self: AttributeValue<T>): Observable.Observab
return RxAttributeUtils.observeAttribute(self._object, self._attributeName, rawget(self :: any, "_defaultValue"))
end

--[=[
Allows you to set a value, and returns a clean up that resets to default value

@param value T
@return () -> () -- Cleanup
]=]
function AttributeValue.SetValue<T>(self: AttributeValue<T>, value: T)
self._object:SetAttribute(rawget(self :: any, "_attributeName"), value)

return function()
if self.Value == value then
self._object:SetAttribute(rawget(self :: any, "_attributeName"), rawget(self :: any, "_defaultValue"))
end
end
end

--[=[
The current property of the Attribute. Can be assigned to to write
the attribute.
Expand Down Expand Up @@ -124,7 +140,7 @@ end

function AttributeValue.__newindex<T>(self: AttributeValue<T>, index, value)
if index == "Value" then
self._object:SetAttribute(rawget(self :: any, "_attributeName"), value)
self:SetValue(value)
elseif index == "AttributeName" then
error("Cannot set AttributeName")
else
Expand Down
Loading