pub fn use_optimistic<A, R, D>(
mutation: Mutation<A, R>,
subscription: Signal<SubscriptionState<D>>,
apply: impl Fn(&D, &A) -> D + 'static,
) -> OptimisticMutation<A, R, D>where
A: Serialize + Clone + 'static,
R: DeserializeOwned + 'static,
D: Clone + PartialEq + 'static,Expand description
Create an optimistic mutation that layers local patches over a live
subscription. Returns an OptimisticMutation whose .data() reflects
the optimistic state and whose .fire() applies the transform, sends the
mutation, and auto-reverts on error or TTL expiry.
ⓘ
let reorder = use_optimistic(
use_reorder_task(),
use_list_tasks_live_signal(),
|tasks, args: &ReorderTaskInput| {
tasks.iter().map(|t| {
if t.id == args.id { Task { status: args.status, position: args.position, ..t.clone() } }
else { t.clone() }
}).collect()
},
);
// Read from reorder.data() instead of the raw subscription
// Call reorder.fire(args) for optimistic + server mutation