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

Is there any reactivity? #200

Closed
Xumeiquer opened this issue Apr 26, 2021 · 3 comments
Closed

Is there any reactivity? #200

Xumeiquer opened this issue Apr 26, 2021 · 3 comments

Comments

@Xumeiquer
Copy link

Question
I would like to know if there are any kind of reactivity in Vugu. For example, imagine the following code:

<div vg-content='c.Price()'></div>
<button @click='c.SetPrice(event)'>Set Price</button>

Will the c.Price() be called after the c.SetPrice sets a value on a interval variable (the same one the uses c.Price)?

Is your question related to a problem? Please describe.
No, as far as I know

Suggested Changes
None at the moment

Additional context
Nothing.

@Nv7-GitHub
Copy link

I believe so, although I don't know if this is true. From what I know, first, it will call c.SetPrice(event). Then, using the updated data, it will re-render the page.

@bradleypeabody
Copy link
Contributor

Yes. It probably should be stated more explicitly on this page https://www.vugu.org/doc/dom-events but this should work as you are expecting. There are two things that cause a re-render: 1. Any DOM event, as soon as the handler exits causes a re-render, or 2. You can use EventEnv.Lock()/UnlockRender() to tell it to explicitly re-render (useful from goroutines).

In your example above c.SetPrice(event) will be called and as soon as it exits a render will occur and c.Price() will be called again.

@Xumeiquer
Copy link
Author

Nice, really nice. Thank you for the explanation.

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

No branches or pull requests

3 participants