-
Notifications
You must be signed in to change notification settings - Fork 21
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
Breaking changes for better usability discussion #64
Comments
I do agree with this one, at first I thought it was just a naming convention until I realize it wasn't. I suggest using a function with a name |
Also, I just notice that compiling with AOT refuses the binding to work properly. I wonder if this is related to the |
I assume that it can caused by that classic avalonia binding is using string path to property, so some types can be trimmed while building. also take a look on this sample where we have a workaround to prevent class from trimming
|
After some experience of making big app with this package I started to think that mapping extensions to every property was not the best idea. And the better approach at the moment will be using property initializers like this: public class Component : ComponentBase
{
protected override object Build() =>
new StackPanel()
.Children(
new TextBlock() { Text = "Hello world" }
.Ref(out _textBlock1)
new TextBlock() { Text = Bind(() => $"Counter: {(Counter == 0 ? "zero" : Counter)}") },
new Button() { Content = "Click me" }
.OnClick(OnButtonClick)
);
. . . . . So we keep only common, not autogenerated extensions, i.e. for Children to visually split declaration of inner nodes from other properties and reduce amount of closing braces. For Styles and event handlers I have to think yet. So this change will lead to:
cons:
I'm going to test the new approach for a couple weeks and I'd like to hear any comments from you about this as well |
I feel that the current Extension Method approach provides a cleaner and more consistent developer experience. Its also inline with other frameworks like Uno. I just noticed that they are able to use their Source Generator to generate code for external libraries. See here, https://platform.uno/docs/articles/external/uno.extensions/doc/Learn/Markup/GeneratingExtensions.html#using-the-generator-for-3rd-party-libraries Some comments on the pros:
"allow to see native documentation from Avalonia properties"
"more compact syntax, because it's still readable when you define property initializers in one line"
The 2 approaches side by side: public class Component : ComponentBase
{
protected override object Build() =>
new StackPanel()
.Children(
new TextBlock() { Text = "Hello world" }
.Ref(out _textBlock1)
new TextBlock() { Text = Bind(() => $"Counter: {(Counter == 0 ? "zero" : Counter)}") },
new Button() { Content = "Click me" }
.OnClick(OnButtonClick)
);
. . . . . public class Component : ComponentBase
{
protected override object Build() =>
new StackPanel()
.Children(
new TextBlock()
.Ref(out _textBlock1)
.Text("Hello world"),
new TextBlock()
.Text(Bind(() => $"Counter: {(Counter == 0 ? "zero" : Counter)}")),
new Button()
.Content("Click me")
.OnClick(OnButtonClick)
);
. . . . . |
@gritsenko, I think we can generate extensions for local and external classes with a Source Generator. My plan is to hack a proof of concept. If it works, this should simplify the approach to a single codebase. Then we can look into performance by converting it to a Incremental Source Generator. |
@IvanJosipovic thank you for your enthusiasm!) I'm going to check out it |
I think using @ prefix for binding definition was not a good idea. It leads to increasing complexity and involves unnecessary string parsing logic under the hood. So I think this should be deprecated in future releases.
The text was updated successfully, but these errors were encountered: