I want to send Javascript code over the wire and I don't want to use the full ScalaJS compiler for that. Let's assume this scenario in the backend:
I have a service that wants to define some validations for a textbox in the frontend. My frontend is written in Javascript and gets a Javascript function from the backend in json format and use that for validation.
I want to write that function in Scala in my backend and compile it to JS using ScalaJS and put it in json and send it to my frontend:
def validation(input: String): Boolean = {
input.contains("scala is cool")
}
val jsFunctionText:Json = ScalaJSMagicCompiler.compileAndOptimizeFunction(validation)
reply(jsFunctionText)
Is there any way to do that? If not, what would be the best route to use the ScalaJS compiler to compile the function or a class and get a pointer to the output compiled file in the output folder or something?
I would rather do it at compile time but don't know if it's possible to have safe access to the generated code. something like this would be great:
@CompileAsJS("validation")
def validation(input: String): Boolean = {
input.contains("scala is cool")
}
val jsFunctionText:Json = ScalaJSMagicCompiler.retrieveFromFile("validation", "output.jar")
reply(jsFunctionText)