Reputation: 55
I'd like to implement the following in jruby:
ref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Object document = dataSnapshot.getValue();
System.out.println(document);
}
});
Ther ValueEventListener:
public interface ValueEventListener {
void onDataChange(DataSnapshot snapshot);
void onCancelled(DatabaseError error);
}
Upvotes: 0
Views: 57
Reputation: 55
Much simpler than I had initially assumed. Include the interface in a class with the on change method and pass in a proc to the listener.
class EventListenerValue
include com.google.firebase.database.ValueEventListener
def on_data_change(data_snapshot)
puts data_snapshot
document = data_snapshot.val
puts document
end
end
event_listener = EventListenerValue.new
ref.add_value_event_listener { |snapshot| event_listener.on_data_change(snapshot) }
Upvotes: 1