Skip to content

Commit

Permalink
Fix issue #1463 (#1464)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Aug 3, 2020
1 parent 72d0b2f commit 7565670
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion yew/src/html/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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> {
Expand Down

0 comments on commit 7565670

Please sign in to comment.