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

Improve AnyScope API #2445

Merged
merged 2 commits into from Feb 26, 2022
Merged

Improve AnyScope API #2445

merged 2 commits into from Feb 26, 2022

Conversation

AaronErhardt
Copy link
Contributor

@AaronErhardt AaronErhardt commented Feb 8, 2022

Description

  • Improve documentation
  • Add try_downcast method to AnyScope
  • Make find_parent_scope public. It could be used to find a parent component and send a message to it.

Checklist

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

Signed-off-by: Aaron Erhardt <aaron.erhardt@t-online.de>
Signed-off-by: Aaron Erhardt <aaron.erhardt@t-online.de>
@hamza1311
Copy link
Member

Make find_parent_scope public. It could be used to find a parent component and send a message to it.

Is there a reason you need this? I don't mind increasing the public API but I would like to avoid doing it for no reason.

@hamza1311 hamza1311 added the A-yew Area: The main yew crate label Feb 8, 2022
@github-actions
Copy link

github-actions bot commented Feb 8, 2022

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

https://yew-rs-api--pr2445-scope-improvements-dsua3146.web.app

(expires Tue, 15 Feb 2022 18:55:06 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@AaronErhardt
Copy link
Contributor Author

I have an application that is structured into many small components that represent parts of a (kind of huge) questionnaire. They all write the changes to the same state (using a context provider) that stores the whole data of the questionnaire. When changes occur, the data is synced automatically with the database including visual feedback that the sync operation was successful. Currently, the synchronization is handled by a component that's the parent (or the parent's parent) of the individual questionnaire parts. I just need to send it a sync message. However, to send it a message, I need to use a lot of scope.get_parent().unwrap().get_parent().unwrap().downcast().

try_downcast would be enough to implement something like find_parent_scope manually but since it's already in the private API I though it could be exposed directly.

Possibly, my implementation is just unidiomatic, but it does the job pretty well apart from the code that tries to get the correct parent component.

@hamza1311 hamza1311 requested a review from siku2 February 8, 2022 19:56
Copy link
Member

@hamza1311 hamza1311 left a comment

Choose a reason for hiding this comment

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

Looks good. I understand the reasons to expose this, sounds reasonable to me. I'll leave the final decision to @siku2

@siku2 siku2 merged commit 36058d4 into yewstack:master Feb 26, 2022
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants