Fusion
Fusion copied to clipboard
Add attributes support to New
Currently it's not possible to set attributes on instances being created with the New function. Additionally, it's not possible to listen for changes on attributes.
While attributes aren't particularly useful within Fusion, having support for them would make it easier to integrate Fusion with legacy UI codebases which depend on them.
Possible API (implemented as part of the New function):
New "Instance" {
[Attribute "Foo"] = "bar", -- if a state or computed object, binds to the attribute
[AttributeChange "Foo"] = function(newValue)
print("The attribute was changed to:", newValue)
end
}
An alternate possible API from Twitter (adapted from a suggestion by @/bradsharppp):
New "Instance" {
[Attributes] = {
Foo = "bar",
[OnChange "Foo"] = function(newValue)
print("The attribute was changed to:", newValue)
end
}
}
Alternatively, we could keep AttributeChange separate from the Attributes table?
I personally prefer the first option as it is very similar to the API for normal properties.
I personally prefer the first option as it is very similar to the API for normal properties.
Agreed - I don't personally see many use cases where a lot of attributes are being used at once within the context of Fusion, so I think it'd overall be cleaner not to use a nested table.
I personally prefer the first option as it is very similar to the API for normal properties.
Agreed - I don't personally see many use cases where a lot of attributes are being used at once within the context of Fusion, so I think it'd overall be cleaner not to use a nested table.
Same here! I think fusion should eliminate the times where you normally in Roact get huge files with lots of scopes.