flow
flow copied to clipboard
LitRenderer withProperties method to optimize code
Describe your motivation
Say I have a grid that uses the following record:
public record Rectangle(double width, double height) {}
And I want to add a column that uses LitRenderer:
grid.addColumn(
LitRenderer
.<Rectangle>of("<span class=\"${item.class}\">${item.text}</span>")
.withProperty("class", item -> {
// Some logic that checks both `width` and `height`.
})
.withProperty("text", item -> {
// Same logic.
})
);
Even though I perform the same logic, I have to do it twice.
Describe the solution you'd like
LitRenderer#withProperties
LitRenderer
.<Rectangle>of(...)
.withProperties("class", item -> {
// Some logic that checks both `width` and `height`.
// Returns maybe a JSON object with property's `class` and `text`.
})
Perhaps this could be expanded further to support a single method for both properties and functions.
I feel that component renderers are not a solution as they are troublesome for large datasets.
@mshabarov Not a big deal, but does the "Good First Issue" label refer to it being my first issue or a good first issue for a new developer? If the former, this is my not first Vaadin issue.
@oliveryasuna these labels simply means that we in Vaadin Flow appreciate any contribution for it and our estimation is that it should be relatively easy for external developers to implement it. No matter if you've done any other contributions in past or if it's your first one :)
@oliveryasuna these labels simply means that we in Vaadin Flow appreciate any contribution for it and our estimation is that it should be relatively easy for external developers to implement it. No matter if you've done any other contributions in past or if it's your first one :)
Understood, thank you for clarifying. Just a tedious question.
I'm not sure how this could be implemented without breaking getValueProviders() since the names of the available properties would only be known after running the new type of value provider and seeing what properties were included in its return value. This also makes me believe this isn't an easy issue for someone to get started with contributing.
@Legioth Funny you mention that. I attempted this, but realized the same, and was coming here to suggest we remove the "Good First Issue" label.