https://kotlinlang.org logo
#http4k
Title
# http4k
d

dmcg

12/03/2021, 8:41 AM
I’ve just been using HandlebarsTemplates in

https://youtu.be/MxzAr4UBOs0

. Which leads me to ask the question, why does there need to be a ViewModel type?
d

dave

12/03/2021, 8:17 PM
There's not much to it apart from being able to set the name of the template file used when rendering.
Aka Seemed like a reasonable idea at the time...
d

dmcg

12/03/2021, 8:18 PM
It’s just a bit of a pain to have to extend a type when I could be using Map
and maybe telling you where to find the template
d

dave

12/03/2021, 8:20 PM
Can you do something with a generic instance, a map Val and a delegate?
d

dmcg

12/03/2021, 8:21 PM
Now I know there’s nothing intrinsic I’ll look at how to fudge it
Good evening BTW
It seems to be putting the cart before the horse, but is this too horrible?
Copy code
fun <K, V> Map<K, V>.asViewModel(template: String): ViewModel = object: ViewModel, Map<K, V> by this@asViewModel {
    override fun template() = template
}
d

dave

12/03/2021, 8:50 PM
Seems like something I might do. 😉 Whatever works for you!
d

dmcg

12/03/2021, 8:50 PM
Oh, so too horrible then!
d

dave

12/03/2021, 8:55 PM
YOLO!