Last active
August 29, 2015 14:22
-
-
Save chiquitinxx/780922395b08fcf6b19e to your computer and use it in GitHub Desktop.
Create #groovylang code that run in groovy, java and javascript environments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GrooscriptObservable.fromList(["one", "two", "three"]) | |
.take(2) | |
.subscribe({arg -> println(arg)}) | |
//In groovy and converted code in js, you get in console: | |
//one | |
//two | |
import org.grooscript.asts.GsNative | |
class GrooscriptObservable<T> { | |
def observable | |
GrooscriptObservable(List list) { | |
this.observable = platformObservable(list) | |
} | |
def methodMissing(String name, args) { | |
this.observable."$name"(*args) | |
} | |
static fromList(List list) { | |
new GrooscriptObservable(list) | |
} | |
@GsNative | |
private platformObservable(List list) {/* | |
return Rx.Observable.from(list); | |
*/ | |
Class.forName("rx.Observable").invokeMethod("from", list) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment