yew
yew copied to clipboard
File upload - simplify a bit with gloo::file::FileList::from
Description
gloo::file::FileList::from can do some of the conversion for us, removing the need for an auxiliary fn. This leads to trimming down the callbacks a bit. And hey, we have this FileDetails, why not just use it instead of passing the vars separately?
Checklist
- [ x] I have reviewed my own code
- [ ] I have added tests Example tests?
Size Comparison
| examples | master (KB) | pull request (KB) | diff (KB) | diff (%) |
|---|---|---|---|---|
| async_clock | 98.044 | 98.044 | 0 | 0.000% |
| boids | 168.187 | 168.187 | 0 | 0.000% |
| communication_child_to_parent | 90.549 | 90.549 | 0 | 0.000% |
| communication_grandchild_with_grandparent | 102.778 | 102.778 | 0 | 0.000% |
| communication_grandparent_to_grandchild | 98.207 | 98.207 | 0 | 0.000% |
| communication_parent_to_child | 86.901 | 86.901 | 0 | 0.000% |
| contexts | 102.367 | 102.367 | 0 | 0.000% |
| counter | 83.544 | 83.544 | 0 | 0.000% |
| counter_functional | 83.969 | 83.969 | 0 | 0.000% |
| dyn_create_destroy_apps | 86.927 | 86.927 | 0 | 0.000% |
| file_upload | 97.942 | 97.245 | -0.697 | -0.712% |
| function_memory_game | 164.288 | 164.288 | 0 | 0.000% |
| function_router | 338.087 | 338.087 | 0 | 0.000% |
| function_todomvc | 158.255 | 158.255 | 0 | 0.000% |
| futures | 226.149 | 226.149 | 0 | 0.000% |
| game_of_life | 105.657 | 105.657 | 0 | 0.000% |
| immutable | 186.278 | 186.278 | 0 | 0.000% |
| inner_html | 77.900 | 77.900 | 0 | 0.000% |
| js_callback | 105.875 | 105.875 | 0 | 0.000% |
| keyed_list | 195.677 | 195.677 | 0 | 0.000% |
| mount_point | 80.877 | 80.877 | 0 | 0.000% |
| nested_list | 111.612 | 111.612 | 0 | 0.000% |
| node_refs | 88.216 | 88.216 | 0 | 0.000% |
| password_strength | 1712.037 | 1712.037 | 0 | 0.000% |
| portals | 91.121 | 91.121 | 0 | 0.000% |
| router | 308.771 | 308.771 | 0 | 0.000% |
| simple_ssr | 138.063 | 138.063 | 0 | 0.000% |
| ssr_router | 375.353 | 375.353 | 0 | 0.000% |
| suspense | 112.439 | 112.439 | 0 | 0.000% |
| timer | 86.486 | 86.486 | 0 | 0.000% |
| timer_functional | 95.247 | 95.247 | 0 | 0.000% |
| todomvc | 139.418 | 139.418 | 0 | 0.000% |
| two_apps | 83.573 | 83.573 | 0 | 0.000% |
| web_worker_fib | 132.149 | 132.149 | 0 | 0.000% |
| web_worker_prime | 182.645 | 182.645 | 0 | 0.000% |
| webgl | 80.607 | 80.607 | 0 | 0.000% |
✅ None of the examples has changed their size significantly.
Oh smart, will do. I didn' want to change the logic of why they kept it that way, but now without anything else happening, it does seem silly.
In a real usage with error handling, I might not want to pull the reader out till it was completed successfully, but as this doens't have that, cloning it is just a waste (and someone will handle their own stuff for that for their real usage). And debatable you should pull it out, do stuff, and handle your error accordingly. But all in all, more thinking perhaps than "just stick in the Vec" requires, heh.
On Sun, Jul 21, 2024 at 05:15 Elina @.***> wrote:
@.**** approved this pull request.
In examples/file_upload/src/main.rs https://github.com/yewstack/yew/pull/3685#discussion_r1685725333:
self.files.push(file);
self.readers.remove(&name);If you flip these two lines, you should be able to avoid the clone above. It doesn't really matter though
— Reply to this email directly, view it on GitHub https://github.com/yewstack/yew/pull/3685#pullrequestreview-2190315213, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAAANNNXYUPW6S7UXONQVLZNOQ7PAVCNFSM6AAAAABLFUUTHWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDCOJQGMYTKMRRGM . You are receiving this because you authored the thread.Message ID: @.***>