RxSwift icon indicating copy to clipboard operation
RxSwift copied to clipboard

[Swift 3.0] Rename disposable-related methods

Open mohsenr opened this issue 10 years ago • 4 comments

Rename Some methods to better match Swift 3.0 API Design Guidelines.

Methods will old name will still exist for a while with a deprecation annotation.

This is a summary of the proposed changes:


extension CompositeDisposable {

+   @available(*, renamed: "insert()")
    public func addDisposable(_ disposable: Disposable) -> DisposeKey?

+   public func insert(_ disposable: Disposable) -> DisposeKey?

+   @available(*, renamed: "removeDisposable(forKey:)")
    public func removeDisposable(_ disposeKey: DisposeKey)

+   public func removeDisposable(forKey disposeKey: DisposeKey)

}

extension DisposeBag {

+   @available(*, renamed: "insert()")
    public func addDisposable(_ disposable: Disposable)

+   public func insert(_ disposable: Disposable)

}

+@available(*, renamed: "Bag.disposeAll()")
public func disposeAllIn(_ bag: Bag<Disposable>)

+extension Bag where T: Disposable {
+    
+    public func disposeAll()
+    
+}


mohsenr avatar Jul 25 '16 13:07 mohsenr

The last renaming doesn’t work as the compiler can’t produce call to Bag<Disposable> when not using a concrete subtype. Instead, we have:

+@available(*, renamed: "disposeAll(in:)")
public func disposeAllIn(_ bag: Bag<Disposable>)

+public func disposeAll(in bag: Bag<Disposable>)

mohsenr avatar Jul 25 '16 15:07 mohsenr

Hey,

yeah, I think your suggestions make sense. The one change I would suggest is using public func remove(forKey disposeKey: DisposeKey) instead of public func removeDisposable(forKey disposeKey: DisposeKey)

... so there is no redundant Disposable.

kzaher avatar Jul 25 '16 21:07 kzaher

I modelled that on Dictionary.removeValue(forKey:) cause its the closest API for what we’re doing here.

Though you’re right that the shorter name feels better. Specially given that the type is not parameterised. Maybe we should parallel with Array.remove(at:): so we’d have remove(for:) – unless you think the Key part is needed?

mohsenr avatar Jul 26 '16 08:07 mohsenr

@mohsenr yeah, my reasoning was because of array.remove(at:).

I'm fine with remove(for:) suggestion.

kzaher avatar Jul 27 '16 13:07 kzaher