-
Notifications
You must be signed in to change notification settings - Fork 32
Add CompositeDisposable::addIfDisposable
#12
Conversation
@@ -29,3 +29,10 @@ describe "CompositeDisposable", -> | |||
expect(disposable1.disposed).toBe true | |||
expect(disposable2.disposed).toBe false | |||
expect(disposable3.disposed).toBe true | |||
|
|||
it "denies to add an object that does not respond to ::dispose", -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎨 What about rejects an object that does not implement ::dispose
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s probably better but eventually I went with throws an error
, as it’s more consistent with how specs are named in atom/atom. Thanks! 🙇
Since |
Also, do you know if this would cause the |
Nice catch, I have just added it. 👍
I think the error will still be raised on Ideally, a type system would warn us about such kinds of issues but given that there isn't one, I think this is best thing we could possibly do. Also, I wouldn’t silently skip @kevinsawicki: thoughts? |
Yeah, thinking about the tabs example, it would seem unfortunate to have to wrap calls to add and dispose now in a try/catch since showing a notification isn't helpful at all and associating the pane item to a package is difficult/impossible. Having I feel like the pattern will be people just wrapping these methods in |
CompositeDisposable
CompositeDisposable::addIfDisposable
The problem this PR is trying to address comes from a package not respecting an API’s implementation contract. In particular, atom/tabs#183 was caused by the package implementing a function (which was supposed to return a Ideally, a type system would catch these kinds of errors early on thereby solving the problem altogether. However, since we haven’t got such facility in our environment, how can we solve it? This PR was initially created to put stricter guards whenever we added new disposables to a After discussing about this with @kevinsawicki, though, we agreed that there could have been situations where package authors simply ignored these new exceptions, thus leaving the problem unsolved. Therefore we decided to introduce a new API ( @benogle @maxbrunsfeld @nathansobo: what do you think? |
I feel a bit weirded out about expanding the API of what is otherwise a super minimal library. How many places do we anticipate using this method? Would it be rare enough to just guard the value in those cases and go ahead and throw exceptions from the core library? |
I still think I think that if we went that route, we should have |
👍 |
Closing in favor of #15. Thanks everyone for your feedback! 🙇 |
This should allow package developers to catch issues like atom/tabs#183 early on.This method will allow to have less strict checks whenever we add a disposable for code that we do not manage, thereby avoiding issues like atom/tabs#183 altogether.
/cc: @kevinsawicki @benogle