I am trying to use squirrelly in my program but wa...
# javascript
y
I am trying to use squirrelly in my program but was unable to import it as Kotlin, so reverting to use dynamic:
Copy code
val templateEngine: dynamic = js("Sqrl")
 templateEngine.render(content, tokens)
The issue is that
tokens
is a
Map<String, String>
and Sqrl is not happy with it... I used this code to workaround the issue:
Copy code
val data: dynamic = js("{}")
tokens.forEach { e -> val k = e.key; val v = e.value; js("data[k] = v") }
templateEngine.render(content, data)
which works... But this seems so hacky. Is there a better way?
👌 1
@turansky and would you mind elaborating in what a better way would be?
t
You can declare external class/interface with
iterator
operator
Example cc @Sergei Grishchenko
y
I am not sure if this will work because the API is expecting an object (= map) not an array but I guess I will give it a try
t
You can use
Record
type if you have plain
Object