I’ve just been using HandlebarsTemplates in <https...
# http4k
d
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
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
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
Can you do something with a generic instance, a map Val and a delegate?
d
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
Seems like something I might do. 😉 Whatever works for you!
d
Oh, so too horrible then!
d
YOLO!