Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #1463 #1464

Merged
merged 1 commit into from
Aug 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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