mirror of
https://github.com/danbulant/cushy
synced 2026-05-22 05:38:54 +00:00
Refs #98 This refactor overhauls the reactive system to move all the reactive methods to traits. The side effect of this change is that now DynamicReader's API is the same as Dynamic's API, but because it only implements Source<T>, DynamicReader does not offer any mutation functions. While it's unfortunate to have more traits to include to use Cushy, this seems like the best option, and it offers a path to try to integrate this into the tuple ForEach/MapEach traits. Unfortunately, my attempt at doing those in this set of changes led to issues specifying generic associated lifetimes for the DynamicGuard. But, I was also in the middle of this larger refactoring, so it might be that a fresh attempt will succeed.
20 lines
653 B
Rust
20 lines
653 B
Rust
use cushy::value::{Destination, Dynamic, Source};
|
|
use cushy::widget::MakeWidget;
|
|
use cushy::Run;
|
|
|
|
// begin rustme snippet: readme
|
|
fn main() -> cushy::Result {
|
|
// Create a dynamic usize.
|
|
let count = Dynamic::new(0_isize);
|
|
// Create a dynamic that contains `count.to_string()`
|
|
let count_label = count.map_each(ToString::to_string);
|
|
|
|
// Create a new button whose text is our dynamic string.
|
|
count_label
|
|
.into_button()
|
|
// Set the `on_click` callback to a closure that increments the counter.
|
|
.on_click(move |_| count.set(count.get() + 1))
|
|
// Run the application
|
|
.run()
|
|
}
|
|
// end rustme snippet
|