Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/icanzilb/cancellor
Bind multiple cancellables to the lifetime of another object like a view controller.
https://github.com/icanzilb/cancellor
combine-framework reactive-programming swift
Last synced: 1 day ago
JSON representation
Bind multiple cancellables to the lifetime of another object like a view controller.
- Host: GitHub
- URL: https://github.com/icanzilb/cancellor
- Owner: icanzilb
- License: mit
- Created: 2021-02-04T16:06:11.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-02-04T19:33:58.000Z (over 3 years ago)
- Last Synced: 2024-09-22T02:46:47.595Z (11 days ago)
- Topics: combine-framework, reactive-programming, swift
- Language: Swift
- Homepage: http://trycombine.com
- Size: 8.79 KB
- Stars: 32
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cancellor
Bind multiple cancellables to the lifetime of another object like your view controller.
## Usage
Import **Cancellor** and subscribe your publishers inside an `ownedCancellables` block. When your view controller is dismissed any active subscriptions will get cancelled automatically.
```swift
import Cancellorclass MyViewController: UIViewController {
override func viewDidLoad() {
ownedCancellables {
myPublisher1.sink(...)
myPublisher2.sink(...)
myPublisher3.assign(to: ..., on: ...)
}
}
}
```To tie a single subscription to the lifetime of another object use:
```swift
class ViewModel: NSObject { ... }
let vm = ViewModel(...)...
myPublisher
.sink(...)
.owned(by: vm)
```## Import
Add the following dependency to your **Package.swift** file:
```swift
.package(url: "https://github.com/icanzilb/Cancellor", from: "0.2.0")
```## License
Cancellor is available under the MIT license. See the LICENSE file for more info.
## Credits
Created by Marin Todorov.
📚 You can support me by checking out our Combine book: [combinebook.com](http://combinebook.com).
Inspired by Ash Furrow's [NSObject-rx](https://github.com/RxSwiftCommunity/NSObject-Rx).
Name by https://github.com/manmal.