Git Product home page Git Product logo

rx-firebase's Introduction

Android RxFirebase

Simple and lightweight RxJava2 wrapper for use with the Android Firebase client

The Tasks API

Starting with Google Play services version 9.0.0, you can use a Task API and a number of methods that return Task or its subclasses. Task is an API that represents asynchronous method calls, similar to PendingResult in previous versions of Google Play Services.

Usage

Many of the operations can be referenced in further detail in the official documentation.

Much of this library is built around the latest changes from the RxTasks library since many of the core functions return a Task<T> result which can easily be converted to an RxJava2 type.

As such, much of the core behaviour using in previous versions of this library have been deprecated. With behaviour remaining to consume child events, and convert value events into RxJava2 types.

A common method that returns a Task is FirebaseAuth.signInAnonymously(). It returns a Task<AuthResult> which means the task will return an AuthResult object when it succeeds.

For example the Firebase sign in API asynchronously returns an AuthResult which can be consumed via toSingle method as an extension of Task<T>.

If consuming from Java code, the class RxFirebaseAuth can be used with JVM static behaviour to honour previous API contracts, however these are marked as deprecated. Extension functions of provided types should be preferred.

FirebaseAuth
  .getInstance()
  .onAuthState()
  .subscribe { /* ... */ }

FirebaseDatabase
  .getInstance()
  .getReference("server/saving-data/fireblog/posts")
  .onChildAdded<String>()
  .subscribe { /* ... */ }

Installation

dependencies {
  compile 'io.ashdavies.rx:rx-firebase:+'
}

Description

A lightweight RxJava2 wrapper for the Android Firebase client SDK, the user is expected to own the lifecycle of an asynchronous request via RxJava2 Disposable handling, however elements in this library will properly unregister listeners when a Publisher is cancelled, except in the case of value setting where it is only possible to register a listener when making the request. In this case the emitter is checked for it's subscription state.

Whilst the FirebaseDatabase api is mirrored with RxFirebaseDatabase it only really uses the database reference, this is so that the reference hierarchy can easily be traversed through child and parent elements. Methods requiring FirebaseDatabase obtain this from the DatabaseReference and allow you to chain further requests by returning itself.

Future development

Further development for this library has not been planned, and will soon become deprecated, it is recommended to use Kotlin Coroutines integration with Google Play Services Tasks API.

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.