From 7d3efcce14f46b779e962c7b8911ba3a8f0a920b Mon Sep 17 00:00:00 2001 From: Jens Reimann Date: Sun, 2 Aug 2020 23:01:59 +0200 Subject: [PATCH] Fix issue #1463 --- yew/src/html/scope.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/yew/src/html/scope.rs b/yew/src/html/scope.rs index 2bce25b687a..1f8395dbfc0 100644 --- a/yew/src/html/scope.rs +++ b/yew/src/html/scope.rs @@ -267,6 +267,24 @@ impl Scope { }; closure.into() } + + /// Creates a `Callback` from a 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 {