From 9b3514f6964e2be9d4fdd4d081c72d74dc11990a Mon Sep 17 00:00:00 2001 From: Tristan Celder Date: Fri, 8 May 2020 14:52:44 +0100 Subject: [PATCH] Removed CancellableBag --- Assets/Entwine/README.md | 1 - .../CancellableBag.swift | 9 +- .../{ => Deprecated}/Deprecations.swift | 6 +- Tests/EntwineTests/CancellableBagTests.swift | 82 ------------------- 4 files changed, 9 insertions(+), 89 deletions(-) rename Sources/Entwine/{Utilities => Deprecated}/CancellableBag.swift (87%) rename Sources/Entwine/{ => Deprecated}/Deprecations.swift (88%) delete mode 100644 Tests/EntwineTests/CancellableBagTests.swift diff --git a/Assets/Entwine/README.md b/Assets/Entwine/README.md index b4263c0..19de623 100644 --- a/Assets/Entwine/README.md +++ b/Assets/Entwine/README.md @@ -21,7 +21,6 @@ _Entwine Utilities_ are a collection of operators, tools and extensions to make - The `ReplaySubject` makes it simple for subscribers to receive the most recent values immediately upon subscription. - The `withLatest(from:)` operator enables state to be taken alongside UI events. - `Publishers.Factory` makes creating publishers fast and simple – they can even be created inline! -- `CancellableBag` helps to gather all your cancellable in a single place and helps to make your publisher chain declarations even clearer. be sure to checkout the [documentation](http://tcldr.github.io/Entwine/EntwineDocs) for the full list of operators and utilities. diff --git a/Sources/Entwine/Utilities/CancellableBag.swift b/Sources/Entwine/Deprecated/CancellableBag.swift similarity index 87% rename from Sources/Entwine/Utilities/CancellableBag.swift rename to Sources/Entwine/Deprecated/CancellableBag.swift index b8e89c2..336f341 100644 --- a/Sources/Entwine/Utilities/CancellableBag.swift +++ b/Sources/Entwine/Deprecated/CancellableBag.swift @@ -1,7 +1,7 @@ // // Entwine // https://github.com/tcldr/Entwine -// +// // Copyright © 2019 Tristan Celder. All rights reserved. // // Permission is hereby granted, free of charge, to any person obtaining a copy @@ -25,6 +25,7 @@ import Combine /// A container for cancellables that will be cancelled when the bag is deallocated or cancelled itself +@available(*, deprecated, message: "Replace with mutable Set") public final class CancellableBag: Cancellable { public init() {} @@ -46,8 +47,8 @@ public final class CancellableBag: Cancellable { // MARK: - Cancellable extension public extension Cancellable { - /// Adds this cancellable to the passed `CancellationBag` - func cancelled(by cancellationBag: CancellableBag) { - cancellationBag.add(self) + @available(*, deprecated, message: "Replace CancellableBag with Set and use `store(in:)`") + func cancelled(by cancellableBag: CancellableBag) { + cancellableBag.add(self) } } diff --git a/Sources/Entwine/Deprecations.swift b/Sources/Entwine/Deprecated/Deprecations.swift similarity index 88% rename from Sources/Entwine/Deprecations.swift rename to Sources/Entwine/Deprecated/Deprecations.swift index 8dfcac0..62cf7b5 100644 --- a/Sources/Entwine/Deprecations.swift +++ b/Sources/Entwine/Deprecated/Deprecations.swift @@ -22,5 +22,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -@available(*, deprecated, renamed: "CancellableBag") -public typealias CancellationBag = CancellableBag +import Combine + +@available(*, deprecated, message: "Replace with mutable Set") +public typealias CancellationBag = Set diff --git a/Tests/EntwineTests/CancellableBagTests.swift b/Tests/EntwineTests/CancellableBagTests.swift deleted file mode 100644 index 73531f9..0000000 --- a/Tests/EntwineTests/CancellableBagTests.swift +++ /dev/null @@ -1,82 +0,0 @@ -// -// Entwine -// https://github.com/tcldr/Entwine -// -// Copyright © 2019 Tristan Celder. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -import XCTest -import Combine - -@testable import Entwine -@testable import EntwineTest - -final class CancellableBagTests: XCTestCase { - - func testBagCancelsContainedCancellablesOnDeallocation() { - - let scheduler = TestScheduler() - let subject = PassthroughSubject() - let subscriber = scheduler.createTestableSubscriber(Int.self, Never.self) - - var sut: CancellableBag! = CancellableBag() - - subscriber.cancelled(by: sut) - - scheduler.schedule(after: 100) { subject.subscribe(subscriber) } - scheduler.schedule(after: 110) { subject.send(1) } - scheduler.schedule(after: 120) { subject.send(2) } - scheduler.schedule(after: 130) { sut = nil } - scheduler.schedule(after: 140) { subject.send(3) } - - scheduler.resume() - - XCTAssertEqual(subscriber.recordedOutput, [ - (100, .subscription), - (110, .input(1)), - (120, .input(2)), - ]) - } - - func testBagCancelsContainedCancellablesOnExplicitCancel() { - - let scheduler = TestScheduler() - let subject = PassthroughSubject() - let subscriber = scheduler.createTestableSubscriber(Int.self, Never.self) - - let sut = CancellableBag() - - subscriber.cancelled(by: sut) - - scheduler.schedule(after: 100) { subject.subscribe(subscriber) } - scheduler.schedule(after: 110) { subject.send(1) } - scheduler.schedule(after: 120) { subject.send(2) } - scheduler.schedule(after: 130) { sut.cancel() } - scheduler.schedule(after: 140) { subject.send(3) } - - scheduler.resume() - - XCTAssertEqual(subscriber.recordedOutput, [ - (100, .subscription), - (110, .input(1)), - (120, .input(2)), - ]) - } -}