How to render a seed for each element in a collection? #20
-
Two topics today! In VueJS we can do something like:
I found
The above should work great if we have a static set of "todos", but imagine we want the "todos" to be loaded from the server instead. My first thought is to try using
Both ways don't quite feel right. What is the qlovaseed'y pattern here? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is actually quite a challenging use-case, as until we get generics later this year, there are no type-safe clientside collections. The best thing you can do at the moment is to use 'feeds' (qlova.org/seed/new/feed). Feeds are like repeaters but for dynamic collections. package main
import (
"image/color"
"qlova.org/seed/client"
"qlova.org/seed/new/app"
"qlova.org/seed/new/button"
"qlova.org/seed/new/feed"
"qlova.org/seed/new/text"
"qlova.org/seed/set/align"
"qlova.org/seed/use/js"
"qlova.org/seed/use/js/console"
)
func main() {
//Create a new feed of 'values'
var values = feed.With(func() []string {
//return type can be any json-serialisable slice.
return []string{"a", "b", "c"}
})
app.New("Feed",
button.New(text.Set("Click me"), client.OnClick(values.Refresh())),
//Create a template that will be repeated for each element of 'values'
values.New(align.Center(),
//Here we cast the current elements value into a javascript 'client' string.
text.New(text.SetStringTo(js.String{Value: values.Data.GetValue()})),
text.New(text.Set("hello"), text.SetColor(color.NRGBA{255, 0, 0, 255}),
client.OnClick(console.Log(values.Data)),
),
),
).Launch()
} Feeds don't have a developer-friendly way of reading values yet (you need to cast the values to js.Value) and there is no type safety. This is still an area of investigation for Qlovaseed. |
Beta Was this translation helpful? Give feedback.
This is actually quite a challenging use-case, as until we get generics later this year, there are no type-safe clientside collections.
The best thing you can do at the moment is to use 'feeds' (qlova.org/seed/new/feed). Feeds are like repeaters but for dynamic collections.