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

Add a method to emit multiple messages in one callback #660

Merged
merged 5 commits into from
Sep 27, 2019
Merged
Changes from 2 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
16 changes: 16 additions & 0 deletions src/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,22 @@ where
}
}

/// This method create an effect that provider a dispatch function to send messages mutiple
/// times.
pub fn create_effect<F, IN>(&mut self, function: F) -> Callback<IN>
where
F: Fn(IN, &dyn Fn(COMP::Message)) + 'static,
{
let scope = self.scope.clone();
let dispatch = move |msg: COMP::Message| {
scope.clone().send_message(msg);
};
let closure = move |input| {
function(input, &dispatch);
};
closure.into()
}

/// This method sends messages back to the component's loop.
pub fn send_back<F, IN>(&mut self, function: F) -> Callback<IN>
where
Expand Down