GithubHelp home page GithubHelp logo

rxjava-gwt's Introduction

RxJava GWT

Maven Central Build Status Join the chat

Compatibility pack and minimal GWT dependant code to make RxJava works in GWT. This includes, some missing JDK emulation (most of them from java.util.concurrent). Some minor changes from RxJava that might be eventually applied directly to RxJava. And some super-sources and a JavaScript friendly Scheduler to adapt RxJava to the browser.

Getting started

The best way to get started with RxJava GWT is to download and run some examples like RxSnake, RxBreakout, RxCanvas or just find for rxjava+gwt in github. Most of them can be tried by cloning and executing mvn gwt:devmode.

You should note that most of the GWT specific utilities are in RxGWT. So you probably want to depend on RxGWT instead of RxJava GWT, which includes common utils like event handlers adapter, request adapters, more advanced schedulers, etc. All those examples depends on RxGWT.

RxGWT contains basic utilities to make arbitrary XHR request, but if you want a typed API or you want to communicate between client and server you should take a look to AutoREST, a REST API lib with RxJava support. Nominatim is a example using the same JAX-RS and RxJava friendly API in JRE (client), JEE (server), Android and GWT.

If you use GWT RPC, you can use AutoRPC to generate RxJava friendly async interfaces automatically.

Download

Releases deployed to the Central Repository

Snapshots of the development version available in Sonatype's snapshots repository.

Goals

  • Use same RxJava API in the client side
  • Improve RxJava GWT performance (emulate classes)
  • Make original RxJava project GWT compatible

Source code folders

The 'super' and 'modified' folders are both super-sources, but they are separated because the 'super' contains emulations that can be eventually merged into GWT and 'modified' contains RxJava changes that can be eventually merged into RxJava project. Leaving this project with only GWT specific code and just a few super sources to fix scheduling incompatibilities and reasonable performance improvements.

Profiling with d8

Install V8 and create aliases for d8 and xxx-tick-processor.

mvn -Dd8 package
cd target/d8/perf
d8 -prof --log-timer-events perf.nocache.js
tick-processor --source-map=../../gwt/deploy/perf/symbolMaps/<HASH>_sourceMap0.json v8.log

Install V8 on Mac Profiling GWT applications with v8 and d8 Performance Tips for JavaScript in V8

Why did I start this project?

This is an old story not useful to understand anything about the project, hehe but I like to remember why I started it :bowtie:

My primary goal to start this project was to have a shared (between client and server) type safe Promise implementation. This promises most of the time are server request calls, and most of this request returns a collection of items (zero or one are collections too ๐Ÿ˜ฌ). So I end up with the conclusion that Observables was an elegant solution to my problem. With Observables, you can define your shared API and provides a Promise like API to handle and compose responses (composition was the primary motivation to use promises, if you don't need composition callbacks are probably enough). So you can define service like this:

public interface FilesService extends DirectRestService {
    @GET @Path("/files") public Observable<FileVO> files(@QueryParam("matches") String matches);
}

And can be used like:

// simple: request one file and show
filesService.files("/one.file").subscribe(resultBox::showFile);

// advanced: request 10 files each time search box changes, canceling previous and showing the results
Observable<String> searchText = RxUser.bindValueChange(searchBox);
Observable<List<String>> searchResult = searchText
    .switchMap(matches -> filesService
        .files(matches).observeOn(Schedulers.compute())
        .map(Tools::heavyWeightOperation).take(10).toList())
    .share();
searchResult.subscribe(resultBox::showFiles);    

This is pretty awesome and powerful, as RxJava requires subscription and notify un-subscriptions, it makes request composition easy and safer because you can clean up resources without an annoying API, canceling the any pending request as soon as the un-subscriptions is notified, and you get it almost for free. Also, if you have some heavyweight operation, you can process it progressively without locking up the main loop (in the example above, it's done using the observeOn operator), and finally reduce the result into a list to show the final result in a resultBox.

Note: AutoREST GWT implements the shareable JAX-RS interface using RxJava in the client side and RxGWT exposes a lot of common tools like the 'RxUser.bindValueChange' in the code example.

rxjava-gwt's People

Contributors

gitter-badger avatar hpehl avatar ibaca avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxjava-gwt's Issues

RxJava 2.0

Hi
I'm just started with RxJava on the server side and GWT on the client side.
RxJava GWT looks like just what I need next. However, I really would like to use RxJava 2.0. Any thoughts/progress on that?
Thanks!

Repository with GWT 2.8.2-rx1 is returning 400 Bad Request

Hello,

the repository that is required to use GWT 2.8.2-rx1 is not working right now.
Accessing URL https://raw.githubusercontent.com/intendia-oss/rxjava-gwt/mvn-repo/ returns 400: Bad Request with no detail on how to fix it.

Can you please advice on how to fix the problem or fix it yourselves?
Thank you.

Sincerely yours,
Tomas Rohrbacher

JsInterop Compatibility

Hi,

this is more a question than an actual issue. We are building a shared library between server, web (gwt), mobile(android and ios(j2objc)). I am looking for an elegant pattern for async code in our library.
On the web, we are using gwt only for our logic layer and exposing all functions with jsinterop. With rxjava-gwt we'll be able to use rxjava in the gwt part of the app, but I am curious if it was possible to also access this from javascript directly. I know there is RxJs for javascript and a try to make this accessible in java (https://gist.github.com/bsorrentino/f678d415432a6f63503bbf8268c00cd8) but this is probably not compatible.

So this is more a question if you have any experience with this? Is this even possible? Or is it easier to build some wrappers that connect both?

Thanks for the great library :)
Regards,
arne

GWT 2.8.0 compatibility

Hi,

In my current GWT 2.0.8 project, merely adding the dependency for rxjava-gwt:1.0.14-beta1, together with the in my module descriptor, kills the GWT compiler:

[ERROR] Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
[ERROR] at java.util.Arrays.copyOfRange(Arrays.java:3664)
[ERROR] at java.lang.String.(String.java:207)
[ERROR] at java.lang.StringBuilder.toString(StringBuilder.java:407)
[ERROR] at com.google.gwt.dev.javac.JdtUtil.signature(JdtUtil.java:361)
[ERROR] at com.google.gwt.dev.jjs.impl.ReferenceMapper.get(ReferenceMapper.java:99)
[ERROR] at com.google.gwt.dev.jjs.impl.GwtAstBuilder$AstVisitor$JsniReferenceCollector.endVisit(GwtAstBuilder.java:314)
[ERROR] at com.google.gwt.dev.js.ast.JsNameRef.traverse(JsNameRef.java:113)
[ERROR] at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:467)
[ERROR] at com.google.gwt.dev.js.ast.JsModVisitor$NodeContext.traverse(JsModVisitor.java:153)
[ERROR] at com.google.gwt.dev.js.ast.JsModVisitor.doAccept(JsModVisitor.java:176)
[ERROR] at com.google.gwt.dev.js.ast.JsVisitor.accept(JsVisitor.java:109)
[ERROR] at com.google.gwt.dev.js.ast.JsInvocation.traverse(JsInvocation.java:88)
[ERROR] at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:467)

any Ideas ?

regards

~Chris

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.