From b595c2abbf191a164053cbf7471acbfd990cfdc1 Mon Sep 17 00:00:00 2001
From: Jens Reimann <jreimann@redhat.com>
Date: Sun, 2 Aug 2020 23:01:59 +0200
Subject: [PATCH] Fix issue #1463

---
 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<COMP: Component> Scope<COMP> {
         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<COMP: Component> Scope<COMP> {
         };
         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<F, IN>(&self, function: F) -> Callback<IN>
+    where
+        F: FnOnce(IN) -> Vec<COMP::Message> + 'static,
+    {
+        let scope = self.clone();
+        let closure = move |input| {
+            let messages = function(input);
+            scope.send_message_batch(messages);
+        };
+        Callback::once(closure)
+    }
 }
 
 struct ComponentState<COMP: Component> {