From 7565670267a0b313c7d8a4536e452ba347bc3d8e Mon Sep 17 00:00:00 2001 From: Jens Reimann Date: Mon, 3 Aug 2020 16:30:10 +0200 Subject: [PATCH] Fix issue #1463 (#1464) --- yew/src/html/scope.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/yew/src/html/scope.rs b/yew/src/html/scope.rs index 2bce25b687a..b3be1688d7f 100644 --- a/yew/src/html/scope.rs +++ b/yew/src/html/scope.rs @@ -231,7 +231,7 @@ impl Scope { closure.into() } - /// Creates a `Callback` from a FnOnce which will send a message + /// Creates a `Callback` from an `FnOnce` which will send a message /// to the linked component's update method when invoked. /// /// Please be aware that currently the result of this callback @@ -267,6 +267,24 @@ impl Scope { }; closure.into() } + + /// Creates a `Callback` from an `FnOnce` which will send a batch of messages back + /// to the linked component's update method when invoked. + /// + /// Please be aware that currently the results of these callbacks + /// will synchronously schedule calls to the + /// [Component](Component) interface. + pub fn batch_callback_once(&self, function: F) -> Callback + where + F: FnOnce(IN) -> Vec + 'static, + { + let scope = self.clone(); + let closure = move |input| { + let messages = function(input); + scope.send_message_batch(messages); + }; + Callback::once(closure) + } } struct ComponentState {