From 6490d6db4df2cc3c4748782f82582b0ab1052898 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Sat, 31 Dec 2022 16:59:40 -0600 Subject: [PATCH] Add a dispatch_and method --- Cargo.toml | 2 +- src/lib.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index fba5160..cd5df35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sycamore-state" -version = "0.1.0" +version = "0.1.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/lib.rs b/src/lib.rs index 82941cb..fa8a345 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,6 +59,15 @@ where self.dispatcher.map(cx, msg, self.signal) } + /// Directly handle a state message and then run a Fn. + pub fn dispatch_and(&'ctx self, cx: Scope<'ctx>, msg: Msg, f: F) + where + F: FnOnce(), + { + self.dispatch(cx, msg); + f(); + } + /// Provides a ReadSignal handle for the contained Signal implementation. pub fn read_signal(&'ctx self) -> &'ctx ReadSignal { self.signal