-
Notifications
You must be signed in to change notification settings - Fork 2
Remove reliance on CamelCase component names #9
Remove reliance on CamelCase component names #9
Conversation
|
Accidentally PR'd the archived repo. Moving to idom-team/flake8-idom#3 |
|
I unarchived this a while back. Haven't had time to switch to flake8-idom. |
|
A note on this this - one reason using the CamelCase for function component definitions makes sense is that the behavior is much more like that of a class. If for example, we named these with snake case one might expect the following to be true: @component
def my_component():
print("It ran!")
return idom.html.div()
assert my_component() == idom.html.div()However, in reality: assert isinstance(my_component(), Component)We also do not see the print statement. To get the initially expected result we must do manually, what the layout automatically would otherwise: instance = my_component()
assert instance.render() == idom.html.div()STDOUT: The take away here being that the naming of function components with CamelCase is more than just stylistic. It is an attempt to indicate a behavioral difference between functions that are/aren't components - functions named with CamelCase behave much more like a class (i.e. it's an object constructor). |
|
To end users, that's irrelevant. Functions def = Regardless of what they mutate into due to the decorator, I believe PEP8 should be followed. Plus we can't expect most users to use the |
|
You'll need to update the test cases in this file to use an |
rmorshea
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM besides this. Will merge and release next week.
|
closed in favor of #14 |
is_component_defnow checks if a function is decorated with@idom.componentto determine whether something is a component.This implementation also works if directly using
@componentas a decorator.Also, all hook names are now explicitly checked for rather than assuming everything
use_*is a hook.