mmaillot
01/31/2018, 8:44 PMval expressLib = require("express")
class Express(val app: dynamic = expressLib()) {
fun get(route: String, callback: (req: Request, res: Response) -> Unit) {
app.get(route, { req, res ->
val request = Request(req)
val response = Response(res)
callback(request, response)
});
}
}
class Response(private val responseJs: dynamic) {
fun send(data: String): Response {
return Response(responseJs.send(data))
}
fun json(data: Any): Response {
return Response(responseJs.send(data))
}
}
Is it a good approach ?anton.bannykh
02/01/2018, 11:08 AManton.bannykh
02/01/2018, 11:14 AMexternal
declarations instead: https://kotlinlang.org/docs/reference/js-interop.html#external-modifieranton.bannykh
02/01/2018, 11:15 AManton.bannykh
02/01/2018, 11:22 AManton.bannykh
02/01/2018, 11:23 AMmmaillot
02/01/2018, 12:42 PManton.bannykh
02/01/2018, 1:10 PManton.bannykh
02/01/2018, 1:10 PManton.bannykh
02/01/2018, 1:11 PManton.bannykh
02/01/2018, 1:11 PMmmaillot
02/01/2018, 1:57 PManton.bannykh
02/01/2018, 2:03 PMmmaillot
02/01/2018, 2:15 PMldavin
02/01/2018, 3:02 PMldavin
02/01/2018, 3:02 PMldavin
02/01/2018, 3:02 PMldavin
02/01/2018, 3:03 PManton.bannykh
02/01/2018, 3:08 PMldavin
02/01/2018, 3:42 PMldavin
02/01/2018, 3:43 PMldavin
02/01/2018, 3:43 PMldavin
02/01/2018, 3:43 PManton.bannykh
02/01/2018, 3:43 PMmmaillot
02/01/2018, 9:37 PMpackage express
@JsModule("express")
external class Express {
fun get(route: String, callback: (req: dynamic, res: Response) -> dynamic)
fun listen(port: Int, function: dynamic)
}
external class Response {
fun sendStatus(code: Int): Response
fun type(type: String): Response
fun send(data: String): Response
fun json(data: Any): Response
}
thank you!anton.bannykh
02/02/2018, 10:57 AM