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

Nightly features #2743

Merged
merged 10 commits into from Jun 24, 2022
Merged

Nightly features #2743

merged 10 commits into from Jun 24, 2022

Conversation

hamza1311
Copy link
Member

Description

Add a nightly feature to use unstable features. This PR adds the following features:

  • UseForceUpdate has Fn/FnMut/FnOnce implementations calling force_trigger
  • UseReducerHandle has Fn/FnMut/FnOnce implementations calling dispatch
  • use_prepared_state! does not rewrite async closures to closure returning async block
  • void dynamic tags, when used with children, include source file and line number in their panic message

Fixes #2681

Checklist

  • I have reviewed my own code
  • I have added tests

@hamza1311 hamza1311 added A-yew Area: The main yew crate A-yew-macro Area: The yew-macro crate labels Jun 19, 2022
github-actions[bot]
github-actions bot previously approved these changes Jun 19, 2022
@github-actions
Copy link

github-actions bot commented Jun 19, 2022

Visit the preview URL for this PR (updated for commit 0b3c967):

https://yew-rs-api--pr2743-nightly-features-vychbm58.web.app

(expires Fri, 01 Jul 2022 14:12:47 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions
Copy link

github-actions bot commented Jun 19, 2022

Size Comparison

examples master (KB) pull request (KB) diff (KB) diff (%)
boids 172.593 172.593 0 0.000%
contexts 109.620 109.620 0 0.000%
counter 86.550 86.550 0 0.000%
counter_functional 87.203 87.203 0 0.000%
dyn_create_destroy_apps 89.664 89.664 0 0.000%
file_upload 102.626 102.626 0 0.000%
function_memory_game 166.894 166.894 0 0.000%
function_router 351.665 351.665 0 0.000%
function_todomvc 161.561 161.561 0 0.000%
futures 226.233 226.233 0 0.000%
game_of_life 107.189 107.189 0 0.000%
inner_html 83.618 83.618 0 0.000%
js_callback 112.846 112.846 0 0.000%
keyed_list 195.105 195.105 0 0.000%
mount_point 86.180 86.180 0 0.000%
nested_list 115.688 115.688 0 0.000%
node_refs 93.597 93.597 0 0.000%
password_strength 1538.157 1538.157 0 0.000%
portals 97.225 97.225 0 0.000%
router 320.458 320.458 0 0.000%
simple_ssr 154.493 154.493 0 0.000%
ssr_router 398.062 398.062 0 0.000%
suspense 110.544 110.544 0 0.000%
timer 89.258 89.258 0 0.000%
todomvc 142.615 142.615 0 0.000%
two_apps 87.160 87.160 0 0.000%
web_worker_fib 153.406 153.406 0 0.000%
webgl 87.438 87.438 0 0.000%

✅ None of the examples has changed their size significantly.

github-actions[bot]
github-actions bot previously approved these changes Jun 19, 2022
github-actions[bot]
github-actions bot previously approved these changes Jun 19, 2022
mod feat_nightly {
use super::*;

impl FnOnce<()> for UseForceUpdate {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not type UseForceUpdate = Rc<dyn Fn()>?

If we do not wish users to assume the underlying type of the handle, we can use type UseForceUpdate = impl Fn(); for nightly.

Also maybe should be named UseForceUpdateHandle so it's consistent with other hooks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not type UseForceUpdate = Rc<dyn Fn()>?

@WorldSEnder can better answer that. They added it in #2586

If we do not wish users to assume the underlying type of the handle, we can use type UseForceUpdate = impl Fn(); for nightly.

There's no point of doing that since the underlying type is Rc<dyn Fn()>. We can't use impl Fn() there because it is created as:

Rc::new(move || link.send_message(()))

Replacing that with impl Fn fails because the type alias can't capture the type parameter T.

Also maybe should be named UseForceUpdateHandle so it's consistent with other hooks.

Why not just expose ReRender type instead of having

type UseForceUpdateHandle = ReRender;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason was to not expose the fact that it's an Rc<_> since that's an implementation detail and the exact smart pointer in use might change. I'm not beefed up on the ABI of impl Trait for this case, but I think it makes it impossible to add other methods (and at least Sync/Send would have to be added anyway). That part is easier to control with a struct.

Also maybe should be named UseForceUpdateHandle

No objections. At the time I thought about Handle more for stateful things and just named it after the hook, but some consistency would be nice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with having the option to add more methods on the type

packages/yew/src/functional/hooks/use_reducer.rs Outdated Show resolved Hide resolved
github-actions[bot]
github-actions bot previously approved these changes Jun 20, 2022
github-actions[bot]
github-actions bot previously approved these changes Jun 20, 2022
github-actions[bot]
github-actions bot previously approved these changes Jun 20, 2022
github-actions[bot]
github-actions bot previously approved these changes Jun 24, 2022
@hamza1311 hamza1311 merged commit 54de041 into yewstack:master Jun 24, 2022
@futursolo futursolo mentioned this pull request Jun 24, 2022
2 tasks
@hamza1311 hamza1311 mentioned this pull request Jun 25, 2022
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-yew Area: The main yew crate A-yew-macro Area: The yew-macro crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a nightly feature flag to use nightly features
3 participants