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

Introduce use_future_with_deps #2615

Merged
merged 5 commits into from Apr 17, 2022

Conversation

WorldSEnder
Copy link
Member

Description

Fill the remaining gap from #2609 and introduce use_future_with_deps.
I'll finish the remaining tasks such as docs and better tests tomorrow, just wanted to show that it's possible.

Checklist

  • I have run cargo make pr-flow
  • I have reviewed my own code
  • I have added tests

github-actions[bot]
github-actions bot previously approved these changes Apr 15, 2022
@WorldSEnder
Copy link
Member Author

Oops, I didn't want to request a review immediately @hamza1311 There's still a few things to improve before then.

@github-actions
Copy link

github-actions bot commented Apr 15, 2022

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

https://yew-rs-api--pr2615-use-future-with-deps-obllg21z.web.app

(expires Sun, 24 Apr 2022 09:10:45 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions
Copy link

github-actions bot commented Apr 15, 2022

Size Comparison

examples master (KB) pull request (KB) diff
boids 173.618 173.618 0
contexts 112.688 110.920 -1.768
counter 87.486 87.486 0
counter_functional 88.044 88.044 0
dyn_create_destroy_apps 90.662 90.662 0
file_upload 103.424 103.424 0
function_memory_game 171.559 168.028 -3.530
function_router 355.165 353.456 -1.709
function_todomvc 162.960 162.960 0
futures 227.072 227.072 0
game_of_life 108.501 108.501 0
inner_html 83.977 83.977 0
js_callback 92.600 92.600 0
keyed_list 196.515 196.515 0
mount_point 87.010 87.010 0
nested_list 116.636 116.636 0
node_refs 90.510 90.510 0
password_strength 1540.407 1540.407 0
portals 97.707 97.707 0
router 319.233 319.233 0
simple_ssr 501.096 501.096 0
ssr_router 430.930 429.223 -1.707
suspense 111.460 111.460 0
timer 90.204 90.204 0
todomvc 144.178 144.178 0
two_apps 88.073 88.073 0
webgl 87.665 87.665 0

github-actions[bot]
github-actions bot previously approved these changes Apr 16, 2022
github-actions[bot]
github-actions bot previously approved these changes Apr 16, 2022
@WorldSEnder WorldSEnder marked this pull request as ready for review April 16, 2022 01:02
Copy link
Member

@futursolo futursolo left a comment

Choose a reason for hiding this comment

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

I think use_future(|| async { ... }) is equivalent to use_future_with_deps(|_| async { ... }, ()).

Maybe these 2 hooks should be merged?
This would bring this hook to be more inline with use_memo and lead to a smaller codebase.
(Performance penalty of comparing () should be very minimal.)

packages/yew/src/suspense/hooks.rs Outdated Show resolved Hide resolved
@hamza1311
Copy link
Member

I think use_future(|| async { ... }) is equivalent to use_future_with_deps(|_| async { ... }, ()).

I don't see how this is different from use_effect(|| { ... }) and use_effect_with_deps(|_| { ... }, ()). Should those two be also merged then?

@futursolo
Copy link
Member

futursolo commented Apr 16, 2022

I don't see how this is different from use_effect(|| { ... }) and use_effect_with_deps(|_| { ... }, ()).

use_effect without specifying deps runs on every render (as if the deps changes every time) and use_effect_with_deps(|_| { ... }, ()) runs only once.

github-actions[bot]
github-actions bot previously approved these changes Apr 17, 2022
@jetli
Copy link
Contributor

jetli commented Apr 17, 2022

@WorldSEnder let latest_id = use_state(|| Cell::new(0u32));, should we use use_mute_ref instead to reduce state updates? as it is only used internally

@WorldSEnder
Copy link
Member Author

@WorldSEnder let latest_id = use_state(|| Cell::new(0u32));, should we use use_mute_ref instead to reduce state updates? as it is only used internally

At least for now, the Cell is less expensive, as far as I can tell. No state updates are ever triggered since it uses internal mutability. use_mut_ref is actually more work, since it needs to borrow the RefCell. The point here is to have a shared state, but also use internal mutability.

@hamza1311 hamza1311 merged commit 504693f into yewstack:master Apr 17, 2022
@WorldSEnder WorldSEnder deleted the use_future_with_deps branch April 17, 2022 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants