Skip to content

Commit

Permalink
Fix issue #1463
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Aug 2, 2020
1 parent 72d0b2f commit 7d3efcc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions yew/src/html/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,24 @@ impl<COMP: Component> Scope<COMP> {
};
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<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 7d3efcc

Please sign in to comment.