Add naming for functional components
I want to recommend using functional components by default, but debugging with them is a huge pain because they don't have names.
I'd like to introduce a little utility that keeps a map of functional components to their names:
local function MyComponent(props)
-- ...
end
Roact.setComponentName(MyComponent, "MyComponent")
or maybe even something like
local MyComponent = Roact.FunctionalComponent("MyComponent", function(props)
-- ...
end)
but then we sort of lose the idea that functional components are just simple functions.
It's easy to implement setComponentName, but that raises the question: where is this name read? Is it intended to be used in debugging with print statements or the Lua debugger? We can't make tostring return the component's name, and wrapping the functional component in some way runs into the same issue as #9.
I've mulled over this problem for a couple months now.
I think we should introduce a new library that allows you to give names to things. It would basically just be a global weak map from any to string.
Roact can then optionally load this library and take advantage of it if you have it installed and have named your functional components with it.
I think this is too generically common of a problem to integrate directly into Roact, since naming things in general is useful!