-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support function components #473
Conversation
* Support local and remote function components * Support recursive components by translating them into function components
* No support for slots * No support for contexts * Don't validate args
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.
This looks great, good work!
I had a few small comments/questions, but no blockers
@@ -1223,4 +1294,17 @@ defmodule Surface.Compiler do | |||
|
|||
IOHelper.compile_error(message, file, line) | |||
end | |||
|
|||
defp handle_convert_node_to_ast_error(name, error, meta) do |
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.
❤️
caller_component_type = Module.get_attribute(meta.caller.module, :component_type) | ||
quote generated: true do | ||
component( | ||
&(unquote(Macro.var(fun, __MODULE__)) / 1), |
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.
The spacing here looks odd, but I assume that's not an actual issue?
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.
Yeah, that's not an issue. I find that ugly too but that's the way the formatter handles it so there's not much we can do about it, I guess :)
@@ -0,0 +1,43 @@ | |||
defmodule Surface.Components.Component do |
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.
Should we add a 'props' prop to allow passing a map of props? My thinking is that otherwise users would get warnings about unknown props for this component
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.
They shouldn't get any warning but they can also use {...}
. However, I'm not sure yet if that API is the best one. I'll create some tests for those cases and think how we can improve it.
@@ -0,0 +1,298 @@ | |||
defmodule Surface.Components.ComponentComponentTest do |
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.
defmodule Surface.Components.ComponentComponentTest do | |
defmodule Surface.Components.DynamicComponentTest do |
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.
@Malian good catch! I was also thinking about changing the namespace from Surface.Components.Component
to Surface.Components.Dynamic.Component
as we still gonna have to implement a Surface.Components.Dynamic.LiveComponent
in the near future. Since those built-in components are automatically aliased, I don't mind the larger name. WDYT?
5d6aadb
to
05b3e32
Compare
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.
Amazing work 👏
Can't add it to the review, but we might be able to remove the import Phoenix.HTML.Form
from the Form
component.
@@ -0,0 +1,43 @@ | |||
defmodule Surface.Components.Component do |
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.
Going by the file name:
defmodule Surface.Components.Component do | |
defmodule Surface.Components.DynamicComponent do |
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.
But in the tests it seems you named it Component
on purpose, it does read nicer 🤔
Also closes #343 and #24.