Memoize certain SpecialKeys like OnEvent to allow for easy passthrough.
Currently, if you want to do passthrough events from one component to another, the current expected way is to use string indices in the props table like so:
local myButtonComponent(props)
return New "TextButton" {
[OnEvent "Activated"] = props.Activated
}
end
myButtonComponent {
Activated = function()
print("do thing")
end
}
However, this can sometimes make it somewhat difficult to have a continuous format for setting things to happen on events.
My proposal is to memoize OnEvent registers so that it is easier to perform actions like the following without having to store the special key return everywhere it is needed. This would make users' codebases much more consistent as they would be able to use the same event formatting for their components as they do when using New if they so wish.
local myButtonComponent(props)
return New "TextButton" {
[OnEvent "Activated"] = props[OnEvent "Activated"]
}
end
myButtonComponent {
[OnEvent "Activated"] = function()
print("do thing")
end
}
This seems like a good change. This should probably also be done for the other special keys that take arguments such as OnChange, Out etc
This would be a breaking change for those using this special key multiple times in a property table. I don't think that's a dealbreaker though; we could always let these special keys accept array arguments if we really want to support that kind of usage.
Moving this to an issue #320.