-
-
Notifications
You must be signed in to change notification settings - Fork 373
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
bug: Stale event handlers with Range #1010
Comments
Change your code and add an event scope: ...
return app.Button().Text(name).OnClick(func(ctx app.Context, e app.Event) {
app.Log("clicked", name)
}, app.EventScope(i))
... What actually happens is something very different from what you think that happens. Basically you only have one event Handler there. When you do not only add stuff you can't use simply You can also remove |
Gotcha. When it didn't behave as I expected, I started adding log statements, and what threw me off was that the function got called with the new values, but I expected it to use the latest closure rather than the first. I looked for something like I'm just starting to try out this library, so I expected to overlook things. That said, I learned about It might be a good place to add a |
The options are "my fault". I requested some additional functionality and this hides the more obvious We developed multiple rather large products with Go-App in the last three years, and it is mostly working very well. Here are some of the most important things from my perspective:
|
I think this is the key thing to point out (maybe added to the Range doc) that in my case would have saved me some time. If that makes sense to everyone else I'm happy to add a note in there.
Ty for the tips; I did run into having trouble getting updates to happen when I expected them, but I don't remember if that was a public/private thing or what. In the end I switched to triggering an event/action to "refresh" specific things. |
About the exported (Uppercase) fields: It "overwrites" the updates silently. I think this is actually the most common problem for new users. Some people do not even "export" the fields for the component reuse, but just because they "think" that they need to be exported. Kind of like in reflections. And this is exactly the case. So the better way is to have exported fields twice and copy the value from the "external" to the "internal" state in "OnInit()" or "OnMount()". P.S.: I do not like the "event" system. To me this is just "what you are used to when using java-script". They are also not type save. We actually use simple callback functions and even global state (muhahahaaa 666). Usually sharing a package |
It seems that when using
app.Range
event handlers remain stale, even when the underlying data updates.Example app demonstrating problem
Steps to reproduce:
foo
and seeclicked foo
in the consoleShift
and observe that the button text shiftsbar
button and see it still saysclicked foo
in the consoleThe button below will "shift" the slice and the buttons update as expected. However, it appears the original click handlers are used, rather than the new ones.
I expected that the click handlers would update along with everything else.
A workaround is to embed data in the DOM and pull it back out in the event handler, but is tricky with structs or other complex types that can't be serialized easily.
The text was updated successfully, but these errors were encountered: