-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add custom type for attribute values #1994
Conversation
What is the motivation for having a distinct |
Cases where the user already has a |
I'm wondering whether we should perhaps make |
const VALUE: AttrValue = AttrValue::Static("value"); This isn't possible with |
Sure, but we could "fix" this by introducing a const constructor in this case. |
What will the constructor be called? impl AttrValue {
fn new_static(value: &'static str) -> Self { .. }
fn new_number(value: u32) -> Self { .. }
// ...
} feels wrong
Why not? |
I think once we start tackling #1322 and more specifically allow objects to be set to properties then |
That's a good point, but I don't think #1322 is going to happen anytime soon. For me the question only boils down to whether we want users to be able to destructure |
But I just want to make it clear that I don't feel that strongly about this, I'm just always looking for ways to reduce the public API surface to what's truly needed. |
I don't see how #1322 is gonna be touching the |
If you are talking about breaking the enum, I am already planning to. There are some really nice optimizations we can get by specializing |
Unless I'm misunderstanding what you're trying to do that should still be possible whether the enum is publicly exposed or not. |
The basic idea is "why have enums at all?" - much of diffing can be specialised at compile time. Concerning attributes, make a trait like |
To clarify, I was specifically replying to
|
That trait will need to provide a function that returns a string that will be passed to the DOM. We can do all the diffing that we want on the Rust types but we still need (iirc) |
Yes, it would need to be convertible to a
|
So, for now, should we just roll with it? Or should I make this an opaque type with const constructors? I like the former, const constructors don't feel right when the enum can be constructed directly. |
11e105f
to
1b886ca
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.
Here are the long overdue comments :D
packages/yew/src/virtual_dom/mod.rs
Outdated
} | ||
} | ||
|
||
impl PartialEq<String> for AttrValue { |
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.
We should implement PartialEq<str>
too. Maybe we don't even need PartialEq<String>
then, but not quite sure about that.
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.
How about removing PartialEq
implementations altogether? AsRef
and Deref
can get the job done.
I added the String
one because some place needed it but seems like it works fine if I use as_ref
.
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 removed the implementation. Let me know if one should be added.
# Conflicts: # packages/yew-macro/tests/html_macro/element-fail.stderr # packages/yew-macro/tests/html_macro/html-element-pass.rs
Description
This PR introduces a new type,
AttrValue
, for attribute values. This is a replacement forCow<'static, str>
so that:Fixes #1851
Unsolved questions
VTag
also use this for the tag's nameClasses
use this instead ofCow<'static, str>
Checklist
cargo make pr-flow