The Composable Architecture (简写为TCA) 让你用统一、便于理解的方式来搭建应用程序,它兼顾了组装,测试,以及功效。你可以在 SwiftUI,UIKit,以及其他框架,和任何苹果的平台(iOS、macOS、tvOS、和 watchOS)上使用 TCA。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
extension CurrentValueSubject where Failure == Never { | |
convenience init(with publisher: AnyPublisher<Output, Failure>, value: Output) { | |
self.init(value) | |
publisher.receive(subscriber: AnySubscriber(self)) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// BindingValueSubject.swift | |
// | |
// | |
// Created by Woody Liu on 2023/7/2. | |
// | |
import Combine | |
@frozen public struct BindingValue<Output>: Publisher { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
extension Publisher where Failure == Never { | |
public func bind(to binder: CombineBinder<Output>) -> AnyCancellable { | |
subscribe(binder) | |
return AnyCancellable(binder) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Property Wrapper that wraps an `AnyPublisher`, which is backed by a `CurrentValueSubject`. This is to make it possible to easily expose just a publisher to consumers of a type, | |
/// without also exposing the `CurrentValueSubject` to consumers, effectively allowing for public reads and private writes of a publisher. | |
@propertyWrapper | |
struct CurrentValueBacked<Output> { | |
private var subject: CurrentValueSubject<Output, Never> | |
init(_ output: Output) { | |
subject = CurrentValueSubject<Output, Never>(output) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Publisher { | |
public func filterTo(_ isIncluded: @escaping (Self.Output) -> Bool) -> AnyPublisher<Output, Failure> { | |
self.filter(isIncluded).eraseToAnyPublisher() | |
} | |
public func filterTo(equalTo value: Output) -> AnyPublisher<Output, Failure> where Output: AnyObject&Equatable { | |
return self.filterTo { [weak value] output in | |
value == output | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import RxSwift | |
import RxCocoa | |
struct WRxAnimation { | |
let view: UIView | |
let transform: CGAffineTransform | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
extension Publisher { | |
public func sink(completion completionHandle: (() -> Void)? = nil, receiveError: ((Self.Failure) -> Void)? = nil, receiveValue: ((Self.Output) -> Void)? = nil) -> AnyCancellable { | |
return self.sink(receiveCompletion: { completion in | |
switch completion { | |
case .failure(let error): | |
receiveError?(error) | |
case .finished: |
NewerOlder