disposeBag: add a HasDisposeBag protocol#41
Conversation
ashfurrow
left a comment
There was a problem hiding this comment.
Looks good to me! Anyone from @RxSwiftCommunity/contributors available to review?
| get { | ||
| var disposeBag: DisposeBag! | ||
| doLocked { | ||
| let lookup = objc_getAssociatedObject(self, &AssociatedKeys.rxDisposeBag) as? DisposeBag |
There was a problem hiding this comment.
Interesting – I didn't expect associated objects to work with non-NSObject subclasses. You've verified this works?
There was a problem hiding this comment.
I will add a Unit test for this
There was a problem hiding this comment.
Done, there is a new Test for that. It works.
|
|
||
| It'll work just like a property: when the instance is deinit'd, the `DisposeBag` gets disposed. It's also a read/write property, so you can use your own, too. | ||
|
|
||
| If you want to add a DisposeBag to an Object that does not inherit from NSObject, you can also implement the protocol "DisposeBagable", and you're good to go. This protocol provides a default DisposeBag called rxDisposeBag. |
There was a problem hiding this comment.
Excellent addition to the readme 👍
There was a problem hiding this comment.
Wondering on why we should call this rxDisposebag given the fact it's from RxSwift is rather implicit? what about just calling it disposeBag across the board?
| let address2 = Unmanaged<AnyObject>.passUnretained(newDisposeBag as AnyObject).toOpaque() | ||
| XCTAssert(address1 == address2) | ||
| } | ||
| } |
|
My only gotcha with this is I really don't think this is an intuitive protocol name. Definitely an opinionated thing as naming is hard :) Great implementation though! |
|
For the name, there is another possibility: HasDisposeBag |
|
What about It's very tricky since naming conventions are hard in this sense :) Opinions ? @RxSwiftCommunity/contributors |
|
You should also fix CI :) |
|
I like the HasDisposeBag, because it is very explicit when you read the signature of the class that will implements it. |
|
CI is broken for the Demo app. It was already broken before I think. |
|
I'm definitely OK with this @twittemb . |
|
Yeah, CI is broken for this PR but it's not your fault! Looks like you're a Carthage user right? We just need to run EDIT: I've updated the readme to have the CI badge display the latest master build, instead of just the latest build of any branch. |
|
I think the two pending items are :
|
|
Ok. I've made the following changes:
|
|
Thanks for the Regarding the
|
|
See this is why I liked having all protocols suffixed with "Type", but that went away in Swift 3 :\ I'm in favour of either – we can always change it later + add a |
|
I was inspired by the following article by Krzysztof Zabłocki, who is involved in the swift community. He uses the "Has..." to specify every kinds of Services a class can provide (in a DI context) Another idea: It could be something like "DisposeBagProvider" ... but it is pretty long. |
|
What about also @ashfurrow RxSwift itself still uses Interesting about Krzysztof's article. We can keep it this way for now. I'm still a bit iffy about this :) But that's personal taste. I'd prefer Disposing (e.g. it can Dispose) or the aforementioned |
|
ok. Thanks for your feedback anyway.
Feel free to contribute :-) |
|
Hi, |
|
I think there's agreement with me and @ashfurrow so that's enough. Let's just get the CI working and LGTM! |
|
Yeah, we should definitely get this merged. Any ideas what's wrong with the tests on Travis? I can help take a look tomorrow, let me know. |
|
I'm on an earlier time zone, I'll take a look around tomorrow my morning :) |
| EXTERNAL SOURCES: | ||
| NSObject+Rx: | ||
| :path: "../" | ||
| :path: ../ |
There was a problem hiding this comment.
I think this needs to be ../NSObject_Rx to make CI happy.
There was a problem hiding this comment.
No, this points to the podspec so it should be fine
|
Hey @twittemb Once that is changed and merged @ashfurrow can separately release a new version |
|
Hey @freak4pc |
|
@twittemb I didn't mean to remove the entire Podfile.lock ... I mean you should not have changed it... Can you fix that ? Right now you just deleted the entire file. Regarding Carthage.resolved, might be but that shouldn't be part of this specific PR IMO |
|
@freak4pc ok sorry for the misunderstanding ... I've restored the Podfile.lock with the changes you recommend. |
In this commit, we try to conform to protocol oriented programming. It is more flexible to introduce a HasDisposeBag protocol so that every object that respect this one can have a DisposeBag (NSObject does respect that protocol now)
|
@freak4pc should be alright now :-) |
|
@twittemb Yup! looks good! Let's see if CI clears and I'm good to merge this. |
|
Very confusing 🤔 @ashfurrow any thoughts here? I didn't setup the CI here so not sure if any assumptions I'm missing |
|
It's possible that Travis has changed something on their end. I'll investigate and get back to everyone. |
|
ok thanks @ashfurrow |
|
@twittemb If you have the time that would be great! Might also resolve our issue here altogether. |
|
@freak4pc @ashfurrow I'll try to do it today (Montreal time zone) |
|
I can reproduce the problem locally – will have a fix shortly. We might as well keep this PR then. |
|
Okay, so this looks like an instance of a pretty common issue – Carthage and CocoaPods not being in sync. Happens all the time on Moya :) I've opened #42 with the changes from this PR as well as the changes needed to sort things out. |
|
Thanks a lot for contributing! I've invited you to join the RxSwiftCommunity GitHub organization – no pressure to accept! If you'd like more information on what that means, check out our contributor guidelines and feel free to reach out with any questions. |

In this commit, we try to conform to protocol oriented programming. It is more flexible to
introduce a DisposeBagable protocol so that every object that respect this one
can have a DisposeBag (NSObject does respect that protocol now)