-
-
Notifications
You must be signed in to change notification settings - Fork 2
Description
I've been thinking about this since 2024, when I was unemployed and trying to do it using macros. Until macros were abandoned (because I really dislike build).
I was pleasantly surprised when you released Solid, because you were continuing something I'd been trying to do but never released. You bravely released it.
Getting back to the point, perhaps we can consider something simpler.
<solid>
final props = $props({
'firstName': String,
'lastName': Nullable<String>,
});
final fullName = $('${props.firstName} ${props.lastName}');
int age = $state(0);
void onPlus() => age++;
$.mount(() {
print('The widget mounted');
});
</solid>
<Column>
<Text>{{ fullName }}</Text> // t1
<Text>{{ age }}</Text> // t2
<TextButton
@tap="onPlus"
>Plus one age</TextButton>
</Column>Why do we need to do this?
It's difficult. First, we need to write a Solid parser for Solid. Implementing syntax highlighting within the special tag <solid> is something I've considered for a long time.
For example, int age = $state(0); ultimately needs to be split into independent getters and setters.
Essentially, $props, $state, and $ are macro-like markers that perform syntax transformations within the Solid source code.
Why is this necessary? This is one of the most ideal forms where developers can have complete control over Widgets without changing the Flutter framework. Especially when using built-in Widgets, by tracking the state, only the dependent Widgets are rebuilt. That is, when the user clicks Plus one age to trigger onPlus, only t2 will be rebuilt.
Parent Level
<Example firstName="Seven" lastName="Du" />When firstName or lastName is updated, the component itself will not be rebuilt. Because it can collect props while only triggering the rebuild of the t1 Widget.
Emmm, this is a way I've been conceiving for a year to implement SFC based on Dart syntax. I initially implemented its prototype using only macros. If the macros still exist, there's no need to write CLI commands to transform the code.