GithubHelp home page GithubHelp logo

androidautodispose's Introduction

AndroidAutoDispose

中文说明

Easy way to auto dispose rxjava2 with android lifecycle event

AndroidLifeCycle is an android tool for auto dippose rxjava2 disposable when target android lifecycle event arrive.

Overview

Work with AndroidLifecycle and AutoDispose, auto dispose with bound fragment, activity, context or view lifecycle event.

Motivations

Lifecycle management with RxJava and Android is nothing new, so why yet another tool? You can see this in uber AutoDispose readme #Motivations. In short, you should add disposable manually, or use RxLifecycle. Previous not elegant. To use RxLifecycle correct, compose() needed to be as close to the subscribe() call as possible to properly wrap upstream. And Single or Completable dispose always throw CancellationException, you should always remember handle it. This limit make it was risky to use (particularly in a large team with varying levels of RxJava experience). But in this library, you can only listen event at flow last, you can also register global outsideLifecycleExcepitonHandler by AutoDisposePlugins.setOutsideLifecycleHandler, ignore lots of risk.

Usage

Bind myObservable with myFragment destroy event

myObservable
    .doStuff()
    .to(AndroidRxDispose.withObservable(myFragment, FragmentEvent.DESTROY))   // The scope
    .subscribe(s -> ...);

Bind mySingle with myView attached activity pause event

mySingle
    .doStuff()
    .to(AndroidRxDispose.withSingle(myView, ViewEvent.PAUSE))   // The scope
    .subscribe(s -> ...);

Bind myCompletable with myView attached fragment stop event

AndroidLifeCycle.bindFragment(myView, myFragment);

myCompletable
    .doStuff()
    .to(AndroidRxDispose.withCompletable(myView, ViewEvent.STOP))   // The scope
    .subscribe(s -> ...);

Support Rxjava2 Observable, Single, Completable, Maybe, Flowable

Download

Maven Central

compile 'com.github.ykrank:androidautodispose:x.y.z'

License

Copyright (C) 2017 Yk Rank

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

androidautodispose's People

Contributors

ykrank avatar

Stargazers

 avatar  avatar LingYFH avatar icedcap avatar HuangFuSheng avatar Tijn avatar Wuhaha avatar 周游 avatar coder avatar  avatar Noriyoshi Fukuzaki avatar  avatar adon avatar 暗风吹雨 avatar  avatar  avatar Eric avatar  avatar  avatar

Watchers

coder avatar  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.