-
-
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 in Range() implementation? #825
Comments
Can you provide the ExerciseRow component code too ? |
Of course: type ExerciseRow struct {
app.Compo
exercise models.Exercise
}
// The Render method is where the component appearance is defined.
func (h *ExerciseRow) Render() app.UI {
return app.Tr().Style("border", "1px solid black").Body(
app.Td().Style("border", "1px solid black").Body(
app.Text(h.exercise.Question),
),
app.Td().Style("border", "1px solid black").Body(
app.Text(h.exercise.Answer),
),
)
} |
Please try:
@maxence-charriere I think this is related to the problem from #767, which is still not fixed (even if it needs another way to fix it than his method). |
@oderwat This helped thank you so much! It would be good to document that :) |
@rtrzebinski please open the issue again. I am not positive, that this is a "good" way to solve it and has no unwanted side effects. I think when doing it like this you skip the "OnMount" on those components and that is not really how it should work. Likewise, I wanted @maxence-charriere to chime in on that for some time already. I think there has definitely something to be changed. |
Try to export the exercise field in the ExerciseRow component. I think the problem here is that there is nothing to compare to trigger a diff. exercise => Exercise |
Re-opening the issue as requested by @oderwat @maxence-charriere I tried that - making ExerciseRow.Exercise exported (capital letter) indeed improved adding new rows, however without the app.Range(h.rows).Slice(func(i int) app.UI {
if h.rows[i] != nil {
return h.rows[i].Render()
}
return nil
}), It was messing up indexed making deleting and display messed up again, so I'll stick with the Please let me know if you need some more examples / steps to reproduce, I am happy to provide these. |
I avoid the "Bug" in the same way. type tabs struct{
app.Compo
items []*Item
}
type Item struct{
Key string
Label string
}
func (this *tabs) Render() app.UI {
return app.Div().
Body(
app.Range(this.items).Slice(
func(i int) app.UI {
return this.renderTab(this.items[i])
}))
}
func (this *tabs) renderTab(item *Item) app.UI {
return app.Text(item.Label).
OnClick(this.onCloseTab(item), item.Key)
}
func (this *tabs) onCloseTab(item *Item) app.EventHandler {
return func(ctx app.Context, e app.Event) {
this.items = removeItemInSlice(this.items, item)
}
} |
This would mean you can't use a component in a slice and this would mean that there is something seriously missing in Go-App. What do you think @maxence-charriere |
Description:
I'm having a issue with the following code:
It works fine when the component is loaded for the first time, but not when the slice and range needs to be updated.
On rebuilding the underlying slice with data from API call, the UI behaves incorrectly.
I tried manually running
component.Update
- did not help.The only work around is reloading the page with
ctx.Reload()
but it's doing an ugly page refresh, and it's not a solution really.Steps to reproduce:
Add exercises: (question / answer):
(in order to retry with a fresh database simply run
make dev && make run
again and refresh the page)Expected result:
Exercises will appear on the list as they are added.
No manual page reload is needed to display them properly.
Actual result:
Only
11 / 11
(first one added) keeps being duplicated, regardless of the following inputs:Where is the code?
Range -> https://github.com/rtrzebinski/simple-memorizer-4/blob/58475e1c1171863229ff0de07d7f9dbb4c2c8bd4/internal/frontend/components/exercises.go#L40
Update trigger -> https://github.com/rtrzebinski/simple-memorizer-4/blob/58475e1c1171863229ff0de07d7f9dbb4c2c8bd4/internal/frontend/components/exercises.go#L71
Actual UI update -> https://github.com/rtrzebinski/simple-memorizer-4/blob/58475e1c1171863229ff0de07d7f9dbb4c2c8bd4/internal/frontend/components/exercises.go#L89
The text was updated successfully, but these errors were encountered: