vugu / vugu

Vugu: A modern UI library for Go+WebAssembly (experimental)
https://www.vugu.org
MIT License
4.8k stars 175 forks source link

Is there any reactivity? #200

Closed Xumeiquer closed 3 years ago

Xumeiquer commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Nice, really nice. Thank you for the explanation.