Updates documentation for 3.0.0.alpha.1
This commit is contained in:
parent
87b792e54d
commit
72122e3e43
|
|
@ -67,32 +67,32 @@ These are called marble diagrams. There are more marble diagrams at [rxmarbles.c
|
|||
|
||||
If we were to specify sequence grammar as a regular expression it would look like:
|
||||
|
||||
**Next* (Error | Completed)?**
|
||||
**next* (error | completed)?**
|
||||
|
||||
This describes the following:
|
||||
|
||||
* **Sequences can have 0 or more elements.**
|
||||
* **Once an `Error` or `Completed` event is received, the sequence cannot produce any other element.**
|
||||
* **Once an `error` or `completed` event is received, the sequence cannot produce any other element.**
|
||||
|
||||
Sequences in Rx are described by a push interface (aka callback).
|
||||
|
||||
```swift
|
||||
enum Event<Element> {
|
||||
case Next(Element) // next element of a sequence
|
||||
case Error(Swift.Error) // sequence failed with error
|
||||
case Completed // sequence terminated successfully
|
||||
case next(Element) // next element of a sequence
|
||||
case error(Swift.Error) // sequence failed with error
|
||||
case completed // sequence terminated successfully
|
||||
}
|
||||
|
||||
class Observable<Element> {
|
||||
func subscribe(observer: Observer<Element>) -> Disposable
|
||||
func subscribe(_ observer: Observer<Element>) -> Disposable
|
||||
}
|
||||
|
||||
protocol ObserverType {
|
||||
func on(event: Event<Element>)
|
||||
func on(_ event: Event<Element>)
|
||||
}
|
||||
```
|
||||
|
||||
**When a sequence sends the `Completed` or `Error` event all internal resources that compute sequence elements will be freed.**
|
||||
**When a sequence sends the `completed` or `error` event all internal resources that compute sequence elements will be freed.**
|
||||
|
||||
**To cancel production of sequence elements and free resources immediately, call `dispose` on the returned subscription.**
|
||||
|
||||
|
|
@ -116,7 +116,7 @@ let subscription = Observable<Int>.interval(0.3, scheduler: scheduler)
|
|||
print(event)
|
||||
}
|
||||
|
||||
NSThread.sleepForTimeInterval(2)
|
||||
NSThread.sleep(forTimeInterval: 2.0)
|
||||
|
||||
subscription.dispose()
|
||||
|
||||
|
|
@ -218,9 +218,9 @@ sequence
|
|||
|
||||
There is also a couple of additional guarantees that all sequence producers (`Observable`s) must honor.
|
||||
|
||||
It doesn't matter on which thread they produce elements, but if they generate one element and send it to the observer `observer.on(.Next(nextElement))`, they can't send next element until `observer.on` method has finished execution.
|
||||
It doesn't matter on which thread they produce elements, but if they generate one element and send it to the observer `observer.on(.next(nextElement))`, they can't send next element until `observer.on` method has finished execution.
|
||||
|
||||
Producers also cannot send terminating `.Completed` or `.Error` in case `.Next` event hasn't finished.
|
||||
Producers also cannot send terminating `.completed` or `.error` in case `.next` event hasn't finished.
|
||||
|
||||
In short, consider this example:
|
||||
|
||||
|
|
@ -291,8 +291,8 @@ Let's create a function which creates a sequence that returns one element upon s
|
|||
```swift
|
||||
func myJust<E>(element: E) -> Observable<E> {
|
||||
return Observable.create { observer in
|
||||
observer.on(.Next(element))
|
||||
observer.on(.Completed)
|
||||
observer.on(.next(element))
|
||||
observer.on(.completed)
|
||||
return Disposables.create()
|
||||
}
|
||||
}
|
||||
|
|
@ -325,10 +325,10 @@ Lets now create an observable that returns elements from an array.
|
|||
func myFrom<E>(sequence: [E]) -> Observable<E> {
|
||||
return Observable.create { observer in
|
||||
for element in sequence {
|
||||
observer.on(.Next(element))
|
||||
observer.on(.next(element))
|
||||
}
|
||||
|
||||
observer.on(.Completed)
|
||||
observer.on(.completed)
|
||||
return Disposables.create()
|
||||
}
|
||||
}
|
||||
|
|
@ -390,7 +390,7 @@ func myInterval(interval: NSTimeInterval) -> Observable<Int> {
|
|||
if cancel.isDisposed {
|
||||
return
|
||||
}
|
||||
observer.on(.Next(next))
|
||||
observer.on(.next(next))
|
||||
next += 1
|
||||
})
|
||||
dispatch_resume(timer)
|
||||
|
|
@ -410,7 +410,8 @@ let subscription = counter
|
|||
print(n)
|
||||
})
|
||||
|
||||
NSThread.sleepForTimeInterval(0.5)
|
||||
|
||||
NSThread.sleep(forTimeInterval: 0.5)
|
||||
|
||||
subscription.dispose()
|
||||
|
||||
|
|
@ -446,11 +447,11 @@ let subscription2 = counter
|
|||
print("Second \(n)")
|
||||
})
|
||||
|
||||
NSThread.sleepForTimeInterval(0.5)
|
||||
NSThread.sleep(forTimeInterval: 0.5)
|
||||
|
||||
subscription1.dispose()
|
||||
|
||||
NSThread.sleepForTimeInterval(0.5)
|
||||
NSThread.sleep(forTimeInterval: 0.5)
|
||||
|
||||
subscription2.dispose()
|
||||
|
||||
|
|
@ -559,17 +560,17 @@ extension Reactive where Base: NSURLSession {
|
|||
return Observable.create { observer in
|
||||
let task = self.dataTaskWithRequest(request) { (data, response, error) in
|
||||
guard let response = response, data = data else {
|
||||
observer.on(.Error(error ?? RxCocoaURLError.Unknown))
|
||||
observer.on(.error(error ?? RxCocoaURLError.Unknown))
|
||||
return
|
||||
}
|
||||
|
||||
guard let httpResponse = response as? NSHTTPURLResponse else {
|
||||
observer.on(.Error(RxCocoaURLError.NonHTTPResponse(response: response)))
|
||||
observer.on(.error(RxCocoaURLError.nonHTTPResponse(response: response)))
|
||||
return
|
||||
}
|
||||
|
||||
observer.on(.Next(data, httpResponse))
|
||||
observer.on(.Completed)
|
||||
observer.on(.next(data, httpResponse))
|
||||
observer.on(.completed)
|
||||
}
|
||||
|
||||
task.resume()
|
||||
|
|
@ -614,13 +615,13 @@ extension ObservableType {
|
|||
return Observable.create { observer in
|
||||
let subscription = self.subscribe { e in
|
||||
switch e {
|
||||
case .Next(let value):
|
||||
case .next(let value):
|
||||
let result = transform(value)
|
||||
observer.on(.Next(result))
|
||||
case .Error(let error):
|
||||
observer.on(.Error(error))
|
||||
case .Completed:
|
||||
observer.on(.Completed)
|
||||
observer.on(.next(result))
|
||||
case .error(let error):
|
||||
observer.on(.error(error))
|
||||
case .completed:
|
||||
observer.on(.completed)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -680,7 +681,7 @@ This isn't something that should be practiced often, and is a bad code smell, bu
|
|||
being,
|
||||
UIApplication.delegate.dataSomething.attendees
|
||||
)
|
||||
kittens.on(.Next(kitten)) // send result back to rx
|
||||
kittens.on(.next(kitten)) // send result back to rx
|
||||
//
|
||||
// Another mess
|
||||
//
|
||||
|
|
@ -797,15 +798,15 @@ will print
|
|||
```
|
||||
[my probe] subscribed
|
||||
Subscribed
|
||||
[my probe] -> Event Next(Box(0))
|
||||
[my probe] -> Event next(Box(0))
|
||||
This is simply 0
|
||||
[my probe] -> Event Next(Box(1))
|
||||
[my probe] -> Event next(Box(1))
|
||||
This is simply 1
|
||||
[my probe] -> Event Next(Box(2))
|
||||
[my probe] -> Event next(Box(2))
|
||||
This is simply 2
|
||||
[my probe] -> Event Next(Box(3))
|
||||
[my probe] -> Event next(Box(3))
|
||||
This is simply 3
|
||||
[my probe] -> Event Next(Box(4))
|
||||
[my probe] -> Event next(Box(4))
|
||||
This is simply 4
|
||||
[my probe] dispose
|
||||
Disposed
|
||||
|
|
@ -821,14 +822,14 @@ extension ObservableType {
|
|||
let subscription = self.subscribe { e in
|
||||
print("event \(identifier) \(e)")
|
||||
switch e {
|
||||
case .Next(let value):
|
||||
observer.on(.Next(value))
|
||||
case .next(let value):
|
||||
observer.on(.next(value))
|
||||
|
||||
case .Error(let error):
|
||||
observer.on(.Error(error))
|
||||
case .error(let error):
|
||||
observer.on(.error(error))
|
||||
|
||||
case .Completed:
|
||||
observer.on(.Completed)
|
||||
case .completed:
|
||||
observer.on(.completed)
|
||||
}
|
||||
}
|
||||
return Disposables.create {
|
||||
|
|
@ -1081,7 +1082,7 @@ let cancelRequest = responseJSON
|
|||
print(json)
|
||||
})
|
||||
|
||||
NSThread.sleepForTimeInterval(3)
|
||||
NSThread.sleep(forTimeInterval: 3.0)
|
||||
|
||||
// if you want to cancel request after 3 seconds have passed just call
|
||||
cancelRequest.dispose()
|
||||
|
|
@ -1093,7 +1094,7 @@ cancelRequest.dispose()
|
|||
In case you want a more low level access to response, you can use:
|
||||
|
||||
```swift
|
||||
NSURLSession.sharedSession().rx.response(myNSURLRequest)
|
||||
NSURLSession.shared.rx.response(myNSURLRequest)
|
||||
.debug("my request") // this will print out information to console
|
||||
.flatMap { (data: NSData!, response: NSURLResponse!) -> Observable<String> in
|
||||
if let response = response as? NSHTTPURLResponse {
|
||||
|
|
|
|||
38
README.md
38
README.md
|
|
@ -3,7 +3,9 @@
|
|||
|
||||
[](https://travis-ci.org/ReactiveX/RxSwift)   [](https://github.com/Carthage/Carthage)
|
||||
|
||||
Xcode 7.3 Swift 2.2 required
|
||||
**Xcode 8.0 beta 6 (8S201h) required**
|
||||
|
||||
**Swift 3.0**
|
||||
|
||||
## About Rx
|
||||
|
||||
|
|
@ -96,7 +98,7 @@ let searchResults = searchBar.rx.text
|
|||
<tr>
|
||||
<td width="30%"><div class="highlight highlight-source-swift"><pre>
|
||||
searchResults
|
||||
.bindTo(tableView.rx.itemsWithCellIdentifier("Cell")) {
|
||||
.bindTo(tableView.rx.items(cellIdentifier: "Cell")) {
|
||||
(index, repository: Repository, cell) in
|
||||
cell.textLabel?.text = repository.name
|
||||
cell.detailTextLabel?.text = repository.url
|
||||
|
|
@ -118,38 +120,36 @@ Open Rx.xcworkspace, choose `RxExample` and hit run. This method will build ever
|
|||
|
||||
### [CocoaPods](https://guides.cocoapods.org/using/using-cocoapods.html)
|
||||
|
||||
**:warning: IMPORTANT! For tvOS support, CocoaPods `0.39` is required. :warning:**
|
||||
|
||||
```
|
||||
# Podfile
|
||||
use_frameworks!
|
||||
|
||||
target 'YOUR_TARGET_NAME' do
|
||||
pod 'RxSwift', '~> 2.0'
|
||||
pod 'RxCocoa', '~> 2.0'
|
||||
pod 'RxSwift', '~> 3.0.0.alpha.1'
|
||||
pod 'RxCocoa', '~> 3.0.0.alpha.1'
|
||||
end
|
||||
|
||||
# RxTests and RxBlocking make the most sense in the context of unit/integration tests
|
||||
target 'YOUR_TESTING_TARGET' do
|
||||
pod 'RxBlocking', '~> 2.0'
|
||||
pod 'RxTests', '~> 2.0'
|
||||
pod 'RxBlocking', '~> 3.0.0.alpha.1'
|
||||
pod 'RxTests', '~> 3.0.0.alpha.1'
|
||||
end
|
||||
```
|
||||
|
||||
Replace `YOUR_TARGET_NAME` and then, in the `Podfile` directory, type:
|
||||
|
||||
**:warning: If you want to use CocoaPods with Xcode 8.0 beta and Swift 2.3, you might need to add the following
|
||||
**:warning: If you want to use CocoaPods with Xcode 8.0 beta and Swift 3.0, you might need to add the following
|
||||
lines to your podfile: :warning:**
|
||||
|
||||
```
|
||||
post_install do |installer|
|
||||
installer.pods_project.targets.each do |target|
|
||||
target.build_configurations.each do |config|
|
||||
config.build_settings['SWIFT_VERSION'] = '2.3'
|
||||
config.build_settings['MACOSX_DEPLOYMENT_TARGET'] = '10.10'
|
||||
end
|
||||
end
|
||||
end
|
||||
post_install do |installer|
|
||||
installer.pods_project.targets.each do |target|
|
||||
target.build_configurations.each do |config|
|
||||
config.build_settings['SWIFT_VERSION'] = '3.0'
|
||||
config.build_settings['MACOSX_DEPLOYMENT_TARGET'] = '10.10'
|
||||
end
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
```
|
||||
|
|
@ -158,12 +158,10 @@ $ pod install
|
|||
|
||||
### [Carthage](https://github.com/Carthage/Carthage)
|
||||
|
||||
**Xcode 7.1 required**
|
||||
|
||||
Add this to `Cartfile`
|
||||
|
||||
```
|
||||
github "ReactiveX/RxSwift" ~> 2.0
|
||||
github "ReactiveX/RxSwift" ~> 3.0.0.alpha.1
|
||||
```
|
||||
|
||||
```
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ All of these various systems makes our code needlessly complex. Wouldn't it be b
|
|||
* `ObservableType.subscribe(_:)` takes an observer (`ObserverType`) parameter, which will be subscribed to automatically receive sequence events and elements emitted by the `Observable`, instead of manually calling `next()` on the returned generator.
|
||||
*/
|
||||
/*:
|
||||
If an `Observable` emits a Next event (`Event.Next(Element)`), it can continue to emit more events. However, if the `Observable` emits either an Error event (`Event.Error(ErrorType)`) or a Completed event (`Event.Completed`), the `Observable` sequence cannot emit additional events to the subscriber.
|
||||
If an `Observable` emits a next event (`Event.next(Element)`), it can continue to emit more events. However, if the `Observable` emits either an error event (`Event.error(ErrorType)`) or a completed event (`Event.completed`), the `Observable` sequence cannot emit additional events to the subscriber.
|
||||
|
||||
Sequence grammar explains this more concisely:
|
||||
|
||||
`Next* (Error | Completed)?`
|
||||
`next* (error | completed)?`
|
||||
|
||||
And this can also be explained more visually using diagrams:
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ example("PublishSubject") {
|
|||
subject.onNext("🅱️")
|
||||
}
|
||||
/*:
|
||||
> This example also introduces using the `onNext(_:)` convenience method, equivalent to `on(.Next(_:)`, which causes a new Next event to be emitted to subscribers with the provided `element`. There are also `onError(_:)` and `onCompleted()` convenience methods, equivalent to `on(.Error(_:))` and `on(.Completed)`, respectively.
|
||||
> This example also introduces using the `onNext(_:)` convenience method, equivalent to `on(.next(_:)`, which causes a new Next event to be emitted to subscribers with the provided `element`. There are also `onError(_:)` and `onCompleted()` convenience methods, equivalent to `on(.error(_:))` and `on(.completed)`, respectively.
|
||||
----
|
||||
## ReplaySubject
|
||||
Broadcasts new events to all subscribers, and the specified `bufferSize` number of previous events to new subscribers.
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ open class DelegateProxy : _RXDelegateProxy {
|
|||
let internalSubject = PublishSubject<CGPoint>
|
||||
|
||||
public func requiredDelegateMethod(scrollView: UIScrollView, arg1: CGPoint) -> Bool {
|
||||
internalSubject.on(.Next(arg1))
|
||||
internalSubject.on(.next(arg1))
|
||||
return self._forwardToDelegate?.requiredDelegateMethod?(scrollView, arg1: arg1) ?? defaultReturnValue
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import Foundation
|
|||
Represents a sequence event.
|
||||
|
||||
Sequence grammar:
|
||||
Next\* (Error | Completed)
|
||||
next\* (error | completed)
|
||||
*/
|
||||
public enum Event<Element> {
|
||||
/// Next element is produced.
|
||||
|
|
@ -30,11 +30,11 @@ extension Event : CustomDebugStringConvertible {
|
|||
public var debugDescription: String {
|
||||
switch self {
|
||||
case .next(let value):
|
||||
return "Next(\(value))"
|
||||
return "next(\(value))"
|
||||
case .error(let error):
|
||||
return "Error(\(error))"
|
||||
return "error(\(error))"
|
||||
case .completed:
|
||||
return "Completed"
|
||||
return "completed"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ Convenience API extensions to provide alternate next, error, completed events
|
|||
public extension ObserverType {
|
||||
|
||||
/**
|
||||
Convenience method equivalent to `on(.Next(element: E))`
|
||||
Convenience method equivalent to `on(.next(element: E))`
|
||||
|
||||
- parameter element: Next element to send to observer(s)
|
||||
*/
|
||||
|
|
@ -40,14 +40,14 @@ public extension ObserverType {
|
|||
}
|
||||
|
||||
/**
|
||||
Convenience method equivalent to `on(.Completed)`
|
||||
Convenience method equivalent to `on(.completed)`
|
||||
*/
|
||||
final func onCompleted() {
|
||||
on(.completed)
|
||||
}
|
||||
|
||||
/**
|
||||
Convenience method equivalent to `on(.Error(error: Swift.Error))`
|
||||
Convenience method equivalent to `on(.error(Swift.Error))`
|
||||
- parameter error: Swift.Error to send to observer(s)
|
||||
*/
|
||||
final func onError(_ error: Swift.Error) {
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ require specifying `self.*`, they are made global.
|
|||
*/
|
||||
//extension XCTestCase {
|
||||
/**
|
||||
Factory method for an `.Next` event recorded at a given time with a given value.
|
||||
Factory method for an `.next` event recorded at a given time with a given value.
|
||||
|
||||
- parameter time: Recorded virtual time the `.Next` event occurs.
|
||||
- parameter time: Recorded virtual time the `.next` event occurs.
|
||||
- parameter element: Next sequence element.
|
||||
- returns: Recorded event in time.
|
||||
*/
|
||||
|
|
@ -26,9 +26,9 @@ require specifying `self.*`, they are made global.
|
|||
}
|
||||
|
||||
/**
|
||||
Factory method for an `.Completed` event recorded at a given time.
|
||||
Factory method for an `.completed` event recorded at a given time.
|
||||
|
||||
- parameter time: Recorded virtual time the `.Completed` event occurs.
|
||||
- parameter time: Recorded virtual time the `.completed` event occurs.
|
||||
- parameter type: Sequence elements type.
|
||||
- returns: Recorded event in time.
|
||||
*/
|
||||
|
|
@ -37,9 +37,9 @@ require specifying `self.*`, they are made global.
|
|||
}
|
||||
|
||||
/**
|
||||
Factory method for an `.Error` event recorded at a given time with a given error.
|
||||
Factory method for an `.error` event recorded at a given time with a given error.
|
||||
|
||||
- parameter time: Recorded virtual time the `.Completed` event occurs.
|
||||
- parameter time: Recorded virtual time the `.completed` event occurs.
|
||||
*/
|
||||
public func error<T>(_ time: TestTime, _ error: Swift.Error, _ type: T.Type = T.self) -> Recorded<Event<T>> {
|
||||
return Recorded(time: time, event: .error(error))
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ compareTwoImplementations(benchmarkTime: true, benchmarkMemory: false, first: {
|
|||
_ = publishSubject //.asDriver(onErrorJustReturn: -1)
|
||||
/*create { (o: AnyObserver<Int>) in
|
||||
for i in 0..<100 {
|
||||
o.on(.Next(i))
|
||||
o.on(.next(i))
|
||||
}
|
||||
return Disposables.create()
|
||||
}*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue