Search code examples
androidkotlinrxjsduktape

Run rxjs in kotlin using Duktape Android return SyntaxError


I try to run simple script of rxjs in android application using duktape-android library and I can not find it a way to go.

val duktape = Duktape.create()
implementConsole(duktape)

duktape.evaluate("global = {}")
duktape.evaluate(loadData("rxjs.umd.min.js"))
run(duktape)

I put in asserts of application the minim version of rxjs. I implemented the console, set the global context and the I try to call some functions from file. This is my run method :

private fun run(duktape: Duktape) {
    duktape.evaluate("""
      const range = rxjs;
      const filter = rxjs.operators;
      const map = rxjs.operators;
      range(1, 200).pipe(
        filter(x => x % 2 == 1),
        map(x => x + x)
      ).subscribe(x => console.log(x));
      """) }

The result is DuktapeException: SyntaxError: parse error (line 6). Line is the line where filter function is called.

Any idea how should be the syntax for calling functions from rxjs using duktape-android?


Solution

  • duktape only supports ES5, which means there's no support for array functions. See also the compatibility chapter: https://duktape.org/guide.html#compatibility