mk-5 / gdx-fireapp

libGDX Firebase API
Apache License 2.0
65 stars 21 forks source link

Support of ChildEventListener #18

Closed xvadim closed 5 years ago

xvadim commented 5 years ago

It would be nice to have a special method for list events, i.e. support of ChildEventListener. It will allow don't read a full object via the method onDataChange, but just only newly added (or changed) data.

In this case code may look like this (in this example turns is a list of all players' turns during a game):

GdxFIRDatabase.inst().inReference("games/" + roomId + "/turns")
    .onListChanged(...)
    .then(new Consumer(...) {
    @Override
    public void onChildAdded() {
      //process a new turn
    }
   ...also: onChildChanged, onChuldRemoved, onChildMOved
    });
mk-5 commented 5 years ago

good point, thanks for an issue report.

But I really wouldn't like to break promise flow there and add some special type of Consumer. The proposition:

GdxFIRDatabase.inst()
    .inReference("something")
    .onDataChange(List.class, ChangeBehaviour.ADDED, ChangeBehaviour.REMOVED...)
    .then(...)

Maybe something like that should do the trick, what do you think? The ChangeBehaviour varargs argument will be optional.

xvadim commented 5 years ago

Hi, your proposition looks good.

Btw, is your email still the same: git@mk5.pl ?

mk-5 commented 5 years ago

yes, git@mk5.pl is a valid email.

Okay, so that will be next feature - I'll do that soon

mk-5 commented 5 years ago

hello, I'm back with good news. Please check the latest 2.1.0 version, I've added brand new onChildChange method to the API.

Example of usage:

GdxFIRDatabase.inst()
    .inReference("users")
    .onChildChange(List.class, ChildEventType.ADDED, ChildEventType.REMOVED)
    .then(new Consumer<List<User>>() {
        @Override
        @MapConversion(User.class)
        public void accept(List<User> user) {
        }
})
xvadim12 commented 5 years ago

Thanks a lot! Will try.

xvadim commented 5 years ago

It works! Thanks a lot!