#[derive(Slice)]
{
// Attributes available to this derive:
#[bounce]
}
Expand description
A reducer-based state that is Copy-on-Write and notifies registered hooks when prev_value != next_value.
It can be derived for any state that implements Reducible + PartialEq + Default.
ยงExample
use std::rc::Rc;
use bounce::prelude::*;
use yew::prelude::*;
enum CounterAction {
Increment,
Decrement,
}
#[derive(PartialEq, Default, Slice)]
struct Counter(u64);
impl Reducible for Counter {
type Action = CounterAction;
fn reduce(self: Rc<Self>, action: Self::Action) -> Rc<Self> {
match action {
CounterAction::Increment => Self(self.0 + 1).into(),
CounterAction::Decrement => Self(self.0 - 1).into(),
}
}
}See: use_slice