Skip to content

Commit 375beee

Browse files
committed
chore: 拼写错误
1 parent 1057ea9 commit 375beee

File tree

1 file changed

+68
-30
lines changed

1 file changed

+68
-30
lines changed

Sources/SectionKit/Common/SKPublished.swift

Lines changed: 68 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@ public enum SKPublishedKind {
1616
public final class SKPublishedValue<Output>: Publisher {
1717

1818
public typealias Failure = Never
19-
public typealias TranshformPublisher = (_ publisher: AnyPublisher<Output, Failure>) -> AnyPublisher<Output, Failure>
20-
public typealias TranshformAnyPublisher = (_ publisher: AnyPublisher<Output, Failure>) -> any Publisher<Output, Failure>
21-
public typealias TranshformOnValueChanged = (_ old: Output, _ new: Output) -> Void
22-
public typealias TranshformOnChanged = (_ value: Output) -> Void
19+
public typealias TransformPublisher = (_ publisher: AnyPublisher<Output, Failure>) -> AnyPublisher<Output, Failure>
20+
public typealias TransformAnyPublisher = (_ publisher: AnyPublisher<Output, Failure>) -> any Publisher<Output, Failure>
21+
public typealias TransformOnValueChanged = (_ old: Output, _ new: Output) -> Void
22+
public typealias TransformOnChanged = (_ value: Output) -> Void
2323

24-
public struct Transhform {
24+
public struct Transform {
2525

26-
public let publisher: TranshformPublisher?
27-
public let onChanged: TranshformOnValueChanged?
26+
public let publisher: TransformPublisher?
27+
public let onChanged: TransformOnValueChanged?
2828

29-
public init(publisher publisherTranshform: TranshformPublisher? = nil,
30-
onChanged: TranshformOnValueChanged? = nil) {
31-
self.publisher = publisherTranshform
29+
public init(publisher publisherTransform: TransformPublisher? = nil,
30+
onChanged: TransformOnValueChanged? = nil) {
31+
self.publisher = publisherTransform
3232
self.onChanged = onChanged
3333
}
3434

35-
public static func mapPublisher(_ transhform: @escaping TranshformAnyPublisher) -> Transhform {
35+
public static func mapPublisher(_ transform: @escaping TransformAnyPublisher) -> Transform {
3636
.init { publisher in
37-
transhform(publisher).eraseToAnyPublisher()
37+
transform(publisher).eraseToAnyPublisher()
3838
}
3939
}
4040

41-
public static func print(prefix: String = "") -> Transhform {
41+
public static func print(prefix: String = "") -> Transform {
4242
.init(onChanged: { old, new in
4343
if prefix.isEmpty {
4444
Swift.print("[SKPublished]", old, "=>", new)
@@ -48,13 +48,13 @@ public final class SKPublishedValue<Output>: Publisher {
4848
})
4949
}
5050

51-
public static func onChanged(_ transhform: @escaping TranshformOnChanged) -> Transhform {
51+
public static func onChanged(_ transhform: @escaping TransformOnChanged) -> Transform {
5252
.init(onChanged: { old, new in
5353
transhform(new)
5454
})
5555
}
5656

57-
public static func onChanged(_ transhform: @escaping TranshformOnChanged) -> Transhform where Output: Equatable {
57+
public static func onChanged(_ transhform: @escaping TransformOnChanged) -> Transform where Output: Equatable {
5858
.init(onChanged: { old, new in
5959
guard old != new else {
6060
return
@@ -63,7 +63,7 @@ public final class SKPublishedValue<Output>: Publisher {
6363
})
6464
}
6565

66-
public static func removeDuplicates() -> Transhform where Output: Equatable {
66+
public static func removeDuplicates() -> Transform where Output: Equatable {
6767
.mapPublisher { publisher in
6868
publisher.removeDuplicates()
6969
}
@@ -75,23 +75,32 @@ public final class SKPublishedValue<Output>: Publisher {
7575
didSet {
7676
currentValueSubject?.send(value)
7777
passThroughSubject?.send(value)
78-
transhforms.forEach { $0.onChanged?(oldValue, value) }
78+
transforms.forEach { $0.onChanged?(oldValue, value) }
7979
}
8080
}
8181

8282
private let passThroughSubject: PassthroughSubject<Output, Failure>?
8383
private let currentValueSubject: CurrentValueSubject<Output, Failure>?
8484
private let subject: AnyPublisher<Output, Failure>
8585

86-
public var transhforms: [Transhform] = []
86+
public var transforms: [Transform] = []
8787

8888
public var publisher: AnyPublisher<Output, Failure> {
89-
return transhforms.compactMap(\.publisher).reduce(subject) { $1($0) }
89+
return transforms.compactMap(\.publisher).reduce(subject) { $1($0) }
9090
}
91-
92-
public init(wrappedValue: Output, kind: SKPublishedKind = .currentValue, transhforms: [Transhform] = []) {
91+
92+
public convenience init(wrappedValue: Output, kind: SKPublishedKind = .currentValue, transform: Transform) {
93+
self.init(wrappedValue: wrappedValue, kind: kind, transform: [transform])
94+
}
95+
96+
@available(*, deprecated, message: "Use init(wrappedValue:kind:transform:) instead")
97+
public convenience init(wrappedValue: Output, kind: SKPublishedKind = .currentValue, transhforms: [Transform] = []) {
98+
self.init(wrappedValue: wrappedValue, kind: kind, transform: transhforms)
99+
}
100+
101+
public init(wrappedValue: Output, kind: SKPublishedKind = .currentValue, transform: [Transform] = []) {
93102
self.value = wrappedValue
94-
self.transhforms = transhforms
103+
self.transforms = transform
95104
switch kind {
96105
case .passThrough:
97106
let subject = PassthroughSubject<Output, Failure>()
@@ -106,6 +115,8 @@ public final class SKPublishedValue<Output>: Publisher {
106115
}
107116
}
108117

118+
119+
109120
public func sink(receiveValue: @escaping ((Output) -> Void)) -> AnyCancellable {
110121
publisher
111122
.receive(on: DispatchQueue.main)
@@ -137,27 +148,54 @@ public final class SKPublishedValue<Output>: Publisher {
137148
}
138149

139150
public var projectedValue: SKPublishedValue<Value>
151+
152+
public init(wrappedValue: Value,
153+
kind: SKPublishedKind = .currentValue,
154+
transform: [SKPublishedValue<Value>.Transform] = []) {
155+
self.projectedValue = .init(wrappedValue: wrappedValue, kind: kind, transform: transform)
156+
}
157+
158+
public init<V>(kind: SKPublishedKind = .currentValue,
159+
transform: [SKPublishedValue<Value>.Transform] = []) where Value == Optional<V> {
160+
self.projectedValue = .init(wrappedValue: nil, kind: kind, transform: transform)
161+
}
162+
163+
public init(wrappedValue: Value,
164+
kind: SKPublishedKind = .currentValue,
165+
transform: SKPublishedValue<Value>.Transform) {
166+
self.projectedValue = .init(wrappedValue: wrappedValue, kind: kind, transform: [transform])
167+
}
168+
169+
public init<V>(kind: SKPublishedKind = .currentValue,
170+
transform: SKPublishedValue<Value>.Transform) where Value == Optional<V> {
171+
self.projectedValue = .init(wrappedValue: nil, kind: kind, transform: [transform])
172+
}
173+
140174

175+
@available(*, deprecated)
141176
public init(wrappedValue: Value,
142177
kind: SKPublishedKind = .currentValue,
143-
transhforms: [SKPublishedValue<Value>.Transhform] = []) {
144-
self.projectedValue = .init(wrappedValue: wrappedValue, kind: kind, transhforms: transhforms)
178+
transhforms: [SKPublishedValue<Value>.Transform]) {
179+
self.projectedValue = .init(wrappedValue: wrappedValue, kind: kind, transform: transhforms)
145180
}
146181

182+
@available(*, deprecated)
147183
public init<V>(kind: SKPublishedKind = .currentValue,
148-
transhforms: [SKPublishedValue<Value>.Transhform] = []) where Value == Optional<V> {
149-
self.projectedValue = .init(wrappedValue: nil, kind: kind, transhforms: transhforms)
184+
transhforms: [SKPublishedValue<Value>.Transform]) where Value == Optional<V> {
185+
self.projectedValue = .init(wrappedValue: nil, kind: kind, transform: transhforms)
150186
}
151187

188+
@available(*, deprecated)
152189
public init(wrappedValue: Value,
153190
kind: SKPublishedKind = .currentValue,
154-
transhforms: SKPublishedValue<Value>.Transhform) {
155-
self.projectedValue = .init(wrappedValue: wrappedValue, kind: kind, transhforms: [transhforms])
191+
transhforms: SKPublishedValue<Value>.Transform) {
192+
self.projectedValue = .init(wrappedValue: wrappedValue, kind: kind, transform: [transhforms])
156193
}
157194

195+
@available(*, deprecated)
158196
public init<V>(kind: SKPublishedKind = .currentValue,
159-
transhforms: SKPublishedValue<Value>.Transhform) where Value == Optional<V> {
160-
self.projectedValue = .init(wrappedValue: nil, kind: kind, transhforms: [transhforms])
197+
transhforms: SKPublishedValue<Value>.Transform) where Value == Optional<V> {
198+
self.projectedValue = .init(wrappedValue: nil, kind: kind, transform: [transhforms])
161199
}
162200

163201
public init(initialValue: Value) {

0 commit comments

Comments
 (0)