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

Adding callback_future_once on LinkFuture trait (yewtil crate) #1696

Closed
fraillt opened this issue Jan 11, 2021 · 3 comments · Fixed by #1712
Closed

Adding callback_future_once on LinkFuture trait (yewtil crate) #1696

fraillt opened this issue Jan 11, 2021 · 3 comments · Fixed by #1712
Labels
ergonomics 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt

Comments

@fraillt
Copy link
Contributor

fraillt commented Jan 11, 2021

Issuehunt badges

It would be nice to have callback_future_once, as it matches nicely with callback_once.
also it looks much cleaner.

self.link.callback_future_once(|_| async move {
    Msg::FileUploaded(upload_form.post_async().await)
})

vs.

self.link.callback_future(move |_| {
    let upload_form = upload_form.clone();
    async move { Msg::FileUploaded(upload_form.post_async().await) }
}),

Implementation is pretty simple as well.

impl<COMP: Component> LinkFuture for ComponentLink<COMP> {
...
    fn callback_future_once<FN, FU, IN, M>(&self, function: FN) -> yew::Callback<IN>
    where
        M: Into<Self::Message>,
        FU: Future<Output = M> + 'static,
        FN: FnOnce(IN) -> FU + 'static,
    {
        let link = self.clone();

        let closure = move |input: IN| {
            let future: FU = function(input);
            link.send_future(future);
        };

        Callback::once(closure)
    }
...
}

Does it needs more discussion, or maybe I can make a PR? :)


IssueHunt Summary

fraillt fraillt has been rewarded.

Backers (Total: $5.00)

Submitted pull Requests


Tips

@jstarry
Copy link
Member

jstarry commented Jan 23, 2021

No more discussion needed, sounds nice to have, PR is welcome @fraillt!

@issuehunt-oss
Copy link

issuehunt-oss bot commented Jan 23, 2021

@jstarry has funded $5.00 to this issue.


@issuehunt-oss issuehunt-oss bot added the 💵 Funded on Issuehunt This issue has been funded on Issuehunt label Jan 23, 2021
@issuehunt-oss
Copy link

issuehunt-oss bot commented Jan 23, 2021

@jstarry has rewarded $4.50 to @fraillt. See it on IssueHunt

  • 💰 Total deposit: $5.00
  • 🎉 Repository reward(0%): $0.00
  • 🔧 Service fee(10%): $0.50

@issuehunt-oss issuehunt-oss bot added 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt and removed 💵 Funded on Issuehunt This issue has been funded on Issuehunt labels Jan 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ergonomics 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants