项目作者: toddway

项目描述 :
Rx extensions for Firebase - works for Android or Java server modules
高级语言: Kotlin
项目地址: git://github.com/toddway/FirebaseRx.git
创建时间: 2017-02-26T23:56:18Z
项目社区:https://github.com/toddway/FirebaseRx

开源协议:

下载


Features

  • Use as Kotlin extensions or static Java methods
  • Loose API coupling (should be compatible with any version of Firebase)
  • additional functions for copying, moving, and observing selective keys
  • support for Android Firebase SDK and Server Firebase SDK

Usage

Firebase Queries (or DatabaseReferences)…

Kotlin extensions:

  1. val query = FirebaseDatabase.getInstance().getReference("whatever")
  2. //observe all changes to a Firebase query
  3. val o = query.observeValue(Pojo::class.java)
  4. //observe single change to a Firebase query
  5. val o = query.observeValue(Pojo::class.java).take(1)
  6. //observe set value
  7. val o = query.setValue(new Pojo()).observeTask()
  8. //observe all children of a Firebase query as a map
  9. val o = query.observeChildMap(Pojo::class.java)
  10. //observe children of a Firebase query that match a set of keys
  11. val keys = listOf("one", "two", "five");
  12. val o = query.observeChildMap(Pojo::class.java, keys);

Java:

  1. Query query = FirebaseDatabase.getInstance().getReference("whatever");
  2. //observe all changes to a Firebase query
  3. Observable<Pojo> o = FirebaseRx.observeValue(query, Pojo.class);
  4. //observe single change to a Firebase query
  5. Observable<Pojo> o = FirebaseRx.observeValue(query, Pojo.class).take(1);
  6. //observe set value
  7. Observable<Void> o = FirebaseRx.observeSetValue(query, new Pojo());
  8. //observe all children of a Firebase query as a map
  9. Observable<Map<String, Pojo>> o = FirebaseRx.observeChildMap(query, Pojo.class);
  10. //observe children of a Firebase query that match a set of keys
  11. List<String> keys = Arrays.asList("one", "two", "five");
  12. Observable<Map<String, Pojo>> o = FirebaseRx.observeChildMap(query, Pojo.class, keys);

Tasks (e.g. authentication calls)…

Kotlin extensions:

  1. val auth = FirebaseAuth.getInstance();
  2. //observe sign in anonymously
  3. val o = auth.signInAnonymously().observeTask()
  4. //observe sign in with credential
  5. val o = auth.signInWithCredential(credential).observeTask();

Java:

  1. FirebaseAuth auth = FirebaseAuth.getInstance();
  2. //observe sign in anonymously
  3. Observable<AuthResult> o = FirebaseRx.observeTask(auth.signInAnonymously());
  4. //observe sign in with credential
  5. Observable<AuthResult> o = FirebaseRx.observeTask(auth.signInWithCredential(credential));

Install

Add jitpack to your root build.gradle:

  1. allprojects {
  2. repositories {
  3. maven { url 'https://jitpack.io' }
  4. }
  5. }

Add dependency to your Android module build.gradle:

  1. dependencies {
  2. compile ('com.github.toddway.FirebaseRx:android:X.X.X') {
  3. exclude group: 'com.google.firebase'
  4. }
  5. }

or add dependency to your Java server module build.gradle:

  1. dependencies {
  2. compile ('com.github.toddway.FirebaseRx:server:X.X.X') {
  3. exclude group: 'com.google.firebase'
  4. }
  5. }

License

  1. Copyright 2017-Present Todd Way
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.