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

Explain yield and yield from more #554

Closed
wwwillchen opened this issue Jun 28, 2024 · 3 comments
Closed

Explain yield and yield from more #554

wwwillchen opened this issue Jun 28, 2024 · 3 comments
Assignees
Labels
docs Improvements or additions to documentation

Comments

@wwwillchen
Copy link
Collaborator

wwwillchen commented Jun 28, 2024

https://google.github.io/mesop/guides/interactivity/

From chat:

yeah, this part is a bit confusing unless you're familiar with Python generators.

Essentially an event handler function e.g. on_click can be a regular function or a generator function (i.e. uses yield)

Sometimes, you may want to share logic between multiple event handler functions, so you'll extract it into a method like:

def submit()
   s = me.state(State)
   s.is_loading = True
   yield
   s.content = call_llm()
   s.is_loading=False
   yield

because submit itself is a generator function, you can't just call it like a normal python function (e.g. submit()), instead you need to do yield from submit() this way the yields in submit run as expected

@wwwillchen wwwillchen added the docs Improvements or additions to documentation label Jun 28, 2024
@pranshu-raj-211
Copy link

I'd love to work on this and I'm familiar with generators.
Could you please describe what exactly you want to have in the docs, for example you mentioned multiple callback functions using the same code essentially, should there be examples of wrapper functions too.

@wwwillchen
Copy link
Collaborator Author

Hi @pranshu-raj-211 - thanks for volunteering. I think showing examples of having multiple callback functions reuse the same code would be great.

Could you clarify what you mean by wrapper functions? Please feel free to send a PR to update our docs:

and I'd be happy to review - thanks!

@wwwillchen
Copy link
Collaborator Author

Updated docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants