These are chat archives for ReactiveX/RxJava

20th
Sep 2018
Incubator
@incube8r
Sep 20 2018 19:57
Hello
Aadi Deshpande
@cilquirm
Sep 20 2018 20:05
Hi, i'm having trouble mapping a flowable. I am getting an error that I kinda sorta understand but I can't understand why I 'm getting it:
[Java] The parameterized method <Tuple2<Entity,SourceEntry>>map(Function<? super Entity,? extends Tuple2<Entity,SourceEntry>>) of type Flowable<Entity> is not applicable for the arguments (Function<Entity,Tuple2<Entity,SourceEntry>>)
Incubator
@incube8r
Sep 20 2018 20:07

Hello, in this code (below), is it possible get the FileObject (also), I mean to subscribe to get it?)

public Single<Boolean> uploadFile(String entityType, String entityId, String blobName){
    return Single.create(e -> {
        uploadElement = DOM.createElement("input");
        uploadElement.setAttribute("type", "file");
        uploadElement.setAttribute("accept", "*/*");;
        Event.sinkEvents(uploadElement, Event.ONCHANGE);
        Event.setEventListener(uploadElement, event -> {
            final FileObject fileObject = (FileObject) getFile(event);
            readAsDataURL((FileObject) fileObject, new FileReaderCallback() {
                @Override
                public void onLoad(String data) {
                        Entity entity = new Entity(entityType);
                        entity.setEntityId(entityId);
                        entity.setBlobProperty(blobName, data).subscribe(isSuccess -> {
                            e.onSuccess(isSuccess);
                        }, error -> {
                            e.onError(error);
                        });
                }
            });
        });
        click();
    });
}

Or I have to change the Single<Boolean> to something else that will be able to get the FileObject and pass it one.onSuccess?

Ignacio Baca Moreno-Torres
@ibaca
Sep 20 2018 20:09
Something eles? Hehe just use Single<FileObject>
Incubator
@incube8r
Sep 20 2018 20:10
I also need to get the boolean status
so I have to create a POJO to have both Boolean and FileObject at the same time?
Ignacio Baca Moreno-Torres
@ibaca
Sep 20 2018 20:11
Boolean status? It is always true, this is not a status
Incubator
@incube8r
Sep 20 2018 20:12
the method entity.setBlobProperty emits isSuccess which is the status either true or false
Ignacio Baca Moreno-Torres
@ibaca
Sep 20 2018 20:12
You are also adding a listener and never removing it, use the rxgwt utilities for observing event which handle that correctly
Oh I see, and this is an Observable? Remember, never ever subscribe inside another subscription, use flap Map instead
RxJava is like callback on steroids, so whenever you see a callback you can trivially wrap it as a RxJava type, readasdataurl has a callback, so wrap it as a rxtype and flatMap too (when I say flatMap, you can use the one you need, flatMap, concatMap, switchMap...)
Incubator
@incube8r
Sep 20 2018 20:19
problem here is that Event.setEventListener blocking that chain
I mean I can't do return Observable... inside that anonymous class
I could flatMap outside but the typed return would change
Ignacio Baca Moreno-Torres
@ibaca
Sep 20 2018 20:21
use RxGWT, then flapMap the event with the ReadAsDatUrl Observable wrapper
Incubator
@incube8r
Sep 20 2018 20:27
can you show me how to do this the right way using the RxGWT utilities?
Ignacio Baca Moreno-Torres
@ibaca
Sep 20 2018 21:23
:grimacing: sorry I'm out, but yep I'll help you tomorrow :wink: