Code Monkey home page Code Monkey logo

rxcommon's Introduction

RxCommon

A multi-platform ReactiveX implementation targetting JVM, iOS, Android, and JS.

More targets can be added upon request.

Documentation

Please refer to https://reactivex.io for documentation.

Sources

The reactivex documentation covers much of the functionality. If there are any significant discrepancies, excluding those illuminated within this documentation, please post an issue.

  • Observable
  • Single - Similar to observable, but will complete when the first value is emitted.
  • BehaviorRelay - Subject which ignores all notifications. Relays retain and emit the latest element.
  • BehaviorSubject - Similar to the BehaviorRelay, but acknowledges notifications
  • PublishSubject
  • More coming, new collaborators / contributions are greatly appreciated.

Operators

More operators are coming quickly, but not all have been implemented.

Currently supported operators:

Examples

Single(just = "hello")
  .map { "$it world" }
  .subscribe(NextObserver { result ->
    // result => "hello world"
  })

/* Be sure to dispose when this is no longer needed to prevent leaks. */
val disposable = Observable<String>(createWithEmitter = { emitter ->
  emitter.next("we're happy")
  emitter.next("la la la")

  Disposables.create {
    /*
     * This block is called when this cold observable loses all of its observers or
     * a notification is received. Use this to clean up any open connections, etc.
     */
  }
}).flatMap { happyText ->
  /* Use the text to maybe fetch something from an api. */
  return@flatMap Single<String>(error = UnauthorizedException()) // Uh oh, expired access
    .onErrorReturn { throwable ->
      /* Handle throwable, maybe check for unauthorized and recover */
      return@onErrorReturn Single(just = "$happyText recovery")
    }
}.subscribe(NextTerminalObserver({ emission ->
  /*
   * emission => "we're happy recovery"
   * emission => "la la la recovery"
   */
}, { throwable ->
  /* No terminal notifications in this example */
}))

Installing

Please ensure you're using gradle 5.3+.

Installing has recently become significantly easier. Now it's as simple as including the following:

Kotlin Build Script

kotlin {
    sourceSets {
        val commonMain by getting {
            dependencies {
                api("com.noheltcj:rxcommon:0.7.0")
            }
        }
    }
}

Groovy Build Script

kotlin {
    sourceSets {
        commonMain {
            dependencies {
                api 'com.noheltcj:rxcommon:0.7.0'
            }
        }
    }
}

Kotlin Support Map (For Native)

Since native modules require dependencies to be compiled with the same kotlin version, we will be keeping up with this support map going forward.

0.4.2 -> 1.3.20
0.5.0 -> 1.3.21
0.5.1 -> 1.3.21
0.5.2 -> 1.3.30
0.5.3 -> 1.3.31
0.6.0 -> 1.3.50
0.6.1 -> 1.3.61
0.7.0 -> 1.4.30

Objective-C Generics

Objective-c only has partial generics support, so we lose a bit of information when this library is imported as a framework in XCode.

To help with this, when you produce an Objective-C framework, be sure to enable generics support.

components.main {
    outputKinds("framework")
    extraOpts "-Xobjc-generics"
}

Concurrency

This library doesn't support concurrency. In the majority of cases, concurrency is a side effect that can be handled on the platform. If you are doing anything that requires a significant amount of time to operate, it's important to do this work off the main thread (Especially if your application has a user interface). Of course do that using other resources such as RxSwift, RxJava, or basic platform concurrency frameworks, but ensure you've returned to the main thread before re-entering the common code.

rxcommon's People

Contributors

noheltcj avatar erickaguila18 avatar hiosdra avatar

Watchers

James Cloos 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.