GithubHelp home page GithubHelp logo

yuzygo / rxlifecycle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zhihu/rxlifecycle

0.0 2.0 0.0 238 KB

Bind observables to the lifecycle of Activity or Fragment in a non-invasive way.

Java 100.00%

rxlifecycle's Introduction

RxLifecyle is a library that can help you to unsubscribe the observable sequences automatically when a activity or fragment is destroying. There are some differences between this library and trello/RxLifecycle:

  • This library will actually unsubscribe the sequence (See here). It means that the downstream observer will not receive onComplete(), onError()... anymore when the unsubscription occurs.

  • This library doesn't require you to inherit any activity or fragment. It will insert a non-gui fragment to your activity or fragment to listen the lifecycle events.

The simplest usage:

Observable.interval(0, 2, TimeUnit.SECONDS)
        // ...
        .compose(RxLifecycle.bind(this)
                .<Long>disposeObservableWhen(LifecycleEvent.DESTROY_VIEW))
        .subscribe();

In order to make sure the downstream will not continue to emit items, you need to put the compose(RxLifecycle.bind ..) at the bottom of the chain call. See the example for learning more usages.

To integrate this library to your project, you need to add the JitPack repository to build.gradle repositories firstly.

repositories {
    maven { url "https://jitpack.io" }
}

And then add library dependencies:

dependencies {
    compile 'com.github.nekocode.rxlifecycle:rxlifecycle:{lastest-version}'
    compile 'com.github.nekocode.rxlifecycle:rxlifecycle-compact:{lastest-version}' // Optional
}

This project is licensed under Apache 2.0. The lastest version of the library is Release.

rxlifecycle's People

Contributors

nekocode avatar gejiaheng avatar

Watchers

James Cloos avatar  avatar

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.