Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIButton.rex_pressed example in README #58

Merged
merged 2 commits into from
Oct 30, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ func propertySink<S: SinkType>(sink: S)(signal: Signal<S.Element, NoError>) -> P
func propertySink<S: SinkType>(sink: S)(producer: SignalProducer<S.Element, NoError>) -> PropertyOf<S>
```

## UIKit Extensions

##### `UIButton.rex_pressed`

Flexible way to bind CocoaAction to the press of button.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add another sentence that the button is automatically disabled while the Action is executing.


```swift
let downloadAction: Action<Void, NSData, NoError> = Action { _ in
return SignalProducer { observer, disposable in
if let zipURL = NSURL(string: "https://github.com/neilpa/Rex/archive/master.zip") {
if let zipData = NSData(contentsOfURL: zipURL) {
observer.sendNext(zipData)
observer.sendCompleted()
}
}
}
}

let downloadCocoaAction = CocoaAction(downloadAction, input: ())
let cocoaActionProducer: SignalProducer<CocoaAction, NoError> = SignalProducer<CocoaAction, NoError>(value: downloadCocoaAction)
startDownloadButton.rex_pressed <~ cocoaActionProducer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified a bit

let downloadAction = Action<UIButton, NSData, NSError> { _ in
    let url = NSURL(string: "https://github.com/neilpa/Rex/archive/master.zip")
    let request = NSURLRequest(URL: url!)
    return NSURLSession.sharedSession().rac_dataWithRequest(request).map { $0.0 }
}

downloadButton.rex_pressed.value = downloadAction.unsafeCocoaAction

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only time you need to bind with <~ is if the underlying action will change over time. That'll be the uncommon case when building UI.

```

## License
Rex is released under the [MIT license](LICENSE)