Skip to content

Commit

Permalink
Update package
Browse files Browse the repository at this point in the history
  • Loading branch information
vmanot committed Oct 28, 2024
1 parent 33b8b3e commit a6f9814
Show file tree
Hide file tree
Showing 22 changed files with 75 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extension ObservableObject {
}
}

public func _onReceiveOfValueEmittedBy<T: _ObservableObjectX>(
public func _onReceiveOfValueEmittedBy<T: ObjectDidChangeObservableObject>(
_ object: T,
perform action: @escaping () -> Void
) {
Expand All @@ -97,7 +97,7 @@ extension ObservableObject {
}
}

public func _onReceiveOfValueEmittedBy<T: _ObservableObjectX>(
public func _onReceiveOfValueEmittedBy<T: ObjectDidChangeObservableObject>(
_ object: T,
perform action: @escaping () async throws -> Void
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ open class TaskOperation<Base: ObservableTask>: Operation, @unchecked Sendable {
.outputPublisher
.toResultPublisher()
.sink { status in
switch TaskStatus(status) {
switch ObservableTaskStatus(status) {
case .idle:
self._executing = false
self._finished = false
Expand Down
4 changes: 2 additions & 2 deletions Sources/Merge/Intermodular/Helpers/Swift/Process.Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ extension Process {
process.processIdentifier
}

public var status: TaskStatus<Success, Error> {
public var status: ObservableTaskStatus<Success, Error> {
base.status
}

public var objectWillChange: AnyObjectWillChangePublisher {
.init(from: base)
}

public var objectDidChange: AnyPublisher<TaskStatus<Success, Error>, Never> {
public var objectDidChange: AnyPublisher<ObservableTaskStatus<Success, Error>, Never> {
base.objectDidChange
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Swallow
///
/// `ObservableObject` subscribes to the `objectWillChange` publishers of all elements contained within it and forwards them to its own `objectWillChange` publisher.
@propertyWrapper
public final class ObservableArray<Element: ObservableObject>: MutablePropertyWrapper, Sequence, _ObservableObjectX {
public final class ObservableArray<Element: ObservableObject>: MutablePropertyWrapper, Sequence, ObjectDidChangeObservableObject {
public let objectWillChange = ObservableObjectPublisher()

private var cancellables: [ObjectIdentifier: AnyCancellable] = [:]
Expand Down
2 changes: 1 addition & 1 deletion Sources/Merge/Intramodular/Observable Tasks/AnyTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Swallow
/// A task that performs type erasure by wrapping another task.
public final class AnyTask<Success, Error: Swift.Error>: ObservableObject, ObservableTask, @unchecked Sendable {
public typealias ID = AnyHashable
public typealias Status = TaskStatus<Success, Error>
public typealias Status = ObservableTaskStatus<Success, Error>

public let base: any ObservableTask<Success, Error>
public let objectDidChange: AnyPublisher<Status, Never>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import Combine
import Foundation

public final class EmptyObservableTask<Success, Error: Swift.Error>: ObservableTask {
public var status: TaskStatus<Success, Error> {
public var status: ObservableTaskStatus<Success, Error> {
.idle
}

public var objectWillChange: AnyPublisher<TaskStatus<Success, Error>, Never> {
public var objectWillChange: AnyPublisher<ObservableTaskStatus<Success, Error>, Never> {
Empty().eraseToAnyPublisher()
}

public var objectDidChange: AnyPublisher<TaskStatus<Success, Error>, Never> {
public var objectDidChange: AnyPublisher<ObservableTaskStatus<Success, Error>, Never> {
Empty().eraseToAnyPublisher()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Swift

/// A base class to subclass when building observable tasks.
open class ObservableTaskBase<Success, Error: Swift.Error>: ObservableTask {
public typealias Status = TaskStatus<Success, Error>
public typealias Status = ObservableTaskStatus<Success, Error>

let statusValueSubject = CurrentValueSubject<Status, Never>(.idle)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension ObservableTasks {
private let receiveStart: (() -> Void)?
private let receiveCancel: (() -> Void)?

public var status: TaskStatus<Success, Error> {
public var status: ObservableTaskStatus<Success, Error> {
base.status
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension ObservableTasks {
public final class Map<Upstream: ObservableTask, Success>: ObservableTask {
public typealias Success = Success
public typealias Error = Upstream.Error
public typealias Status = TaskStatus<Success, Error>
public typealias Status = ObservableTaskStatus<Success, Error>

private let upstream: Upstream
private let transform: (Upstream.Success) -> Success
Expand All @@ -33,7 +33,7 @@ extension ObservableTasks {
self.transform = transform
}

public var status: TaskStatus<Success, Error> {
public var status: ObservableTaskStatus<Success, Error> {
upstream.status.map(transform)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Swift
/// A mutable task.
open class PassthroughTask<Success, Error: Swift.Error>: ObservableTask {
public typealias Body = (PassthroughTask) -> AnyCancellable
public typealias Status = TaskStatus<Success, Error>
public typealias Status = ObservableTaskStatus<Success, Error>

private let lock = NSRecursiveLock()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import Foundation
import Swallow

/// An observable task is a token of activity with status-reporting.
public protocol ObservableTask<Success, Error>: Cancellable, Identifiable, _ObservableObjectX where ObjectDidChangePublisher.Output == TaskStatus<Self.Success, Self.Error> {
public protocol ObservableTask<Success, Error>: Cancellable, Identifiable, ObjectDidChangeObservableObject where ObjectDidChangePublisher.Output == ObservableTaskStatus<Self.Success, Self.Error> {
associatedtype Success
associatedtype Error: Swift.Error

/// The status of this task.
var status: TaskStatus<Success, Error> { get }
var status: ObservableTaskStatus<Success, Error> { get }

/// Start the task.
func start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public final class OpaqueObservableTask: CustomStringConvertible, ObjCObject, Ob
(base as? CustomStringConvertible)?.description ?? "(Task)"
}

public var status: TaskStatus<Success, Error> {
public var status: ObservableTaskStatus<Success, Error> {
base._opaque_status
}

public var objectWillChange: AnyObjectWillChangePublisher {
.init(from: base)
}

public var objectDidChange: AnyPublisher<TaskStatus<Success, Error>, Never> {
public var objectDidChange: AnyPublisher<ObservableTaskStatus<Success, Error>, Never> {
base._opaque_objectDidChange
}

Expand Down Expand Up @@ -98,11 +98,11 @@ extension OpaqueObservableTask: Equatable {
// MARK: - Auxiliary

extension ObservableTask {
fileprivate var _opaque_status: TaskStatus<Any, Swift.Error> {
fileprivate var _opaque_status: ObservableTaskStatus<Any, Swift.Error> {
status.map({ $0 as Any }).mapError({ $0 as Swift.Error })
}

fileprivate var _opaque_objectDidChange: AnyPublisher<TaskStatus<Any, Swift.Error>, Never> {
fileprivate var _opaque_objectDidChange: AnyPublisher<ObservableTaskStatus<Any, Swift.Error>, Never> {
objectDidChange
.map({ $0.map({ $0 as Any }).mapError({ $0 as Swift.Error }) })
.eraseToAnyPublisher()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import Combine
import Swallow

public protocol TaskStatusType<Success, Error> {
public protocol ObservableTaskStatusType<Success, Error> {
associatedtype Success
associatedtype Error
}

/// The status of a task.
@frozen
public enum TaskStatus<Success, Error: Swift.Error>: TaskStatusType {
public enum ObservableTaskStatus<Success, Error: Swift.Error>: ObservableTaskStatusType {
case idle
case active
case paused
Expand All @@ -23,7 +23,7 @@ public enum TaskStatus<Success, Error: Swift.Error>: TaskStatusType {

// MARK: - Extensions

extension TaskStatus {
extension ObservableTaskStatus {
public var isTerminal: Bool {
switch self {
case .success, .canceled, .error:
Expand All @@ -46,7 +46,7 @@ extension TaskStatus {
}
}

extension TaskStatus {
extension ObservableTaskStatus {
public var successValue: Success? {
if case let .success(success) = self {
return success
Expand All @@ -64,7 +64,7 @@ extension TaskStatus {
}
}

extension TaskStatus {
extension ObservableTaskStatus {
public var output: TaskOutput<Success, Error>? {
switch self {
case .active:
Expand Down Expand Up @@ -106,8 +106,8 @@ extension TaskStatus {
}
}

extension TaskStatus {
public func map<T>(_ transform: (Success) -> T) -> TaskStatus<T, Error> {
extension ObservableTaskStatus {
public func map<T>(_ transform: (Success) -> T) -> ObservableTaskStatus<T, Error> {
switch self {
case .idle:
return .idle
Expand All @@ -124,7 +124,7 @@ extension TaskStatus {
}
}

public func mapError<T: Swift.Error>(_ transform: (Error) -> T) -> TaskStatus<Success, T> {
public func mapError<T: Swift.Error>(_ transform: (Error) -> T) -> ObservableTaskStatus<Success, T> {
switch self {
case .idle:
return .idle
Expand All @@ -144,15 +144,15 @@ extension TaskStatus {

// MARK: - Conformances

extension TaskStatus: Equatable where Success: Equatable, Error: Equatable {
extension ObservableTaskStatus: Equatable where Success: Equatable, Error: Equatable {

}

extension TaskStatus: Hashable where Success: Hashable, Error: Hashable {
extension ObservableTaskStatus: Hashable where Success: Hashable, Error: Hashable {

}

extension TaskStatus: Sendable where Success: Sendable {
extension ObservableTaskStatus: Sendable where Success: Sendable {

}

Expand Down Expand Up @@ -287,7 +287,7 @@ extension ObservableTask {
}
}

extension TaskStatus {
extension ObservableTaskStatus {
public init(_ status: Result<Success, Error>) {
switch status {
case .success(let value):
Expand Down Expand Up @@ -320,7 +320,7 @@ extension TaskStatus {
}

extension Result {
public init?(_ status: TaskStatus<Success, Failure>) {
public init?(_ status: ObservableTaskStatus<Success, Failure>) {
switch status {
case .success(let success):
self = .success(success)
Expand All @@ -331,3 +331,10 @@ extension Result {
}
}
}

// MARK: - Deprecated

@available(*, deprecated, renamed: "ObservableTaskStatusType")
public typealias TaskStatusType = ObservableTaskStatusType
@available(*, deprecated, renamed: "ObservableTaskStatus")
public typealias TaskStatus<T, U: Error> = ObservableTaskStatus<T, U>
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public enum TaskFailure<Error: Swift.Error>: _ErrorX, HashEquatable {
// MARK: - Initializers

extension TaskFailure {
public init?<Success>(_ status: TaskStatus<Success, Error>) {
public init?<Success>(_ status: ObservableTaskStatus<Success, Error>) {
if let failure = status.failure {
self = failure
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum TaskOutput<Success, Error: Swift.Error> {

extension TaskOutput {
public var value: Success? {
TaskStatus(self).successValue
ObservableTaskStatus(self).successValue
}

public var isTerminal: Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum TaskResult<Success, Error: Swift.Error> {
}
}

public init?(_ status: TaskStatus<Success, Error>) {
public init?(_ status: ObservableTaskStatus<Success, Error>) {
switch status {
case .idle:
return nil
Expand Down Expand Up @@ -91,7 +91,7 @@ extension TaskResult: Sendable where Success: Sendable {

// MARK: - Supplementary

extension TaskStatus {
extension ObservableTaskStatus {
public init(_ result: TaskResult<Success, Error>) {
switch result {
case .canceled:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extension TaskStatusDescription {
}

public init<Success, Error: Swift.Error>(
_ status: TaskStatus<Success, Error>
_ status: ObservableTaskStatus<Success, Error>
) {
switch status {
case .idle:
Expand Down Expand Up @@ -173,7 +173,7 @@ extension TaskStatusDescription {
}
}

extension TaskStatus {
extension ObservableTaskStatus {
@_disfavoredOverload
public static func == (lhs: Self, rhs: TaskStatusDescription.Comparison) -> Bool {
TaskStatusDescription(lhs) == rhs
Expand Down
Loading

0 comments on commit a6f9814

Please sign in to comment.