-
Notifications
You must be signed in to change notification settings - Fork 24
Add a consistent rendering protocol. #92
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
Conversation
70657cb
to
49b3d74
Compare
87d6e24
to
b0ca361
Compare
I've been playing with these changes (well, after fixing that one lint issue) and: so far, so good. All my "template" functions return As a random aside: these changes also caused me to slightly update my @dataclass(frozen=True)
class with_children[C, R: h.Renderable, **P]:
"""Wrap a function to make it look more like an htpy.Element."""
_f: t.Callable[t.Concatenate[C, P], R]
_args: tuple[t.Any, ...] = field(default_factory=tuple)
_kwargs: t.Mapping[str, t.Any] = field(default_factory=dict)
def __getitem__(self, children: C) -> R:
"""Render the component with the given children."""
return self._f(children, *self._args, **self._kwargs)
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> t.Self:
"""Return a new instance of the class with the given arguments."""
return replace(self, _args=args, _kwargs=kwargs)
def __str__(self) -> str:
"""Return the name of the function being wrapped."""
# CONSIDER: alternatively, invoke the function here? If the function
# provides a default value for its arguments, it'll work; otherwise,
# it will blow up... which might be a good thing?
return f"with_children[{self._f.__name__}]" |
29ceefa
to
57fae08
Compare
@davepeck awesome, thanks for the update! pushed an updated version that fixes the lint problem. I renamed I will also add some kind of DeprecationWarning to render_node/iter_node and then hopefully merge this PR in the next few days. Then we can hopefully also get #38 done. Feel free to have a look there too! |
I prefer
Will do... |
I'm trying to get our version of What I'm saying is that I'd love for this to be merged and released, so that I can garbage collect half of my mental state 😅 |
have not been able to finish up these changes yet, not sure when I will get around to it. if someone wants to look into deprecation warnings for render_node/iter_node and update the docs/changelog, that would be helpful! |
I took a quick first stab at this: https://github.com/davepeck/htpy/tree/pelme-zsxolror Tried to match your house style but let me know what's most useful. (Update: my branch has a couple small updates as of 4/3 @ 9AM Pacific) |
7dd0abb
to
99a0f89
Compare
f94613d
to
3fc35b1
Compare
4f47267
to
2c96e6b
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.
I'm really happy where this landed!
This change provides a consistent API to render a htpy object as HTML or iterate over it. This commit introduces the iter_chunks() method which is identical with `__iter__()` but with a better name. With the introduction of Fragment, this commit makes render_node and iter_node redundant. This commit deprecates render_node, iter_node and direct iteration of elements. More info: #86 (comment)
This change provides a consistent API to render a htpy object as HTML or
iterate over it.
This commit introduces the iter_chunks() method which is identical with
__iter__()
but with a better name.With the introduction of Fragment, this commit makes render_node and
iter_node redundant.
This commit deprecates render_node, iter_node and direct iteration of elements.
More info: #86 (comment)