rxjava2和rxkotlin有什么区别?

时间:2019-04-12 05:43:20

标签: android kotlin rx-java2 rx-kotlin

rxjava2依赖性和rxkotlin依赖性之间有什么区别。  如果我使用的是rxkotlin依赖项,是否还需要添加rxjava2依赖项。

implementation 'io.reactivex.rxjava2:rxkotlin:x.y.z'
// do i need to add the below dependencies also?
implementation 'io.reactivex.rxjava2:rxjava:2.2.4'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'

4 个答案:

答案 0 :(得分:5)

  

事情是RX代表Reactive Extensions,而Rx Java代表   Rx Kotlin或Rx Swift都是Reactive的实现   该特定语言的扩展名。

什么是RxJAVA? RxJava是Reactive Extensions的Java VM实现。在这里我们可以在任何线程上创建异步数据流,对其进行转换,并且这些异步数据流可以由观察者在任何线程上使用。

什么是RxKotlin? RxKotlin是Reactive Extensions的Kotlin实现。

什么是RxAndroid? 它特定于Android平台,并在RxJava之上添加了更多类。

有关更多详细信息,请访问我的rxjava简单示例https://github.com/myJarvis/Intro_to_RxJava集合。

为了更加明确,RxKotlin具有Kotlin随附的一些方便的扩展功能。

您可以使用{RxJava&RxAndroid}或{RxKotlin}

  

您可以将RxJava与现成的Kotlin一起使用

答案 1 :(得分:3)

正如您在https://mvnrepository.com/artifact/io.reactivex.rxjava2/rxkotlin/2.3.0所看到的,# determine the nodes that have at least the minimum freq nodes_d3_min_freq <- nodes_d3 %>% filter(freq >= input$nos) # filter the edge list to contain only links to or from the nodes that have # the minimum or more freq edges_d3_filtered <- edges_d3 %>% filter(from %in% nodes_d3_min_freq$id | to %in% nodes_d3_filtered$id) # filter the nodes list to contain only nodes that are in or are linked to # nodes in the filtered edge list nodes_d3_filtered <- nodes_d3 %>% filter(id %in% unlist(select(edges_d3_filtered, from, to))) # re-adjust the from and to values to reflect the new positions of nodes in # the filtered nodes list edges_d3_filtered$from <- match(edges_d3_filtered$from, nodes_d3_filtered$id) - 1 edges_d3_filtered$to <- match(edges_d3_filtered$to, nodes_d3_filtered$id) - 1 forceNetwork(Links = edges_d3_filtered, Nodes = nodes_d3_filtered, Source = "from", Target = "to", NodeID = "label", Group = "id", Value = "value", opacity = 1, fontSize = 20, zoom = TRUE, Nodesize = "peso", arrows = TRUE) 取决于rxkotlin。因此,除非您专门排除它,否则它会自动添加为transitive dependency

不出所料,rxjava并不依赖于rxkotlin,因此如果要使用它,确实需要添加它。 rxandroidrxandroid都使用相同的rxkotlin类型,因此它们可以自由互操作。

答案 2 :(得分:2)

由于Kotlin与Java具有100%的互操作性,因此您可以毫无困难地在Kotlin项目中使用大多数Java库-RxJava库也不例外。

有一个专用的RxKotlin library,它是常规RxJava库的Kotlin包装器。该包装器提供了扩展程序,这些扩展程序针对Kotlin环境优化了RxJava,并可以进一步减少您需要编写的样板代码。

如果您使用的是rxkotlin,则只需添加以下行

implementation 'io.reactivex:rxkotlin:x.y.z'

,如果要使用rxjava2,则需要包括其他依赖项,即

implementation 'io.reactivex.rxjava2:rxjava:2.2.4'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'

但是如果您使用Kotlin作为编程语言,我建议您使用rxkotlin

更多详细信息,请参见this link

答案 3 :(得分:0)

此Android开发中的主要库为 RxJava 。由于 Kotlin 可与Java库完全互操作,因此 RxKotlin 只是原始 RxJava 的一个薄包装。

相关问题