Replies: 4 comments 12 replies
-
Closure doesn't mean you have to use signal in it. So you can do label(|| "initial") |
Beta Was this translation helpful? Give feedback.
-
I have an idea that might work. If you look at the internal implementation of the reactivity of widgets, the widgets themselves are static by nature, and the reactivity is a So my proposal is, on the widget building function, they only takes the initial value, (static by default), and then they provide a chained method which takes the closure to provide reactivity. So the label("text") let text = create_rw_signal(String::new("initial"));
label("initial").update(|| text.get())
stack((view1, view2)) let items = create_rw_signal(vec![1,2]);
stack(()).update(|| items.get(), |i| *i, |i| label(i.to_string())) |
Beta Was this translation helpful? Give feedback.
-
For my own project i created MaybeSignal enum, basically same that Leptos has. I don't know how bad it is performance wise but it makes really easy to create components that can take static or dynamic (signal) as value. https://gist.github.com/aalhitennf/d1a647065518f36cefeb9f659a270ab8 Not sure if this i correct, pasting it from old files but you should get the idea
Using signal
or static
|
Beta Was this translation helpful? Give feedback.
-
As far as I know, the Google team has designed two types of widgets in the Flutter framework: StatefulWidget and StatelessWidget. They correspond to stateful and stateless respectively. |
Beta Was this translation helpful? Give feedback.
-
Disclaimer: this is a bit meta and the "right" level of granularity certainly depends on many factor.
As I'm wrapping a bunch of floem widget factories, I came to notice that many/most receive a lot of closures, which is dandy to inject signals, e.g.
As I'm becoming more familiar with the implementation and widgets, i came to wonder if it wasn't "simpler" and just as costly to write something like:
minus maybe some copies (which could easily be addressed), this may seem like more typing at first but assuming that many labels will actually not be reactive, would be less typing and a simpler API, i.e. static by default and reactive when needed.
I assume this is why there's
text()
a.k.a.static_label()
. Though the same argument could be made for widgets, e.g.img()
,svg()
, ... and probably many more closure-heavy widgets. In other words, I'm wondering if it could make sense to make at least all "static asset" widgets (maybe others) less-reactive by default and wrap them in reactive containers to swap 'em in and out? Should there even be a reactive label, img, svg, ...?Given you have to maintain a large number of widget APIs, I'm confident that you've carefully thought about this. This makes me think that I'm probably just missing something.
Beta Was this translation helpful? Give feedback.
All reactions