Skip to content

Commit

Permalink
Add no-op method for Callback (#793)
Browse files Browse the repository at this point in the history
When a component is created with an optional event handler, it can
be passed as an `Option` prop, however in certain cases, it is useful to
have either a default event handler, rather than passing a `None`.
  • Loading branch information
mdtusz authored and jstarry committed Dec 10, 2019
1 parent 06c1c82 commit f872884
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ impl<IN> Callback<IN> {
pub fn emit(&self, value: IN) {
(self.0)(value);
}

/// Creates a no-op callback which can be used when it is not suitable to use an
/// `Option<Callback>`.
pub fn noop() -> Self {
Self::from(|_| {})
}
}

impl<IN: 'static> Callback<IN> {
Expand Down

0 comments on commit f872884

Please sign in to comment.