DeclarativeHub / ReactiveKit

A Swift Reactive Programming Kit
MIT License
1.24k stars 114 forks source link

Suggestion: rename Disposable.dispose(in:) #244

Open ibsh opened 4 years ago

ibsh commented 4 years ago

The shared verb between this method and Disposable.dispose() makes them appear extremely similar in behaviour.

I suggest RxSwift's .disposed(by:)

srdanrasic commented 4 years ago

Good idea @ibsh! I've added store(in:) family of methods that are more aligned with Apple's Combine in the latest release.

extension Disposable {

    public func dispose(in disposeBag: DisposeBagProtocol) {
        disposeBag.add(disposable: self)
    }

    public func store(in disposeBag: DisposeBagProtocol) {
        disposeBag.add(disposable: self)
    }

    public func store<C>(in collection: inout C) where C: RangeReplaceableCollection, C.Element == AnyCancellable {
        collection.append(AnyCancellable(self))
    }

    public func store(in set: inout Set<AnyCancellable>) {
        set.insert(AnyCancellable(self))
    }
}