yew
yew copied to clipboard
Introduce a new use_async hook, that allows for setting dependencies
Description
Introduce an use_async hook, that performs a computation in another task and returns the result.
(Probably) fixes #364
The main API design question is whether we want to introduce the idea of cancellation in the API or not. Adding it afterwards would likely require adding a variant to UseAsyncStatus. This being said, Yew is not stable yet, and probably at least 90% of the use cases are covered by this API, so I think it makes sense to postpone the decision after verifying that there is an actual need.
This PR is not done yet, and is here mostly to gather feedback on whether this is something that Yew developers would be interested in having upstream. I'm using it in my own code here, and thought it would likely be helpful to other people too.
The alternatives I know of are:
- The
use_asyncanduse_async_with_optionsfromyew_hooks. They do not support introducing dependencies that would trigger a future re-computation. yewtil'sLinkFuture. Not having used it I'm less familiar with it, but AFAIU it requires struct components, which is not the direction Yew development seems to be moving towards.
Checklist
Things still missing if you confirm that this PR is of interest to you:
- [x] I have reviewed my own code
- [ ] I have added tests
- [ ] Writing clear documentation
- [ ] Fixing all of CI
Size Comparison
| examples | master (KB) | pull request (KB) | diff (KB) | diff (%) |
|---|---|---|---|---|
| async_clock | 100.530 | N/A | N/A | N/A |
| boids | 173.547 | N/A | N/A | N/A |
| communication_child_to_parent | 93.072 | N/A | N/A | N/A |
| communication_grandchild_with_grandparent | 105.655 | N/A | N/A | N/A |
| communication_grandparent_to_grandchild | 101.043 | N/A | N/A | N/A |
| communication_parent_to_child | 89.413 | N/A | N/A | N/A |
| contexts | 105.821 | N/A | N/A | N/A |
| counter | 86.281 | N/A | N/A | N/A |
| counter_functional | 86.451 | N/A | N/A | N/A |
| dyn_create_destroy_apps | 89.275 | N/A | N/A | N/A |
| file_upload | 100.440 | N/A | N/A | N/A |
| function_memory_game | 172.253 | N/A | N/A | N/A |
| function_router | 349.531 | N/A | N/A | N/A |
| function_todomvc | 162.304 | N/A | N/A | N/A |
| futures | 229.101 | N/A | N/A | N/A |
| game_of_life | 109.982 | N/A | N/A | N/A |
| immutable | 189.679 | N/A | N/A | N/A |
| inner_html | 80.040 | N/A | N/A | N/A |
| js_callback | 109.576 | N/A | N/A | N/A |
| keyed_list | 198.589 | N/A | N/A | N/A |
| mount_point | 82.877 | N/A | N/A | N/A |
| nested_list | 114.631 | N/A | N/A | N/A |
| node_refs | 90.462 | N/A | N/A | N/A |
| password_strength | 1726.314 | N/A | N/A | N/A |
| portals | 93.754 | N/A | N/A | N/A |
| router | 318.227 | N/A | N/A | N/A |
| simple_ssr | 141.650 | N/A | N/A | N/A |
| ssr_router | 389.408 | N/A | N/A | N/A |
| suspense | 116.107 | N/A | N/A | N/A |
| timer | 88.976 | N/A | N/A | N/A |
| timer_functional | 97.995 | N/A | N/A | N/A |
| todomvc | 142.318 | N/A | N/A | N/A |
| two_apps | 85.590 | N/A | N/A | N/A |
| web_worker_fib | 136.037 | N/A | N/A | N/A |
| web_worker_prime | 186.757 | N/A | N/A | N/A |
| webgl | 82.662 | N/A | N/A | N/A |
✅ None of the examples has changed their size significantly.
@hamza1311 you might not have seen my earlier comment
Considering the time I've been having recently, I think I unfortunately won't have any to come back to this PR.
Going to close this, but anyone please feel free to take it over! :)