RxSwiftCommunity/RxSwiftExt là dự án mã nguồn mở trên GitHub, viết chủ yếu bằng Swift, với 1.4k sao. A collection of Rx operators & tools not found in the core RxSwift distribution
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
If you're using RxSwift, you may have encountered situations where the built-in operators do not bring the exact functionality you want. The RxSwift core is being intentionally kept as compact as possible to avoid bloat. This repository's purpose is to provide additional convenience operators and Reactive Extensions.
Installation
This branch of RxSwiftExt targets Swift 5.x and RxSwift 5.0.0 or later.
If you're looking for the Swift 4 version of RxSwiftExt, please use version 3.4.0 of the framework.
CocoaPods
Add to your Podfile:
pod 'RxSwiftExt', '~> 5'
This will install both the RxSwift and RxCocoa extensions.
If you're interested in only installing the RxSwift extensions, without the RxCocoa extensions, simply use:
pod 'RxSwiftExt/Core'
Using Swift 4:
pod 'RxSwiftExt', '~> 3'
Carthage
Add this to your Cartfile
github "RxSwiftCommunity/RxSwiftExt"
Operators
RxSwiftExt is all about adding operators and Reactive Extensions to RxSwift!
Operators
These operators are much like the RxSwift & RxCocoa core operators, but provide additional useful abilities to your Rx arsenal.
unwrap
ignore
ignoreWhen
Observable.once
distinct
map
not
and
Observable.cascade
pairwise
nwise
retry
repeatWithBehavior
catchErrorJustComplete
pausable
pausableBuffered
apply
filterMap
Observable.fromAsync
Observable.zip(with:)
Observable.merge(with:)
count
partition
bufferWithTrigger
There are two more available operators for materialize()'d sequences:
errors
elements
Read below for details about each operator.
Reactive Extensions
RxSwift/RxCocoa Reactive Extensions are provided to enhance existing objects and classes from the Apple-ecosystem with Reactive abilities.
Sequentially cascade through a list of observables, dropping previous subscriptions as soon as an observable further down the list starts emitting elements.
let a = PublishSubject<String>()
let b = PublishSubject<String>()
let c = PublishSubject<String>()
Observable.cascade([a,b,c])
.subscribe { print($0) }
a.onNext("a:1")
a.onNext("a:2")
b.onNext("b:1")
a.onNext("a:3")
c.onNext("c:1")
a.onNext("a:4")
b.onNext("b:4")
c.onNext("c:2")
next(a:1)
next(a:2)
next(b:1)
next(c:1)
next(c:2)
pairwise
Groups elements emitted by an Observable into arrays, where each array consists of the last 2 consecutive items; similar to a sliding window.
Repeats the source observable sequence using given behavior in case of an error or until it successfully terminated.
There are four behaviors with various predicate and delay options: immediate, delayed, exponentialDelayed and
customTimerDelayed.
// in case of an error initial delay will be 1 second,
// every next delay will be doubled
// delay formula is: initial * pow(1 + multiplier, Double(currentAttempt - 1)), so multiplier 1.0 means, delay will doubled
_ = sampleObservable.retry(.exponentialDelayed(maxCount: 3, initial: 1.0, multiplier: 1.0), scheduler: delayScheduler)
.subscribe(onNext: { event in
print("Receive event: \(event)")
}, onError: { error in
print("Receive error: \(error)")
})
Receive event: First
Receive event: Second
Receive event: First
Receive event: Second
Receive event: First
Receive event: Second
Receive error: fatalError
repeatWithBehavior
Repeats the source observable sequence using given behavior when it completes. This operator takes the same parameters as the retry operator.
There are four behaviors with various predicate and delay options: immediate, delayed, exponentialDelayed and customTimerDelayed.
// when the sequence completes initial delay will be 1 second,
// every next delay will be doubled
// delay formula is: initial * pow(1 + multiplier, Double(currentAttempt - 1)), so multiplier 1.0 means, delay will doubled
_ = completingObservable.repeatWithBehavior(.exponentialDelayed(maxCount: 3, initial: 1.0, multiplier: 1.2), scheduler: delayScheduler)
.subscribe(onNext: { event in
print("Receive event: \(event)")
})
Receive event: First
Receive event: Second
Receive event: First
Receive event: Second
Receive event: First
Receive event: Second
catchErrorJustComplete
Completes a sequence when an error occurs, dismissing the error condition
next(First)
next(Second)
Source observable emitted error fatalError, ignoring it
completed
pausable
Pauses the elements of the source observable sequence unless the latest element from the second observable sequence is true.
let observable = Observable<Int>.interval(1, scheduler: MainScheduler.instance)
let trueAtThreeSeconds = Observable<Int>.timer(3, scheduler: MainScheduler.instance).map { _ in true }
let falseAtFiveSeconds = Observable<Int>.timer(5, scheduler: MainScheduler.instance).map { _ in false }
let pauser = Observable.of(trueAtThreeSeconds, falseAtFiveSeconds).merge()
let pausedObservable = observable.pausable(pauser)
let _ = pausedObservable
.subscribe { print($0) }
next(2)
next(3)
More examples are available in the project's Playground.
pausableBuffered
Pauses the elements of the source observable sequence unless the latest element from the second observable sequence is true. Elements emitted by the source observable are buffered (with a configurable limit) and "flushed" (re-emitted) when the observable resumes.
Examples are available in the project's Playground.
apply
Apply provides a unified mechanism for applying transformations on Observable
sequences, without having to extend ObservableType or repeating your
transformations. For additional rationale for this see
discussion on github
// An ordinary function that applies some operators to its argument, and returns the resulting Observable
func requestPolicy(_ request: Observable<Void>) -> Observable<Response> {
return request.retry(maxAttempts)
.do(onNext: sideEffect)
.map { Response.success }
.catchError { error in Observable.just(parseRequestError(error: error)) }
// We can apply the function in the apply operator, which preserves the chaining style of invoking Rx operators
let resilientRequest = request.apply(requestPolicy)
filterMap
A common pattern in Rx is to filter out some values, then map the remaining ones to something else. filterMap allows you to do this in one step:
// keep only even numbers and double them
Observable.of(1,2,3,4,5,6)
.filterMap { number in
(number % 2 == 0) ? .ignore : .map(number * 2)
}
The sequence above keeps even numbers 2, 4, 6 and produces the sequence 4, 8, 12.
errors, elements
These operators only apply to observable sequences that have been materialized with the materialize() operator (from RxSwift core). errors returns a sequence of filtered error events, ommitting elements. elements returns a sequence of filtered element events, ommitting errors.
let imageResult = _chooseImageButtonPressed.asObservable()
.flatMap { imageReceiver.image.materialize() }
.share()
let image = imageResult
.elements()
.asDriver(onErrorDriveWith: .never())
let errorMessage = imageResult
.errors()
.map(mapErrorMessages)
.unwrap()
.asDriver(onErrorDriveWith: .never())
fromAsync
Turns simple asynchronous completion handlers into observable sequences. Suitable for use with existing asynchronous services which call a completion handler with only one parameter. Emits the result produced by the completion handler then completes.
func someAsynchronousService(arg1: String, arg2: Int, completionHandler:(String) -> Void) {
// a service that asynchronously calls
// the given completionHandler
}
let observableService = Observable
.fromAsync(someAsynchronousService)
observableService("Foo", 0)
.subscribe(onNext: { (result) in
print(result)
})
.disposed(by: disposeBag)
zip(with:)
Convenience version of Observable.zip(_:). Merges the specified observable sequences into one observable sequence by using the selector function whenever all
of the observable sequences have produced an element at a corresponding index.
let first = Observable.from(numbers)
let second = Observable.from(strings)
first.zip(with: second) { i, s in
s + String(i)
}.subscribe(onNext: { (result) in
print(result)
})
next("a1")
next("b2")
next("c3")
merge(with:)
Convenience version of Observable.merge(_:). Merges elements from the observable sequence with those of a different observable sequences into a single observable sequence.
let oddStream = Observable.of(1, 3, 5)
let evenStream = Observable.of(2, 4, 6)
let otherStream = Observable.of(1, 5, 6)
oddStream.merge(with: evenStream, otherStream)
.subscribe(onNext: { result in
print(result)
})
1 2 1 3 4 5 5 6 6
ofType
The ofType operator filters the elements of an observable sequence, if that is an instance of the supplied type.
Emits the number of items emitted by an Observable once it terminates with no errors. If a predicate is given, only elements matching the predicate will be counted.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/RxSwiftCommunity/RxSwiftExt là nguồn chính thức.
RxSwiftCommunity/RxSwiftExt có bao nhiêu sao?
RxSwiftCommunity/RxSwiftExt có 1.4k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/RxSwiftCommunity/RxSwiftExt. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
RxSwiftCommunity/RxSwiftExt có phải mã nguồn mở không?
Có — RxSwiftCommunity/RxSwiftExt phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/RxSwiftCommunity/RxSwiftExt.
RxSwiftCommunity/RxSwiftExt còn đang phát triển không?
Commit gần nhất trên RxSwiftCommunity/RxSwiftExt là 2.9 năm trước (theo timestamp GitHub). Repo có 217 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
RxSwiftCommunity/RxSwiftExt dùng license gì?
RxSwiftCommunity/RxSwiftExt phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
RxSwiftCommunity/RxSwiftExt là gì?
RxSwiftCommunity/RxSwiftExt (RxSwiftCommunity/RxSwiftExt) là dự án Swift trên GitHub. Theo mô tả gốc: A collection of Rx operators & tools not found in the core RxSwift distribution
RxSwiftCommunity/RxSwiftExt viết bằng ngôn ngữ gì?
RxSwiftCommunity/RxSwiftExt chủ yếu viết bằng Swift. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về RxSwiftExt?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về RxSwiftExt.